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
 General SQL Server Forums
 New to SQL Server Programming
 error

Author  Topic 

Mohamed Faisal
Yak Posting Veteran

51 Posts

Posted - 2014-10-11 : 06:54:44
Hi Kindly help me to see where i went wrong:

this is my code:

CREATE TABLE RENTAL
(
[RENTALNO] INT IDENTITY (1000,1)NOT NULL,
[VEHNO] VARCHAR(8) NOT NULL,
[CUSTNO]varchar(5) NOT NULL,
[DATERENTED] DATE NULL,
[DATERETURNED] DATE NOT NULL,
[CONDITION] CHAR(20) DEFAULT 'EXCELLENT',
CONSTRAINT RENTALNOPK PRIMARY KEY(RENTALNO),
CONSTRAINT VEHNOFK FOREIGN KEY(VEHNO)
REFERENCES Car(VEHNO)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT CUSTNOFK FOREIGN KEY(CUSTNO)
REFERENCES CUSTOMER(CUSTNO)
ON DELETE NO ACTION
ON UPDATE CASCADE
CONSTRAINT CARRENTEDVALUES CHECK((([DATERETURNED]) > DATERENTED)) & ([DATERETURNED] <>DATERENTED)),

CONSTRAINT ContitionValues CHECK([Contition] LIKE 'excellent' OR
[Contition] LIKE'above average' OR [Contition] LIKE'average' OR
[Contition] LIKE'needs repair')

And i am getting the following error:

Msg 156, Level 15, State 1, Line 18
Incorrect syntax near the keyword 'CONSTRAINT'.
Msg 102, Level 15, State 1, Line 18
Incorrect syntax near 'DATERETURNED'.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-10-11 : 10:20:15
Looks like you have too many brackets somewhere
CREATE TABLE RENTAL
(
[RENTALNO] INT IDENTITY (1000,1)NOT NULL,
[VEHNO] VARCHAR(8) NOT NULL,
[CUSTNO]varchar(5) NOT NULL,
[DATERENTED] DATE NULL,
[DATERETURNED] DATE NOT NULL,
[CONDITION] CHAR(20) DEFAULT 'EXCELLENT',
CONSTRAINT RENTALNOPK PRIMARY KEY(RENTALNO),
CONSTRAINT VEHNOFK FOREIGN KEY(VEHNO)
REFERENCES Car(VEHNO)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT CUSTNOFK FOREIGN KEY(CUSTNO)
REFERENCES CUSTOMER(CUSTNO)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT CARRENTEDVALUES
CHECK((([DATERETURNED]) > DATERENTED) and ([DATERETURNED] <>DATERENTED)),
CONSTRAINT ContitionValues CHECK([Contition] LIKE 'excellent' OR
[Contition] LIKE'above average' OR [Contition] LIKE'average' OR
[Contition] LIKE'needs repair'))
Go to Top of Page

Mohamed Faisal
Yak Posting Veteran

51 Posts

Posted - 2014-10-12 : 01:27:06
Thanks allot i seem to have found the problem.
Go to Top of Page
   

- Advertisement -