ID 为 主键 标识
PID 为普通目前表数据如下:
ID PID
1 null
2 null
3 null我想要效果是插入表后,PID自动填数据为ID内容,如下:
ID PID
1 1
2 2
3 3
请问是设计数据库啊,还是程序实现呢?
PID 为普通目前表数据如下:
ID PID
1 null
2 null
3 null我想要效果是插入表后,PID自动填数据为ID内容,如下:
ID PID
1 1
2 2
3 3
请问是设计数据库啊,还是程序实现呢?
我现在写DATALIST分页 它自动给我标识ID 重新排ID ,读出来的ID是排序后的,搞得我的ID都乱了
2 你自己获取最小的id+1 更新
(
id int identity(1, 1),
otherfield varchar(100),
pid int
)
CREATE TRIGGER copy_id
ON test
FOR INSERT
AS
UPDATE test SET pid = id
WHERE pid IS NULL
--Test data
insert into test(otherfield)
select 'a'
union all
select 'b'
create table calculateCol(id int primary key,id1 as id,name varchar(50));insert into calculateCol(id,name) values (1,'sych')select * from calculateCol
--结果
1 1 sych