Create table in SQL Server

Christopher Jack 1,616 Reputation points
2021-06-23T13:34:34.327+00:00

Hi,

I am trying to create a table using

create table DimDestinationVAT (
  id int primary key auto_increment,
  Warehouse_Code varchar(120),
  VAT_Code varchar(120),
  VAT_Value numeric(18,0),
  Date_From To date(),
  Date_To date()
)

However it is returning the error

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

Any help appreciated.

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Guoxiong 8,206 Reputation points
    2021-06-23T13:54:48.183+00:00

    the auto_increment is not supported by the SQL server. You need to use the IDENTITY property.

    create table DimDestinationVAT (  
    	id int IDENTITY(1, 1) NOT NULL primary key,  
    	Warehouse_Code varchar(120),  
    	VAT_Code varchar(120),  
    	VAT_Value numeric(18,0),  
    	Date_From date,  
    	Date_To date  
    )  
    

    If you do not specify NOT NULL on the column, the column is nullable.

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Reddy, Haripriya 6 Reputation points
    2021-06-23T13:54:06.583+00:00

    @Christopher Jack

    The above code auto increment is used in MySQL.

    For SQL Server use identity

    create table DimDestinationVAT (
    id int identity primary key,
    Warehouse_Code varchar(120),
    VAT_Code varchar(120),
    VAT_Value numeric(18,0),
    Date_From date,
    Date_To date
    )

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.