0% found this document useful (0 votes)
26 views7 pages

DBMS PR 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

DBMS PR 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

3CSBS – DBMS 23012571007

sPRACTICAL 3
AIM: Perform & learn following concepts:

• What are data constraints?


• Understand following constraints with simple example. Primary Key,
Unique, NOT NULL, Check, Foreign Key

Answer following SQL Queries:

1. Use Create Command to define Constraint.

Table: ACCOUNT_Key

Column name Data Type Size Attributes


Acc_no Varchar2 5 Primary key / first letter must start with ‘A’
Name Varchar2 30 NOT NULL
City Varchar2 20 NOT NULL
Balance Number 10,2 Balance >=500
Loan_taken Varchar2 3 Values(‘NO’,’YES’)

Insert following records and Write Appropriate Comment on insertion operation


if require.

acc_no Name City Balance loan_taken


A001 Patel Jigar Mehsana 50000 YES
A002 Patel Ramesh Mehsana 50000 YES
A003 Dave Hardik Ahmedabad 75000 NO
A004 Soni Hetal Ahmedabad 100000 NO
A005 Sony Atul Vadodara 100000 YES
A005 Patel Arun Surat 4000 No
A006 NULL Baroda 5000 NO
A007 Patel Rachit NULL 6000 NO
A008 Patel Vir Mehsana 400 NO
A009 Patel Vyom Surat 1000 ABC

PAGE :1
3CSBS – DBMS 23012571007

PAGE :2
3CSBS – DBMS 23012571007

Table: Loan_Key
Column Name Data Type Size Attributes
Loan_no Varchar2 5 Primary Key / first letter must start with ‘L’
Acc_no Varchar2 5 Foreign key References Acc_no of account table
Loan_amt Number 10,2 NOT NULL
Interest_rate Number 5,2 NOT NULL
Loan_date Date
Remaining_loan Number 10,2 Remaining loan<loan amount

Insert followings records.

Loan_no Acc_no Loan_amt Interest_rate Loan_date Remaining_loan


L001 A001 100000 7 1-jan-04 75000
L002 A002 300000 9 18-may-04 150000
L003 A005 500000 11 15-june-04 300000

Table : INSTALLMENT_Key

PAGE :3
3CSBS – DBMS 23012571007

Column Name Data Type Size Attributes


Loan_no Varchar2 5 Foreign key References Loan_no of Loan table
Inst_no Varchar2 5 first letter must start with ‘I’
IDate Date NOT NULL
Amount Number 10,2 NOT NULL

Insert the following records.

Loan_no Inst_no Date Amount


L001 I001 2-Feb-04 15000
L002 I002 18-June-04 20000
L003 I003 15-July-04 20000

2. CONSTRAINTS Based queries. (Note : Use Alter Command to


define Constraint)

PAGE :4
3CSBS – DBMS 23012571007

Create Table: STUDENT

Name of column Type and Size


Rollno Varchar2(6)
Name Varchar2(20)
Branch Varchar2(6)
Address Varchar2(20)
Mobile_Number Number(10)

1. Add PRIMARY KEY (roll no) and provide constraint name PRIM_rollno.

2. Add NOT NULL constraint to name, branch for student table.

PAGE :5
3CSBS – DBMS 23012571007

3. Add check constraint and check name is in capital letter.

4. Add unique constraint on Mobile_Number column.

5. Drop check constraint on name.

Create Table: REGISTER

Name of column Type and Size

PAGE :6
3CSBS – DBMS 23012571007

Rollno Varchar2(6)
Name Varchar2(20)

1. Provide foreign key references rollno of student table.

2. Add check constraint to check name’s first letter is always capital.

3. Add NOT NULL constraint to name of register table.

4. Drop foreign key of REGISTER table.

5. Drop NOT NULL constraint.

DIY Task:

-> Create a Relational Database for a Car Manufacturing Company. Think of at


least 3 schemas of the same. Identify the constraints applicable for each
schema, Justify your answer. Write Queries to apply the same.

PAGE :7

You might also like