Incorrect syntax near the keyword 'Transaction

2019-07-19 17:56发布

I am using SQL Server Management Studio 2008 and writing the following query

INSERT INTO Transaction (TransactionType, AccountID, HolderName, Amount, CurrDate) 
VALUES ('Cash Withdrawal', '25', 'abc', '1000', 'abc');

and the script for table is

SELECT TOP 1000 [ID]
      ,[TransactionType]
      ,[AccountID]
      ,[HolderName]
      ,[Amount]
      ,[CurrDate]
  FROM [ATMSoftware].[dbo].[Transaction]

and ID is the primary key and auto incremented. But I am getting the error on the insert query

Incorrect syntax near the keyword 'Transaction'.

Please help me

Regards

4条回答
地球回转人心会变
2楼-- · 2019-07-19 18:39

Transaction is a reserved word. Put it in brackets.

INSERT INTO [Transaction](TransactionType, AccountID, HolderName, Amount, CurrDate) 
    VALUES ('Cash Withdrawal', '25', 'abc', '1000', 'abc');

When in doubt, put object names in brackets.

查看更多
做个烂人
3楼-- · 2019-07-19 18:39

you need to enclosed your tablename which is Transaction with [ and ]. Transaction is a reserved word.

查看更多
Ridiculous、
4楼-- · 2019-07-19 18:40
INSERT INTO [Transaction](TransactionType, AccountID, HolderName, Amount, CurrDate) 
VALUES ('Cash Withdrawal', '25', 'abc', '1000', 'abc');

This will surely work for you...Because Transaction is a KeyWord in sql management. i also had similar problem once and [] helped me to come out of it.

Vote up or accept if it works for you..

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-07-19 18:55

Transaction is a reserved keyword in SQL Server. You need to enclose the table name in [] to tell SQL Server it is a name and not a keyword:

INSERT INTO [Transaction] 
       (TransactionType,AccountID,HolderName,Amount,CurrDate) 
VALUES 
       ('Cash Withdrawal','25','abc','1000','abc');
查看更多
登录 后发表回答