Need Help with AUTO_INCREMENT
-
Greetings: I am creating an SQL table programmatically using C#. I have set up my SqlCommand and I am using ExecuteNonQuery to execute the following SQL statement:
CREATE TABLE StationData (StnID INT NOT NULL AUTO_INCREMENT, Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT);
This statement is throwing an exception and the exception message says: "Incorrect syntax near "AUTO_INCREMENT"". If I remove the AUTO_INCREMENT specifier from the above statement, then the operation completes successfully and the table and columns are created as expected. It just seems to be that AUTO_INCREMENT specifier. I have checked many similar example statements from various sources and I don't see anything wrong with what I have done here. Any suggestions? Thanks, Mark -
Greetings: I am creating an SQL table programmatically using C#. I have set up my SqlCommand and I am using ExecuteNonQuery to execute the following SQL statement:
CREATE TABLE StationData (StnID INT NOT NULL AUTO_INCREMENT, Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT);
This statement is throwing an exception and the exception message says: "Incorrect syntax near "AUTO_INCREMENT"". If I remove the AUTO_INCREMENT specifier from the above statement, then the operation completes successfully and the table and columns are created as expected. It just seems to be that AUTO_INCREMENT specifier. I have checked many similar example statements from various sources and I don't see anything wrong with what I have done here. Any suggestions? Thanks, MarkTry this:
CREATE TABLE StationData (StnID INT NOT NULL
IDENTITY
, Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT);--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
Try this:
CREATE TABLE StationData (StnID INT NOT NULL
IDENTITY
, Name CHAR(50), Province CHAR(20), Latitude FLOAT, Longitude FLOAT);--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
OK, thanks. It worked. Just wondering, however, IDENTITY seems to have the same effect as AUTO_INCREMENT. What then, is the status of the AUTO_INCREMENT specifier? Obsolete? Why was SQL rejecting it? Thanks, Mark
MySQL syntax is AUTO_INCREMENT[^] SQL Server is IDENTITY [^]
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
MySQL syntax is AUTO_INCREMENT[^] SQL Server is IDENTITY [^]
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
I'm going to have to watch out for that. I've seen a lot of web tutorials and references that talk about AUTO_INCREMENT but it turns out that they were all talking about MySQL, not SQL. I had assumed that they would be similar in syntax but this is turning out to be not the case. Thanks again, Mark