Oracle alter table, oraclealtertable
Create table T_CLASS_INFO (
CLASSNO number (3) primary key, -- class number
CLASSNAME varchar2 (10 ),
CLASSPLACE varchar2 (13)
);
Create table T_STUDENT_INFO (
STUNO number (3), -- Student ID
CLASSNO number (3 ),
STUNAME varchar2 (10 ),
STUSEX char (1 ),
STUCONTECT number (11), -- contact information
STUADD varchar2 (50 ),
STUDETAILINFO varchar2 (100)
);
-- Modify column name
ALTER table T_CLASS_INFO RENAME column classpto to LOCATION;
-- Add primary key constraints
ALTER table T_STUDENT_INFO ADD constraint PK_STU_NO primary key (STUNO );
-- Add a foreign key constraint
ALTER table T_STUDENT_INFO ADD constraint FK_CLASSNO foreign key (CLASSNO) references T_CLASS_INFO (CLASSNO );
-- Add check Constraints
ALTER table T_STUDENT_INFO ADD constraint CK_STU_INFO check (STUSEX in ('F', 'M '));
-- Add the not null Constraint
ALTER table T_STUDENT_INFO modify stucontect constraint NOT_NULL_INFO not null;
-- Add a unique constraint
ALTER table T_STUDENT_INFO ADD constraint UQ_STU_CONTECT unique (STUCONTECT );
-- Add the default Constraint
ALTER table T_STUDENT_INFO modify stusex char (2) default 'M ';
-- Add a column
ALTER table T_STUDENT_INFO add stuid varchar2 (18 );
ALTER table T_STUDENT_INFO add stuage date default sysdate not null;
-- Delete a column
ALTER table T_STUDENT_INFO DROP column STUDETAILINFO;
-- Modify the Column Length
ALTER table T_CLASS_INFO modify classplace varchar2 (50 );
-- Modify the column precision
ALTER table T_STUDENT_INFO modify stuno number (2 );
-- Modify the Data Type of a column
ALTER table T_STUDENT_INFO modify stusex char (2 );
-- Modify the column Default Value
ALTER table T_STUDENT_INFO modify stuage default sysdate + 1;
-- Disable Constraints
ALTER table T_STUDENT_INFO disable FK_CLASSNO;
-- Enable constraints
ALTER table T_STUDENT_INFO enable FK_CLASSNO;
-- Delete Constraints
ALTER table T_STUDENT_INFO DROP FK_CLASSNO;
-- Latency Constraint
ALTER table T_STUDENT_INFO ADD constraint FK_CLASSNO foreign key (CLASSNO)
References T_CLASS_INFO (CLASSNO)
Deferrable initially deferred;
-- Add a comment to the table
Comment on table T_STUDENT_INFO is 'student table ';
-- Add comments to columns
Comment on column T_STUDENT_INFO.STUNAME is 'student name ';
Comment on column T_CLASS_INFO.CLASSNAME is 'class ';
-- Clear all data in the table
Truncate table T_STUDENT_INFO;
-- Delete a table
DROP table T_STUDENT_INFO;