SQL数据库对象的修改

drop:删除属性或约束,常见格式
add:添加属性或约束
modify:修改属性类型及约束
change:重命名属性修改类型及约束
constraint:手动指定约束名

create database test;
use test;
create table Students(         
S_ID integer,                  
S_NAME varchar(10) not null,   
S_AGE integer,                 
S_TEL varchar(11) null,        
primary key(S_ID));            

insert into Students values(1,'TOM',14,'13223616367');  #插入元组
insert into Students values(2,'JACK',14,'13245277581'); #插入元组
select * from Students;                                 #Students表展示

#删除S_TEL属性
alter table Students drop column S_TEL;
select * from Students;

#添加S_TEL属性
alter table Students add column S_TEL varchar(11);
select * from Students;

#修改S_TEL类型以及约束
alter table Students modify column S_TEL varchar(15);
select * from Students;

#属性重命名,修改类型以及约束
alter table Students change column S_TEL S_phonenum varchar(11);
select * from Students;

#表重命名
alter table Students rename to Stu;
select * from Stu;

#删除主键
alter table Stu drop primary key;
select * from Stu;

#添加主键
alter table Stu add primary key(S_ID);
select * from Stu;

#添加唯一性约束
alter table Stu add constraint cons_0 unique index (S_phonenum);
select * from Stu;

#删除唯一性约束
alter table Stu drop index cons_0;
select * from Stu;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值