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 2008 Forums
 Transact-SQL (2008)
 Syntax Errors

Author  Topic 

starchildren3317
Starting Member

1 Post

Posted - 2011-02-07 : 22:23:44
Good Evening Community. I am new to SQL programming. I am creating a bunch of tables for my database and am getting some syntax errors that I can not figure out. I am using SQL Server 2008 Express.

Here is the first table:


CREATE TABLE Movies (
MovieID INTEGER PRIMARY KEY AUTO_INCREMENT,
MovieName varchar(100),
ProductionStudio varchar(100),
Distributor varchar(100),
StartDate date,
EndDate date,
AuditoriumID tinyint(40) REFERENCES Auditorium(AuditoriumID));
GO


This is the Errors I am getting when I Parse:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ','.

Can anyone see where I am going wrong?

Much appreciated!

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-07 : 23:37:27
I could be wrong but as Far I know there is no keyword; AUTO_INCREMENT in SQL server. Rather its Identity which is used for this purpose Replace it with Identity and check your code again ..

Cheers!
MIK
Go to Top of Page

mikgri
Starting Member

39 Posts

Posted - 2011-02-08 : 08:52:03
There is no AUTO_INCREMENT instead you can use Identity property,
tinyint integer data from 0 through 255 and you should not specify size of this data type.
Try this:
CREATE TABLE Movies (
MovieID INTEGER identity(1,1) Constraint pk_movies PRIMARY KEY,
MovieName varchar(100),
ProductionStudio varchar(100),
Distributor varchar(100),
StartDate datetime,
EndDate datetime,
AuditoriumID tinyint constraint fk_movies_auditorium foreign key REFERENCES Auditorium(AuditoriumID));
GO

To create constraint during table creation the reference table (Auditorium) should exist.
Go to Top of Page

mikgri
Starting Member

39 Posts

Posted - 2011-02-08 : 08:53:44
You can use date datatype instead of datetime as it was in your code.
Go to Top of Page
   

- Advertisement -