ID 为 主键 标识
PID 为普通目前表数据如下:
ID PID
1  null
2  null
3  null我想要效果是插入表后,PID自动填数据为ID内容,如下:
ID PID
1  1
2  2
3  3
请问是设计数据库啊,还是程序实现呢?

解决方案 »

  1.   

    我是想插入数据的时候  不填写PID   PID 自动填写为ID数据
      

  2.   


    我现在写DATALIST分页  它自动给我标识ID 重新排ID ,读出来的ID是排序后的,搞得我的ID都乱了 
      

  3.   

    1 用触发器update pid 
    2 你自己获取最小的id+1 更新
      

  4.   

    create table test
    (
    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'
      

  5.   

    你ID和PID一模一样有什么意义?多此一举.
      

  6.   

    --可以运用计算列
    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