create   table   test
(
Aid   int   not   null   identity(1,1),
id as 'table_'+cast(Aid as varchar(10)),
acyear varchar(50) not null
)我想把id这列设成主键
有什么办法吗?

解决方案 »

  1.   

    create   table   test
    (
    Aid   int   not   null   identity(1,1) primary key,
    id as 'table_'+cast(Aid as varchar(10)),
    acyear varchar(50) not null
    )
      

  2.   

    晕,看错了,这样:
    create   table   test
    (
    Aid   int   not   null   identity(1,1) ,
    id as isnull('table_'+cast(Aid as varchar(10)),'') primary key,
    acyear varchar(50) not null
    )
      

  3.   

    如果id不能为空的话,可以改 alter table test add primary key(id)
    如果可以为空的话,就不能添加为主键,因为主键要求的那个字段不能为空。。(*^__^*) 嘻嘻……不知道对不对。。