Create a primary key (example)

Source: Internet
Author: User
Create a primary key (example) SQLaltertableemp_oggaddconstraintPK_empnoprimarykey (empno); -- create a primary key to query the constraints of a table SQLdescuser_constraints; NameNull? Type ----------------------------------------------------------------------------- O

Create a primary key (for example) SQL alter table emp_ogg add constraint PK_empno primary key (empno); -- create a primary key to query the constraints of a table SQL desc user_constraints; Name Null? Type ----------------------------------------- -------- ------------------------------ O

Create a primary key (example)

SQL> alter table emp_ogg add constraint PK_empno primary key (empno );

-- Create a primary key

Queries the constraints of a table.

SQL> desc user_constraints;

Name Null? Type
-----------------------------------------------------------------------------
OWNER VARCHAR2 (30)
CONSTRAINT_NAME not null VARCHAR2 (30)
CONSTRAINT_TYPE VARCHAR2 (1)
TABLE_NAME not null VARCHAR2 (30)
SEARCH_CONDITION LONG
R_OWNER VARCHAR2 (30)
R_CONSTRAINT_NAME VARCHAR2 (30)
DELETE_RULE VARCHAR2 (9)
STATUS VARCHAR2 (8)
DEFERRABLE VARCHAR2 (14)
DEFERRED VARCHAR2 (9)
VALIDATED VARCHAR2 (13)
GENERATED VARCHAR2 (14)
BAD VARCHAR2 (3)
RELY VARCHAR2 (4)
LAST_CHANGE DATE
INDEX_OWNER VARCHAR2 (30)
INDEX_NAME VARCHAR2 (30)
INVALID VARCHAR2 (7)
VIEW_RELATED VARCHAR2 (14)

SQL> select CONSTRAINT_NAME, INDEX_NAME, TABLE_NAME from user_constraints;

-- Query constraints for a user

-- Check whether a primary key exists.

CONSTRAINT_NAME INDEX_NAME TABLE_NAME
------------------------------------------------------------------------------------------
PK_DEPT DEPT
PK_EMP EMP
FK_DEPTNO EMP
SYS_C0010809 SYS_C0010809 TCUSTMER
Sys_c00000010 sys_c00000010 TCUSTORD

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.