生活随笔
收集整理的這篇文章主要介紹了
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
;
alter table Students
drop column S_TEL
;
select * from Students
;
alter table Students
add column S_TEL
varchar(11);
select * from Students
;
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
;
總結
以上是生活随笔為你收集整理的SQL数据库对象的修改的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。