I created the following table, but I get an error;
Incorrect syntax near 'AUTO_INCREMENT'.
SQL
CREATE TABLE [dbo].[MY_TABLE] (
[ID] INT NOT NULL AUTO_INCREMENT,
[NAME] NVARCHAR (100) NULL,
[SCHOOL] NVARCHAR (100) NULL,
PRIMARY KEY (ID)
);
i think i have done everything right. can someone help me out?
You can also make an auto increment in SQL to start from another value with the following syntax: ALTER TABLE table_name AUTO_INCREMENT = start_value; In the syntax above: start_value: It is the value from where you want to begin the numbering.
When executing a query in SQL and the editor throws back this error: Incorrect syntax near …'' That typically means you have used the wrong syntax for the query. This happens mostly when someone switched from one relational database to another relational database, from MySQL to MS SQL Server for example.
By default, the AUTOINCREMENT starts with 1 and increases by 1. Example: We will create Students table with fields Student_ID, First_Name, Last_Name, we will auto generate Student_ID by using auto increment and will make it Primary Key for the table.
To use the auto increment field, in MySQL, you have to use the AUTO_INCREMENT keyword. The starting value for AUTO_INCREMENT is 1 by default, and it will increment by 1 for each new record.
It is IDENTITY
not AUTO_INCREMENT
in SQL Server.
Try this instead:
CREATE TABLE [dbo].[MY_TABLE] (
[ID] INT NOT NULL IDENTITY(1, 1),
[NAME] NVARCHAR (100) NULL,
[SCHOOL] NVARCHAR (100) NULL,
PRIMARY KEY (ID)
);
Its not AUTO_INCREMENT. Here the Demo from sqlfiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With