我遇到以下SQL语句的问题。任何帮助将不胜感激。
Select *
From dbo.Site_tblSliderFeatures
WHERE SliderID =17
GO
BEGIN TRAN
Update dbo.Site_tblSliderFeatures
SliderTitle = 'Racing to the Future',
SliderCaption = 'caption.',
SliderStart = '2014-09-30',
SliderEnd = '2014-10-7',
SliderPhoto = 'images/structure/RacingtotheFuture.png',
SliderLink = 'link'
SELECT *
FROM dbo.Site_tblSliderFeatures
WHERE SliderID = 17
-- COMMIT TRAN
ROLLBACK TRAN
以下是错误消息。
Msg 102,Level 15,State 1,Line 6
' SliderTitle'附近的语法不正确。
答案 0 :(得分:2)
'错误的语法'事实上SET
应该在UPDATE
声明中 - 这应该有效:
USE HomePage
Select * From dbo.Site_tblSliderFeatures WHERE SliderID =17
GO
BEGIN TRAN
Update dbo.Site_tblSliderFeatures
Set SliderTitle='Racing to the Future',
SliderCaption='caption.',
SliderStart='2014-09-30',
SliderEnd='2014-10-7',
SliderPhoto='images/structure/RacingtotheFuture.png',
SliderLink='link'
SELECT * FROM dbo.Site_tblSliderFeatures Where SliderID = 17
-- COMMIT TRAN
ROLLBACK TRAN
此外,作为sgeddes pointed out,在更新语句中添加Where
子句可能是明智之举,因为此查询将更新表中的所有行。
我猜你真的想要这个:
SliderEnd='2014-10-7',
SliderPhoto='images/structure/RacingtotheFuture.png',
SliderLink='link'
Where SliderID=17 -- Limit it to only rows where SliderID=17
SELECT * FROM dbo.Site_tblSliderFeatures Where SliderID = 17
答案 1 :(得分:0)
您的UPDATE
声明存在一些问题:
SET
WHERE
子句,除非您想要更新表中的每一行!试试这个:
...
UPDATE dbo.Site_tblSliderFeatures SET -- Added SET
SliderTitle='Racing to the Future',
SliderCaption='caption.',
SliderStart='2014-09-30',
SliderEnd='2014-10-7',
SliderPhoto='images/structure/RacingtotheFuture.png',
SliderLink='link'
Where SliderID = 17; -- Added where clause and ";"
SELECT * FROM dbo.Site_tblSliderFeatures Where SliderID = 17; -- Added ";" here too
...