Oracle alter table, oraclealtertable

Source: Internet
Author: User

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.