10月笔记

来源:互联网 发布:java 高并发基础教程 编辑:程序博客网 时间:2024/06/05 10:25

create database TestSchool
on primary
(
name="TestSchool.mdf",filename="D:\test\TestSchool.mdf",filegrowth=10%
)
log on
(
name="TestSchool_log.ldf",filename="D:\test\TestSchool_log.ldf"
)

create table TblStudent
(
tSId int identity(1,1) primary key,
tSName nvarchar(10) not null,
TSGender bit default(1),
tSAddress nvarchar(1500),
tSPhone varchar(50),
tSAge int,
tSBirthday datetime,
tSCardid varchar(50),
tSClassid int
)
create table TblScore
(
tScoreId int identity(1,1) primary key,
tSId int null,
tEnglish float,
tMath float

)

go
create table TblTeacher
(
tTId int identity(1,1) primary key,
tTName nvarchar(50),
tTGender bit default(0),
tTAge int,
tTsalary money,
tTBirthday datetime

)
go
 

insert into TblTeacher(tTName,tTGender,tTAge,tTSalary,tTBirthday) values('姚洪波',1,27,10000,'1980-10-10');
--向特定列插入数据
insert into TblTeacher(tTName,tTSalary) values('李雨锦',5000);
 
insert into TblTeacher values('辛兴涛','true',27,10000,'1982-07-09');
 
--union插入多行
insert into TblTeacher
select 'Chris',1,20,1500,'1999-9-9' union
select 'James',1,20,1600,'1999-10-11' union
select 'Tom',1,20,1700,'1999-9-20' union
select 'Marry',0,20,1500,'1999-9-9'
 
insert into TblTeacher
select '辛兴涛','true',27,10000,'1982-07-09' union
select '辛兴涛','true',27,10000,'1982-07-09'
insert into TblTeacher
select 'Tom','true',20,1700,'1999-9-20' union
select '李莫愁','true',32,12200,'1974-07-09' union
select '李莫愁','true',32,12200,'1974-07-09'

select * from TblTeacher
--向一个已经存在的表中插入数据,数据的来源是另一张表
 
insert into TblTeacher(tTName,tTAge,tTsalary)
select tTName,tTAge,tTsalary  from TblTeacher
select * from TblScore

原创粉丝点击