T_sql笔记

sql数据库导出数据到Excel


INSERT INTO OPENDATASOURCE('MICROSOFT.JET.OLEDB.4.0','Extended properties=Excel 5.0;Data Source="D:/book1.xls"')...[Sheet1$]
 

Excel导入数据到sql数据库

--假如接受数据导入的表已经存在
insert into 表 select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=YES;DATABASE=c:/test.xls',sheet1$)
--假如导入数据并生成表
select * into 表 from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=YES;DATABASE=c:/test.xls',sheet1$)

 

 

T-sql创建表(建立单主键、联合主键、外键)

 

 

create table class(
id int primary key,
name varchar(20) not null
)
create table student(
 class_id int constraint FK_student_class_id Foreign key references class(id),
 name varchar(20) not null,
 sex varchar check(sex in('男','女'))
 constraint PK_student primary key clustered(class_id,name)
)

--表已存在时,添加
alter table student add constraint PK_student primary key clustered (class_id,name)

你可能感兴趣的:(T_sql笔记)