user3106444
user3106444

Reputation: 83

Incorrect Syntax near keyword 'Transaction' SQL Insertion Statements

I don't understand where the error is. I've done this a million times before, but for some reason, this error keeps coming up. Here are my Create Table Statements:

CREATE TABLE chf.Transaction
(
TransactionID INT IDENTITY(1,1) PRIMARY KEY,
AmtDue MONEY,
DiscountPercent DECIMAL(5,2),
AmtPaid MONEY,
Date DATETIME,
)
GO

CREATE TABLE chf.Agent
(
AgentID INT IDENTITY(1,1) PRIMARY KEY,
Name VARCHAR(50),
TransactionID INT,
constraint Agent_T_FK foreign key (TransactionID) REFERENCES    chf.Transaction(TransactionID),
)
GO

Upvotes: 0

Views: 6192

Answers (3)

Rahul Parit
Rahul Parit

Reputation: 331

It is happpening just because you are trying to use predefined keywords as table name. You should delimit it with [] symbol.

      CREATE TABLE [transaction]
      (

      );

Find the all keywords list in this link- https://technet.microsoft.com/en-us/library/aa238507(v=sql.80).aspx

Upvotes: 3

Bozman
Bozman

Reputation: 477

Transaction is a reserved word. put [] around it like so

CREATE TABLE chf.[Transaction]
(
TransactionID INT IDENTITY(1,1) PRIMARY KEY,
AmtDue MONEY,
DiscountPercent DECIMAL(5,2),
AmtPaid MONEY,
Date DATETIME,
)
GO

Upvotes: 5

Ravindra Gullapalli
Ravindra Gullapalli

Reputation: 9158

Transaction is a keyword. So it is not allowing. If you want to use Transaction as table name then use like this.

CREATE TABLE chf.[Transaction]

But I strongly recommend not to use the keywords / reserved words

Upvotes: 6

Related Questions