每个表里的字段完全一样,只是数据不同。
比如
table班级01  里的字段是 name sex age 
table班级02  里的字段是 name sex age 现在想做一个学年或者学校的表, 把个各个班级的信息登录到一个数据库表中 请问sql 问怎么写

解决方案 »

  1.   

    select * from tb1
    union all
    select * from tb2
    union all
    ....
      

  2.   

    select * from 班级01 union all
    select * from 班级02
      

  3.   

    create table 学年表(班级ID int,班级名 varchar(20),name varchar(20), sex int, age int )insert 学年表
    select 1,'班级01',* from table1
    union all
    select 2,'班级02',* from table2
    union all
    ......
      

  4.   

    select 
      *
    into tb
    from(
    select '班级01' as 班级,* from [班级01]
    union all
    select '班级02' as 班级,* from [班级02]
    ) t
      

  5.   


    insert into 学校的表
    select name ,sex, age from table班级01
    union all
    select name ,sex, age from table班级02
      

  6.   

    SELECT #T.* INTO table年级 FROM 
    (SELECT * FROM  table班级01 UNION ALL
    SELECT * FROM  table班级02) #T注意:插入以后无论你原先的表的主键是什么,新的table年级表都是没有主键的哦。