Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 FOREIGN KEY ERRORS.

Author  Topic 

Hinduson
Yak Posting Veteran

69 Posts

Posted - 2013-10-02 : 17:57:16
Below is the table i created and when i execute, I get this error.

CREATE TABLE ITEMS_ITEMDETAILS
(
ItemID int Identity(2,2) PRIMARY KEY ,
ItemName Varchar (50) not null,
ItemDescription Varchar (50) not null,
QuantityInHand int,
CONSTRAINT check_ID1 CHECK (QuantityInHand >= 0 ),
UnitPrice Money,
CONSTRAINT check_ID2 CHECK (UnitPrice >= 0 ),
ReorderQuantity int,
CONSTRAINT check_ID3 CHECK (ReorderQuantity >= 0 ),
ReorderLevel int ,
CONSTRAINT check_ID4 CHECK (ReorderLevel >= 0)
CategoryID int constraint fkey_CategoryID Foreign Key References ITEMS_PRODUCTCATEGORY(CategoryID)
SupplierID int constraint fkey_SupplierID Foreign Key References SUPPLIER_SUPPLIERDETAILS (SupplierID)
)


Msg 102, Level 15, State 1, Line 14
Incorrect syntax near 'CategoryID'.


Best Regards.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-10-03 : 03:54:55
Try checking your commas.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-10-03 : 03:55:01
Try checking your commas.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-04 : 01:52:13
you've 2 commas missing at the end

CREATE TABLE ITEMS_ITEMDETAILS
(
ItemID int Identity(2,2) PRIMARY KEY ,
ItemName Varchar (50) not null,
ItemDescription Varchar (50) not null,
QuantityInHand int,
CONSTRAINT check_ID1 CHECK (QuantityInHand >= 0 ),
UnitPrice Money,
CONSTRAINT check_ID2 CHECK (UnitPrice >= 0 ),
ReorderQuantity int,
CONSTRAINT check_ID3 CHECK (ReorderQuantity >= 0 ),
ReorderLevel int ,
CONSTRAINT check_ID4 CHECK (ReorderLevel >= 0),
CategoryID int constraint fkey_CategoryID Foreign Key References ITEMS_PRODUCTCATEGORY(CategoryID),
SupplierID int constraint fkey_SupplierID Foreign Key References SUPPLIER_SUPPLIERDETAILS (SupplierID)
)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -