你试了吗? alter table tb add id2 int identity(1,1) 消息 2744,级别 16,状态 2,第 1 行 为表 'tb' 指定了多个标识列。只允许为每个表指定一个标识列。
alter table 表 add 列 int identity(1,1)
select row_number() over(order by 字段A) as idd,id,a from tb
if object_id('tb') is not null drop table tb go create table tb(id int identity,id2 as id,col varchar(10)) go insert tb select 'a' union all select 'b' go select * from tb /* id id2 col ----------- ----------- ---------- 1 1 a 2 2 b(2 行受影响) */
TONY is great ~~~~~
if object_id('tb') is not null drop table tb go create table tb(id int identity,id2 as id*2,id3 as id+1000,col varchar(10)) go insert tb select 'a' union all select 'b' union all select 'c' go select * from tb /* id id2 id3 col ----------- ----------- ----------- ---------- 1 2 1001 a 2 4 1002 b 3 6 1003 c(3 行受影响) */
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================create table kas(id1 int identity(1,1),id2 int identity(1,3),a int)go
/*------------
消息 2744,级别 16,状态 2,第 1 行
为表 'kas' 指定了多个标识列。只允许为每个表指定一个标识列。-------*/
alter table tb add id2 int identity(1,1)
消息 2744,级别 16,状态 2,第 1 行
为表 'tb' 指定了多个标识列。只允许为每个表指定一个标识列。
alter table 表 add 列 int identity(1,1)
from tb
drop table tb
go
create table tb(id int identity,id2 as id,col varchar(10))
go
insert tb select 'a'
union all select 'b'
go
select * from tb
/*
id id2 col
----------- ----------- ----------
1 1 a
2 2 b(2 行受影响)
*/
drop table tb
go
create table tb(id int identity,id2 as id*2,id3 as id+1000,col varchar(10))
go
insert tb select 'a'
union all select 'b'
union all select 'c'
go
select * from tb
/*
id id2 id3 col
----------- ----------- ----------- ----------
1 2 1001 a
2 4 1002 b
3 6 1003 c(3 行受影响)
*/