带有方括号的SQL语句AUTO_INCREMENT错误

时间:2015-08-05 04:39:11

标签: mysql sql sql-server sql-server-2008

我的新VPN仅接受带有方括号的sql statements,因此我将传统的sql query编辑为:

CREATE TABLE admin (
  [id] int(11) NOT NULL AUTO_INCREMENT,
  [name] varchar(128) NOT NULL,
  [email] varchar(64) NOT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;

但它显示了这个错误:

  

Msg 102,Level 15,State 1,Line 1语法不正确   ' AUTO_INCREMENT'

基本上服务器是windows azure,我使用Microsoft SQL server管理工作室来执行sql查询。

3 个答案:

答案 0 :(得分:0)

CREATE TABLE [dbo].[admin](
    [id] [int](11) IDENTITY(1,1) NOT NULL,
    [name] [varchar](128) NULL,
    [email] [varchar](64) NULL,
 CONSTRAINT [PK_admin] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

答案 1 :(得分:0)

在sql server中应该创建自动增量来使用IDENTITY而不是AUTO_INCREMENT。喜欢这个

CREATE TABLE admin (
  [id] int(11) IDENTITY(1,1) NOT NULL ,
  [name] varchar(128) NOT NULL,
  [email] varchar(64) NOT NULL,
  PRIMARY KEY (id)
) 

更多详细信息,请参阅此链接http://www.w3schools.com/sql/sql_create_table.asp

答案 2 :(得分:0)

CREATE TABLE [dbo].[admin](
[ID] [int]IDENTITY(1,2) NOT FOR REPLICATION NOT NULL,
[name] [char](128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[email] [varchar](64) NOT NULL,
PRIMARY KEY CLUSTERED 
(
  [ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
                        ) ON [PRIMARY]