XT 1024K PCTINCREASE 0 MINEXTENTS 1 MAXEXTENTS 5)
TABLESPACE exampletb
2¡¢ Ð޸ıí½á¹¹
Alter table ±íÃû add (ÁÐÃû ÀàÐÍ); --Ìí¼ÓÐÂÁÐ
Alter table ±íÃû modify (ÁÐÃû ÀàÐÍ); --ÐÞ¸ÄÁж¨Òå
Alter table ±íÃû drop column ÁÐÃû; --ɾ³ýÁÐ
Rename ±íÃû to бíÃû --¸Ä±íÃû£¨±íÃûǰ²»Äܼӷ½°¸Ãû£©
ALTER TABLE ±íÃû RENAME COLUMN µ±Ç°ÁÐÃû TO ÐÂÁÐÃû; --ÐÞ¸ÄÁÐÃû
? Ð޸ıí½á¹¹°¸Àý
SQL> Alter table scott.student add (QQ number(10));
--Ϊstudent±íÔö¼ÓÁдæ·ÅQQºÅ
SQL> Alter table scott.student modify (QQ number(12));
--ÐÞ¸Ästudent±íÖÐÃûΪQQµÄÁÐ
SQL> Alter table scott.student rename COLUMN QQ to QQ_num;
--½«student±íÖÐÃûΪQQµÄÁиÄÃûQQ_num
SQL> Alter table scott.student drop column QQ_num;
--ɾ³ýstudent±íÖÐÃûΪQQ_numµÄÁÐ
SQL> insert into scott.student(id,name) values(1, 'lucy');
--Ïòstudent±íÖвåÈëÒ»Ìõ¼Ç¼
SQL> Alter table scott.student modify (sex char(1) default 'M');
--ÐÞ¸ÄsexÁе͍Òå
SQL> insert into scott.student(id,name) values(2, 'Dell');
--Ïòstudent±íÖвåÈëÒ»Ìõ¼Ç¼
SQL> Alter table scott.student modify (sex char(1) default null);
--ÐÞ¸ÄsexÁе͍Òå
SQL> insert into scott.student(id,name) values(3, 'Mary');
--Ïòstudent±íÖвåÈëÒ»Ìõ¼Ç¼
˼¿¼£ºoracleÖÐÁеÄĬÈÏÖµÉèÖÃÓëÐ޸ġ£
3¡¢ ±íµÄÔ¼Êø
Alter table ±íÃû add constraint Ô¼Êø ; --Ôö¼ÓÒ»¸öÔ¼Êø
Alter table ±íÃû drop constraint Ô¼ÊøÃû; --ɾ³ýÒ»¸öÔ¼Êø
alter table±íÃûenable [validate/novalidate] constraintÔ¼ÊøÃû;
--ÆôÓÃÒ»¸öÔ¼Êø£¬validate/novalidate´ú±íÆôÓÃÔ¼ÊøÊ±ÊÇ·ñ¶Ô±íÖÐÔÓÐÊý¾Ý×÷¼ì²é¡£
alter table±íÃûdisable constraintÔ¼ÊøÃû; --½ûÓÃÒ»¸öÔ¼Êø
? Ð޸ıíÔ¼Êø°¸Àý
SQL> Alter table scott.student disable constraint st_sex_ck;
--½ûÓÃst_sex_ckÔ¼Êø
SQL> insert into scott.student(id,name,sex) values(4, 'Lily', 'N');
SQL> Alter table scott.student enable novalidate constraint st_sex_ck;
--ÆôÓÃst_sex_ckÔ¼Êø£¬µ«²»¼ì²éÒÑÓÐÊý¾Ý¡£
SQL> select * from scott.student;
SQL> insert into scott.student(id,name,sex) values(5, 'Mark', 'N');
SQL>@$ORACLE_HOME/rdbms/admin/utlexpt1.sql --½¨Á¢Òì³£Êý¾Ý±£´æ±í
»òÕß
@ G:\app\Administrator\product\11.2.0\dbhome_1\RDBMS\ADMIN\utlexpt1.sql
--¾ßÌå·¾¶¿ÉÒÔͨ¹ýËÑË÷utlexpt1.sql»ñÈ¡
SQL>alter table scott.student enable validate constraint st_sex_ck exceptions into exceptions; -- ½«Òì³£Êý¾Ý×°ÈëÒì³£±í
SQL> select * from scott.student where rowid in(select row_id from exceptions);
--²é¿´¶ÔÓ¦µÄÔ±íÖеÄÒì³£Êý¾Ý
SQL>Alter table scott.student drop constraint st_sex_ck; --ɾ³ýÔ¼Êøst_sex_ck
|