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

来源:asp之家 时间:2012-11-30 19:55:34 

使用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'

标签:T_sql语句,填入数据
0
投稿

猜你喜欢

  • javascript权威指南,学习笔记,之运算符号

    2008-04-20 16:43:00
  • python异常处理try的实例小结

    2022-01-25 06:06:51
  • Python库 Bokeh 数据可视化实用指南

    2022-09-28 14:54:51
  • JavaScript ES6语法中let,const ,var 的区别

    2024-05-09 15:06:49
  • 分析Python中设计模式之Decorator装饰器模式的要点

    2021-12-06 12:04:01
  • Mysql中悲观锁与乐观锁应用介绍

    2024-01-15 08:26:30
  • Python字符串常规操作小结

    2023-12-02 08:33:23
  • Python3enumrate和range对比及示例详解

    2021-02-05 02:11:47
  • python脚本替换指定行实现步骤

    2022-03-18 16:53:28
  • 从零开始学YII2框架(五)快速生成代码工具 Gii 的使用

    2024-05-11 09:54:56
  • python环境中的概念conda中与环境相关指令操作

    2021-01-09 19:40:55
  • vue2.0 中#$emit,$on的使用详解

    2023-07-02 16:52:27
  • js实现九宫格抽奖

    2024-04-17 10:34:36
  • python中 OpenCV和Pillow处理图像操作及时间对比

    2021-02-04 16:46:52
  • 解决Alexnet训练模型在每个epoch中准确率和loss都会一升一降问题

    2022-12-06 16:17:37
  • mysql 字符串正则表达式及说明

    2024-01-13 17:47:59
  • vue实现一个单独的组件注释

    2024-04-27 15:47:04
  • MySQL DISTINCT 的基本实现原理详解

    2024-01-15 17:21:29
  • 如何基于python实现归一化处理

    2022-09-07 02:05:34
  • python定时复制远程文件夹中所有文件

    2023-08-17 17:55:32
  • asp之家 网络编程 m.aspxhome.com