Dbms Lab6: Jenma Maria Binoy Rollno 34
Dbms Lab6: Jenma Maria Binoy Rollno 34
CONSTRAINTS:
UNIQUE The UNIQUE constraint does not allow to insert a duplicate value in a column.
NOT NULL NOT NULL constraint allows to specify that a column can not contain any NULL
value.
CHECK The CHECK constraint determines whether the value is valid or not from a logical
expression.
DEFAULT While inserting data into a table, if no value is supplied to a column, then the
column gets the value set as DEFAULT
KEY Constraints:
Primary key A PRIMARY KEY constraint for a table enforces the table to accept unique
data for a specific column and this constraint create a unique index for accessing the table
faster.
FOREIGN KEY A FOREIGN KEY creates a link between two tables by one specific column of
both table. The specified column in one table must be a PRIMARY KEY and referred by the
column of another table known as FOREIGN KEY.
Syntax:
Create table tablename (column_name1 data_ type constraints, column_name2 data_ type
constraints …)
2. Create table student with the following fields. All the fields doesnot insert null values:
• Rollno,sname, ,dob;
• Set RollNo as the primary key of the table.
create table student(rollno number(3) primary key,sname varchar(15) not null,dob date);
Name Type
---------- ----------------
EMPNO NUMBER(6)
ENAME VARCHAR2(2
0)
JOB VARCHAR2(1
0)
DEPTNO NUMBER(3)
SALARY NUMBER(7,2
)
Allow NULL for all columns except ename and job. Set default value of salary as ‘5000’;
SQL> create table emp(empno number(6) null ,ename varchar(20) not null,job varchar(10)
not null,deptno number(3) null,salary number(7,2) default 5000);
DNAME VARCHAR2(10)
LOC VARCHAR2(10)
RESULT:
The DDL commands have been executed successfully and the output is verified.