SQL - Constraints • Primary Key


--====================================================
SQL - Constraints      Primary Key
--====================================================

DROP TABLE XX_EMP_TL

CREATE TABLE XX_EMP_TL
(
  EMPNO     NUMBER(4) PRIMARY KEY, -- Column Level Constraints --
  --EMPNO     NUMBER(4) CONSTRAINT XX_EMP_PK PRIMARY KEY, -- Column Level Constraints --
  ENAME     VARCHAR2(100),
  GENDER CHAR(1),  
  SAL       NUMBER(7),
  DEPTNO    NUMBER(2),
  CREATION_DATE Date Default sysdate
  --Constraint XX_EMP_PK PRIMARY KEY ( EMPNO) -- Table Level Constraints --     
--  Constraint XX_EMP_PK PRIMARY KEY ( EMPNO,ENAME) -- Table Level Constraints --
)

select * from XX_EMP_TL

insert into  XX_EMP_TL (EMPNO, ENAME, GENDER, SAL, DEPTNO, CREATION_DATE)  Values ( 1001, 'Sachin', 'M', 15000, 10, sysdate)

insert into  XX_EMP_TL (EMPNO, ENAME, GENDER, SAL, DEPTNO, CREATION_DATE)  Values ( 1001, 'Sachin', 'M', 15000, 10, sysdate)


EMPNO
ENAME
GENDER
SAL
DEPTNO
CREATION_DATE
1001
Sachin
M
24-Jan-41
10
27-03-2020 14:54



COMMIT;

--========

CREATE TABLE XX_EMP_TL
(
  EMPNO     NUMBER(4),
  ENAME     VARCHAR2(100),
  GENDER CHAR(1),  
  SAL       NUMBER(7),
  DEPTNO    NUMBER(2),
  CREATION_DATE Date Default sysdate
)

select * from XX_EMP_TL

edit XX_EMP_TL

COMMIT

ALTER TABLE XX_EMP_TL ADD Constraint XX_EMP1_PK PRIMARY KEY (EMPNO)

ALTER TABLE XX_EMP_TL ADD Constraint XX_EMP2_PK PRIMARY KEY (EMPNO,ENAME)

select * from XX_EMP_TL


insert into  XX_EMP_TL (EMPNO, ENAME, GENDER, SAL, DEPTNO, CREATION_DATE)  Values ( 1001, 'Ravi', 'M', 15000, 10, sysdate)

insert into  XX_EMP_TL (EMPNO, ENAME, GENDER, SAL, DEPTNO, CREATION_DATE)  Values ( 1001, '', 'M', 15000, 10, sysdate)

insert into  XX_EMP_TL (EMPNO, ENAME, GENDER, SAL, DEPTNO, CREATION_DATE)  Values ( 1001, 'Ravi', 'M', 15000, 10, sysdate)


COMMIT;

EMPNO
ENAME
GENDER
SAL
DEPTNO
CREATION_DATE
1001
Sachin
M
24-Jan-41
10
27-03-2020 14:54
1001
Ravi
M
24-Jan-41
10
27-03-2020 14:57


DROP TABLE  APPS.XX_EMP_TL

--============= Check your Constraints --======================


SELECT * FROM ALL_CONSTRAINTS 
WHERE TABLE_NAME = 'XX_EMP_TL'

--============= Check your Constraints --======================

CONSTRAINT_NAME
CONSTRAINT_TYPE
TABLE_NAME
XX_EMP2_PK
P
XX_EMP_TL


Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor