把一个表拆分成两个表
 表M
IDM   name    total   
      ======= ======= 
  1   CPU     12      
  2   MEMORY  25      
  3   LCD     0  
下面结果:     
表A(IDA 自增类型)
IDA      name  
1       CPU          
2      MEMORY 
3      LCD       
表B(IDB 自增类型)
IDB  IDA       total    
1    1        12     
2    2        25      
3    3        0

解决方案 »

  1.   


    create table tb(idm int,name varchar(10),total int)
    insert tb
    select  1,'CPU',12 union      
    select  2,'MEMORY',25 union      
    select  3,'LCD',0  select ida=identity(int,1,1),name into t1 from tbselect idb=identity(int,1,1),t1.ida,tb.total into t2 from t1 ,tb where t1.name=tb.nameselect * from tb
    select * from t1
    select * from t2
    drop table tb,t1,t2
      

  2.   

    把表m中的数据插入到表a和表b中
      

  3.   

    create table tb(idm int,name varchar(10),total int)
    create table t1(ida int identity(1,1),name varchar(10))
    create table t2(idb int identity(1,1),ida int,total int)
    insert tb
    select  1,'CPU',12 union      
    select  2,'MEMORY',25 union      
    select  3,'LCD',0  insert t1 select name  from tbinsert t2 select t1.ida,tb.total  from t1 ,tb where t1.name=tb.nameselect * from tb
    select * from t1
    select * from t2
    drop table tb,t1,t2