通过T_sql语句向其中一次填入一条数据或一次填入多条数据的方式填充数据
程序员文章站
2023-12-12 21:58:28
使用t_sql创建数据库 testschool 创建一个学生表 tblstudent 创建学生成绩表 tblscore q tscoreid (成绩 id, 主键 , 自动...
使用t_sql创建数据库 testschool
创建一个学生表 tblstudent
创建学生成绩表 tblscore q tscoreid (成绩 id, 主键 , 自动编号)、 tsid (学生编号)、 tenglish (英语成绩)、 tmath (数学成绩)
创建老师表 tblteacher q ttid 、 ttname 、 ttgender 、 ttage 、 ttsalary 、 ttbirthday
并使用t_sql语句向其中一次填入一条数据或一次填入多条数据的方式填入数据。
(
1)insert into 表(列) select 列 1 ,列 2 union
2)insert into 表(列) select 列 1 ,列 2 from 表
3) select 列 into 新表名 from 旧表
)
create database testschool
on primary
(
name='testschool',
filename='f:\sql server\testschool.mdf',
size=10mb,
filegrowth=10,
maxsize=100mb
)
log on
(
name='testschool_log',
filename='f:\sql server\testschool_log.ldf'
)
create table tblstudent
(
studentid int identity(1,1) primary key,
tscoreid int not null,
sname nvarchar(50) not null,
sage int not null,
sno numeric(18,0),--身份证号,十八位数字,小数位0
semail varchar(50),
sgender bit default(1),
sbirthday datetime
)
select * from tblstudent
truncate table tblstudent
insert into tblstudent
select 1,'刘备',20,123456789012345678,'123@163.com',1,'1987-5-6' union
select 1,'关羽',19,123456789012345671,'1sfdsf3@163.com',1,'1988-8-6' union
select 1,'张飞',18,123456789012345672,'12sfsd3@163.com',1,'1989-5-19' union
select 4,'曹操',22,123456789012345673,'12sf3@163.com',1,'1985-12-6' union
select 4,'夏侯惇',22,123456789012345674,'1ff23@163.com',1,'1985-3-6' union
select 4,'华佗',50,12345678901234565,'12ff3@163.com',1,'1957-1-16' union
select 4,'甄姬',18,12345678901234565,'12f3@163.com',0,'1989-8-8'
create table tblscore
(
tscoreid int identity(1,1) primary key,
studentid int not null, --学生id,外键
tenglish float,
tmath float
)
select * from tblscore
truncate table tblscore
insert into tblscore
select 1,90,97 union
select 2,90,70 union
select 3,59,100 union
select 4,100,80 union
select 5,60,96 union
select 6,0,100 union
select 7,80,60
create table tblteacher
(
ttid int identity(1,1) primary key,
ttname nvarchar(50) not null,
ttgender bit default(1),
ttage int,
ttsalary money,
ttbirthday datetime
)
select * from tblteacher
insert into tblteacher
select '商炳奇',1,22,10000,'1991-10-30' union
select '刘祎',0,22,10000,'1991-11-06' union
select '耿宇丹',0,21,10000,'1992-12-30' union
select '张少丹',0,22,10000,'1991-6-6' union
select '王静静',0,22,10000,'1991-6-6' union
select '段琳琳',0,22,10000,'1991-6-6' union
select '杨巧巧',0,21,10000,'1991-6-6'
创建一个学生表 tblstudent
创建学生成绩表 tblscore q tscoreid (成绩 id, 主键 , 自动编号)、 tsid (学生编号)、 tenglish (英语成绩)、 tmath (数学成绩)
创建老师表 tblteacher q ttid 、 ttname 、 ttgender 、 ttage 、 ttsalary 、 ttbirthday
并使用t_sql语句向其中一次填入一条数据或一次填入多条数据的方式填入数据。
(
1)insert into 表(列) select 列 1 ,列 2 union
2)insert into 表(列) select 列 1 ,列 2 from 表
3) select 列 into 新表名 from 旧表
)
复制代码 代码如下:
create database testschool
on primary
(
name='testschool',
filename='f:\sql server\testschool.mdf',
size=10mb,
filegrowth=10,
maxsize=100mb
)
log on
(
name='testschool_log',
filename='f:\sql server\testschool_log.ldf'
)
create table tblstudent
(
studentid int identity(1,1) primary key,
tscoreid int not null,
sname nvarchar(50) not null,
sage int not null,
sno numeric(18,0),--身份证号,十八位数字,小数位0
semail varchar(50),
sgender bit default(1),
sbirthday datetime
)
select * from tblstudent
truncate table tblstudent
insert into tblstudent
select 1,'刘备',20,123456789012345678,'123@163.com',1,'1987-5-6' union
select 1,'关羽',19,123456789012345671,'1sfdsf3@163.com',1,'1988-8-6' union
select 1,'张飞',18,123456789012345672,'12sfsd3@163.com',1,'1989-5-19' union
select 4,'曹操',22,123456789012345673,'12sf3@163.com',1,'1985-12-6' union
select 4,'夏侯惇',22,123456789012345674,'1ff23@163.com',1,'1985-3-6' union
select 4,'华佗',50,12345678901234565,'12ff3@163.com',1,'1957-1-16' union
select 4,'甄姬',18,12345678901234565,'12f3@163.com',0,'1989-8-8'
create table tblscore
(
tscoreid int identity(1,1) primary key,
studentid int not null, --学生id,外键
tenglish float,
tmath float
)
select * from tblscore
truncate table tblscore
insert into tblscore
select 1,90,97 union
select 2,90,70 union
select 3,59,100 union
select 4,100,80 union
select 5,60,96 union
select 6,0,100 union
select 7,80,60
create table tblteacher
(
ttid int identity(1,1) primary key,
ttname nvarchar(50) not null,
ttgender bit default(1),
ttage int,
ttsalary money,
ttbirthday datetime
)
select * from tblteacher
insert into tblteacher
select '商炳奇',1,22,10000,'1991-10-30' union
select '刘祎',0,22,10000,'1991-11-06' union
select '耿宇丹',0,21,10000,'1992-12-30' union
select '张少丹',0,22,10000,'1991-6-6' union
select '王静静',0,22,10000,'1991-6-6' union
select '段琳琳',0,22,10000,'1991-6-6' union
select '杨巧巧',0,21,10000,'1991-6-6'