Oracle data table creation, query, constraints, and other operations

Source: Internet
Author: User

1. Create a table, delete a table, copy a table

CREATE TABLE stuinfo-- creating learner information Tables

Stuno Char (6) NOT NULL

Stuname varchar (2) not nul,

Stuage number (3,0) NOT NULL

Create a new table copy the Learner Information table is:CREATE TABLE StuInfo2 as SELECT * from Stuinfo;

Delete Table: 1, drop table Table 2, truncate tables;

2, the table structure of the query: DESC table name;

3, change the table name: ALTER TABLE old table name rename to new table name;

Add columns: ALTER TABLE table Add (column name type, column name type);

Modify columns: ALTER TABLE table modify (column name type, column name type);

Delete a column: ALTER TABLE table drop column name; Delete multiple columns: ALTER TABLE Table drop (column 1, column 2);

4, add a constraint to the table, the EMP table Deptno as a Foreign Key reference dept Table Deptno

ALTER TABLE EMP Add constraint pk_test foreign KEY (deptno) References dept (DEPTNO);

5. Add a PRIMARY KEY constraint to the table

ALTER TABLE EMP ADD constraint Pk_emp_deptno primary key (DEPTNO);

6. Delete the constraint:

ALTER TABLE EMP drop constraint Pk_emp_deptno;

7. Disabling and enabling constraints:

ALTER TABLE Table Dsable| | Enable constraint constraint name;

Oracle data table creation, query, constraints, and other operations

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.