时间:2022-07-03 09:32:20 | 栏目:MsSql | 点击:次
CREATE table MyStudentInfo ( Id int not null primary key, Name varchar(16), Age int, Gender varchar(2), Phone varchar(16), Address varchar(50), GradeId int )
INSERT INTO MyStudentInfo SELECT 1,'张三',20,'1','15801258912','上海',1 UNION SELECT 2,'李四',22,'1','12345678901','北京',1 UNION SELECT 3,'王五',16,'1','13976891234','天津',2 UNION SELECT 4,'赵六',19,'1','18676891234','重庆',3 UNION SELECT 5,'小红',21,'2','17776891234','广州',4 UNION SELECT 6,'小王',25,'2','13176891234','深圳',2 UNION SELECT 7,'小刘',18,'2','13374591234','南京',1
1、将MyStudentInfo表的所有字段数据插入不存在的表
SELECT * INTO studentinfo_test1 FROM MyStudentInfo
2、将MyStudentInfo表的个别字段数据插入不存在的表
SELECT Id,Name INTO MytestInfo FROM myStudentInfo
3、带有where子句
SELECT Id,Name,Gender INTO MytestInfo FROM myStudentInfo WHERE Gender='1'
查询MytestInfo表的数据
4、从一个以上的表中选取数据插入新表
SELECT s.Id,s.Name,s.GradeId,g.GradeName INTO NewTable FROM MyStudentInfo s INNER JOIN GradeInfo g on s.GradeId=g.Id
查询NewTable表的数据
将MyStudentInfo表的id,name列插入studentinfo_test2(studentinfo_test2表已经存在)
INSERT INTO studentinfo_test2 SELECT * FROM MyStudentInfo