T-sql union

来源:互联网 发布:英国读高中知乎 编辑:程序博客网 时间:2024/06/07 19:27

select sName,sAge from student union           以第一条字段的名称为显示student和teacher的名字和年龄,并组合输出     

select  tName,tAge from teacher                        union 排序  去除重复      union all 直接显示连个结果集

 

 

多行插入数据  比  insert into  跟简单高效些

 

insert into Score(studentId,english,math)           为Score表的studentId以及english和math字段添加多条记录

select 1,80,100 union

select 2,90,85 union

...........

 

把现有表中的数据插入到新表中

select * into newStudent from Student           newStudent为新表(newStudent不能存在)Student为现有表

 

把现有表中的数据插入到已存在的表中

 into backStudent  select * from student

 

 

原创粉丝点击