Docsity

Implementing Database Constraints and Subqueries, Cheat Sheet of Law

Toggle sidebar
bg1
Experiment No:3
Aim: To implement Constraints
Primary Key Constraint
Program:
SQL>Create table book (bookid number(4) primary key, bookname
varchar(20) not null ,authorname varchar(20), price number(8));
Output:
Table Created.
SQL>select *from book;
Output:
Foreign Key Constraint
Program:
SQL>Create table publisher(pubid number(4) primary key, pubname
varchar(20) not null ,bookid number(4),foreign key(bookid)references
book);
Output:
Table Created.
SQL>select *from publisher;
Output:
Check Constraint
Program:
SQL>Create table student (studentid number(4), studentname varchar(20),
age number(3),sex char(10),batch varchar(25) check(batch
in(‘science’,’commerce’)),total number(4));
Output:
pf3

Partial preview of the text

Download Implementing Database Constraints and Subqueries and more Cheat Sheet Law in PDF only on Docsity!

Experiment No:

Aim: To implement Constraints

Primary Key Constraint

Program:

SQL>Create table book (bookid number(4) primary key, bookname varchar(20) not null ,authorname varchar(20), price number(8));

Output:

Table Created.

SQL>select *from book;

Output:

Foreign Key Constraint

Program:

SQL>Create table publisher(pubid number(4) primary key, pubname varchar(20) not null ,bookid number(4),foreign key(bookid)references book);

Output:

Table Created.

SQL>select *from publisher;

Output:

Check Constraint

Program:

SQL>Create table student (studentid number(4), studentname varchar(20), age number(3),sex char(10),batch varchar(25) check(batch in(‘science’,’commerce’)),total number(4));

Output:

Table Created.

SQL>select *from student;

Output:

Unique Constraint

Program:

SQL>Create table department (deptid number(4)Unique, deptname varchar(20),subject varchar(25));

Output:

Table Created.

Not Null Constraint

Program:

SQL>Create table college (collegeid number(4)not null, coursename varchar(20),location varchar(25));

Output:

Table Created.

Experiment No:

Aim: To implement Sub Queries

Program: Display the details of book published by PHI

SQL>select *from book where bookid in(select bookid from publisher where pname=’PHI’);

Output:

Program: select the book with max price