加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

通过T_sql语句向其中一次填入一条数据或一次填入多条数据的方式

发布时间:2020-12-12 09:56:21 所属栏目:MsSql教程 来源:网络整理
导读:使用T_SQL创建数据库 TestSchool 创建一个学生表 TblStudent 创建学生成绩表 TblScore q tScoreId (成绩 id,主键,自动编号)、 tSId (学生编号)、 tEnglish (英语成绩)、 tMath (数学成绩) 创建老师表 TblTeacher q tTId 、 tTName 、 tTGender 、 tT

使用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 旧表

<div class="codetitle"><a style="CURSOR: pointer" data="37353" class="copybut" id="copybut37353" onclick="doCopy('code37353')"> 代码如下:<div class="codebody" id="code37353">
create database TestSchool
on primary
(
name='TestSchool',
filename='F:SQL ServerTestSchool.mdf',
size=10mb,
filegrowth=10,
maxsize=100mb
)
log on
(
name='TestSchool_log',
filename='F:SQL ServerTestSchool_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','1988-8-6' union
select 1,'张飞',18,123456789012345672,'12sfsd3@163.com','1989-5-19' union
select 4,'曹操',22,123456789012345673,'12sf3@163.com','1985-12-6' union
select 4,'夏侯惇',123456789012345674,'1ff23@163.com','1985-3-6' union
select 4,'华佗',50,12345678901234565,'12ff3@163.com','1957-1-16' union
select 4,'甄姬','12f3@163.com','1989-8-8' create table TblScore
(
tScoreId int identity(1,
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,70 union
select 3,59,100 union
select 4,100,80 union
select 5,60,96 union
select 6,100 union
select 7,80,60 create table TblTeacher
(
tTId int identity(1,
tTName nvarchar(50) not null,
tTGender bit default(1),
tTAge int,
tTSalary money,
tTBirthday datetime
) select * from TblTeacher insert into TblTeacher
select '商炳奇',10000,'1991-10-30' union
select '刘祎','1991-11-06' union
select '耿宇丹',21,'1992-12-30' union
select '张少丹','1991-6-6' union
select '王静静','1991-6-6' union
select '段琳琳','1991-6-6' union
select '杨巧巧','1991-6-6'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读