Follow us: Connect on YouTube Connect on YouTube Connect on YouTube

Pages

Monday, 11 September 2017

Create SQL Table With Constrains

Constraints are always attached to a column not a table.
We can add constraints in three ways.
Column level -- Along with the column definition
Table level     -- After the table definition
Alter level      -- Using alter command
While adding constraints you need not specify the name but the type only, oracle will internally name the constraint.
If you want to give a name to the constraint, you have to use the constraint clause.

Create table with Constrains with Example:

 
CREATE TABLE emp
(
   empno       NUMBER PRIMARY KEY,
   ename       VARCHAR2 (50) NOT NULL,
   job         VARCHAR2 (10),
   mgr         NUMBER,
   hiredate    DATE DEFAULT (SYSDATE),
   sal         NUMBER,
   hrly_rate   NUMBER,
   comm        NUMBER,
   deptno      NUMBER NOT NULL 
);
Note: To know more about constrains >SQL Constraints
Share this article :

0 comments:

Post a Comment