Emp_id 是自增整型,不需要指定插入值

解决方案 »

  1.   

    Emp_id 是自增整型,不需要指定插入值
      

  2.   

    1: 你的Emp_id字段是int identity(100,5),应该只能是整形数据
    2:自增字段不能这样加,也没必要加。
      

  3.   

    Emp_id 是自增整型,不需要指定插入值
      

  4.   

    你是那里抄的例子!误人子第。use pubs
    go
    IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
          WHERE TABLE_NAME = 'mytable')
       DROP TABLE mytable
    go
    create table mytable
    (Emp_id int identity(100,5),
     last_name varchar(30) not null,
     real_name varchar(30) not null
    )go
    insert mytable(last_name,real_name) values ('aa','vv')
    insert mytable(last_name,real_name) values ('bb','vv')
    insert mytable(last_name,real_name) values ('120','vv')
    insert mytable(last_name,real_name) values ('cc','vv')
    go
      

  5.   

    begin transaction  ---????
    go------???? 在一个事务中是不可以用GO来分开!!!try belowuse pubs
    go
    IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
          WHERE TABLE_NAME = 'mytable')
       DROP TABLE mytable
    go
    create table mytable
    (Emp_id int identity(100,5),
     last_name varchar(30) not null,
     real_name varchar(30) not null
    )go
    begin transaction
    insert into mytable values ('aa','bb')
    commit
    godrop table mytable
    go
      

  6.   

    问题一
    你的事务代码不能这样写。问题二
    insert语句错的一踏糊涂。
      

  7.   

    其实这是清华大学出的:sqlserver7入门与提高
    例子是:
    begin transaction 
    go
    use pubs
    go
    --IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    --      WHERE TABLE_NAME = 'mycompanies')
    --   DROP TABLE mycompanies
    --上面是我加的
    create table mycompanies
    (id_num int identity(100,5),
     company_name Nvarchar(100)
    )
    go
    insert mycompanies(company_name)
    values('New moon Books')
    insert mycompanies(company_name)
    values('Binnet & hardly')
    insert mycompanies(company_name)
    values('Algodata Infosystems')
    insert mycompanies(company_name)
    values('Dhb')
    go
    select * from mycompanies
    order by company_name asc
    go
    commit
    go
    PS:我没有发现我和它有什么不同啊,但它的例子的确没有问题(运行正常)
    ??1.insert mycompanies(company_name)
    values('Binnet & hardly')和我的insert mytable(Emp_id) values ('aa')有不同么?
    ??2.create table mytable
        (  Emp_id int identity(100,5),
     last_name varchar(30) not null,
     real_name varchar(30) not null
      )
      与
      create table mycompanies
    (id_num int identity(100,5),
     company_name Nvarchar(100)
    )
    有区别么?为什么我的程序错?晕
      

  8.   

    to leimin(黄山光明顶) :
    你的代码是正确的,但是好象go 可以放在transaction中
    sorry,刚刚的确晕了,字段都没有看清楚;),谢谢大家帮忙!!!!!!