“21天养成好习惯”第一期-20

--1、创建S_T1数据库中的各个表
--1)依据数据表的结构创建相对应的数据表
--创建student表

create database S_T1
go
create table student
(sno char(9) primary key ,
sname char(6) not null,
ssex char(2) ,
sage int ,
sdept varchar(8) 
)


--创建course表

create table course
(cno char(4) primary key ,
cname varchar(20) not null,
cpno char(4),
ccredit int
)


--创建sc表

create table sc
(
sno char(9) not null,
cno char(4) not null,
grade int ,
primary key(sno,cno)
)


--2)在表student中增加新字段 “班级名称(sclass)”,类型为varchar,长度为10;

alter table student
add sclass varchar(10)


--3)在表student中删除字段“班级名称(sclass)”;

alter table student
drop column sclass


--4)修改表student中字段名为“sname”的字段长度由原来的6改为8;

alter table student
alter column sname char(8)

--5)修改表student中字段“sdept”名称为“dept”,长度为20;
--方法一:使用两次alter table命令

--先删除原有名称的列
alter table student
drop column sdept 
--再添加新名称的列
alter table student
add  dept varchar(20)


--方法二:使用系统存储过程sp_rename把列改名,再修改它的类型和长度

exec sp_rename 'student.sdept' ,'dept','column'

alter table student
alter column dept varchar(20)
--select * from student

--6)修改表student中sage字段名称为sbirth,类型为smalldatetime;
--方法一:使用两次alter table命令
--先删除原有名称的列

alter table student
drop column sage 

--再添加新名称的列
alter table student
add  sbirth smalldatetime


--方法二:使用系统存储过程sp_rename把列改名,再修改它的类型和长度

exec sp_rename 'student.sage' ,'sbirth','column'

alter table student
alter column sbirth smalldatetime

--select * from student

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值