--检查char和varchar的区别
--创建表 注意:多列之间用逗号隔开,最后一列可以没有逗号
--(加入自动增长列:identity(1001,1)默认是(1,1))
Drop table TStu
Create table TStu
(
stu_id varchar(10) not null ,
stu_name varchar(50) not null,
stu_age smallint null,
stu_sex char(2),
stu_Chiscore decimal(5,2) null,
primary key(stu_id,stu_name)
)
--插入全字段数据
insert into Tstudent(stu_id,stu_name,stu_age,stu_sex,stu_Chiscore)
values('1001','张三',20,'男',82.1)
insert into tstudent
values('1002','李司',20,'男',82.1)
--插入部分字段数据
insert into Tstudent(stu_id,stu_name,stu_Chiscore)
values('1003','王五',87.1)
--修改表结构,增加一个新列(在最后)
Alter table TStu
add stu_Mathscore decimal(5,2) null
Alter table TStu
add stu_Score as stu_Mathscore + stu_Chiscore
insert into TStu
values('1040','jjjj',14,'男',78.2,70.5)
--修改表结构,修改列的数据类型、空值属性(column关键字不能少)
Alter table TStu
alter column stu_age int
--修改表结构,删除列
Alter table TStu
drop column stu_age
--删除表结构(整个表)
drop table TStu
--查看表格属性
exec sp_help TStu
--改表名
exec sp_rename TStu,Tstudent
--修改表内数据(单行单列)
update tstudent
set stu_id = '1008'
where stu_id = '1006'