drop table if exists test
create table test(id int not null auto_increment,name varchar(20)not null default 'name',math int null default 60,primary key (id);
insert test values(1,'liyinglin',98)
insert test values(2,'jiangshan',79)
insert test values(3,'wangjiawu',100)
insert test values(4,'xingweiqi',89)
insert test values(5,'lingsheng',61)
执行后报一下的错误:
Server: Msg 156, Level 15, State 1, Line 1
在关键字 'if' 附近有语法错误。
Server: Msg 170, Level 15, State 1, Line 2
第 2 行: 'auto_increment' 附近有语法错误。请高手指点

解决方案 »

  1.   

    drop table test if exists(select * from sysobjects where name='test')
      

  2.   

    if exists (select * from dbo.sysobjects where id = object_id(N'test') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table test
    GO
    create table test(id int Identity(1, 1) not null ,name varchar(20)not null default 'name',math int null default 60,primary key (id))
    insert test values('liyinglin',98)
    insert test values('jiangshan',79)
    insert test values('wangjiawu',100)
    insert test values('xingweiqi',89)
    insert test values('lingsheng',61)
      

  3.   

    sdhylj(青锋-SS),寫法有問題。樓主,你的代碼有幾處問題,再測試下.
      

  4.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[Test]
    GOCREATE TABLE [dbo].[Test] (
    [id] [int] NOT NULL ,
    [name] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    [matn] [int] NOT NULL 
    ) ON [PRIMARY]
    GOALTER TABLE [dbo].[Test] WITH NOCHECK ADD 
    CONSTRAINT [DF_Test_name] DEFAULT ('name') FOR [name],
    CONSTRAINT [DF_Test_matn] DEFAULT (60) FOR [matn],
    CONSTRAINT [PK_Test] PRIMARY KEY  CLUSTERED 
    (
    [id]
    )  ON [PRIMARY] 
    GOinsert test values(1,'liyinglin',98)
    insert test values(2,'jiangshan',79)
    insert test values(3,'wangjiawu',100)
    insert test values(4,'xingweiqi',89)
    insert test values(5,'lingsheng',61)
      

  5.   

    scmail81(琳·风の狼(修罗)) , auto_increment要改為SQL的自增列
      

  6.   

    写反了,这样可以
    if exists(select * from sysobjects where name='test') drop table test
      

  7.   

    drop table test if exists(select * from sysobjects where name='test')
    create table test(id int Identity(1, 1),name varchar(20)not null default 'name',math int null default 60,primary key (id);insert test values(1,'liyinglin',98)
    insert test values(2,'jiangshan',79)
    insert test values(3,'wangjiawu',100)
    insert test values(4,'xingweiqi',89)
    insert test values(5,'lingsheng',61)
    谢谢大家了,我现在是想把这些语句插入到java里面,所以最好越简单越好,上面的代码在查询分析器里面还是有问题,大家受累再帮我看一下吧。
    Server: Msg 170, Level 15, State 1, Line 2
    第 2 行: ';' 附近有语法错误。
    Server: Msg 208, Level 16, State 1, Line 1
    对象名 'test' 无效。
      

  8.   

    if exists(select * from sysobjects where name='test') drop table test
    create table test(id int Identity(1, 1),name varchar(20)not null default 'name',math int null default 60,primary key (id))insert test values('liyinglin',98)
    insert test values('jiangshan',79)
    insert test values('wangjiawu',100)
    insert test values('xingweiqi',89)
    insert test values('lingsheng',61)
      

  9.   

    if exists (select * from dbo.sysobjects where id = object_id(N'test') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table test
    GO
    create table test(id int Identity(1, 1) not null ,name varchar(20)not null default 'name',math int null default 60,primary key (id))
    insert test values('liyinglin',98)
    insert test values('jiangshan',79)
    insert test values('wangjiawu',100)
    insert test values('xingweiqi',89)
    insert test values('lingsheng',61)
    我上面寫的這個是沒有問題的,你怎麼只復制了一半?
      

  10.   

    脑力劳动网(http://www.nlld.net)是一个付费IT技术问答社区。目前注册送2元,如果您在那上面提问,网站可以资助你的提问1到3元,以便你得到满意的回答。
       你也可回答别人的提问,您的帐号上超过3元时,可以要求网站提现。