0% found this document useful (0 votes)
26 views

Lab7 Constraints2

The document provides instructions for creating multiple database tables ("Account", "Account2", etc.) with various column constraints such as primary keys, unique constraints, default values and check constraints. It also has steps to describe the tables, view constraint details, insert sample data with potential errors, add and remove constraints. The goal is to practice applying different constraint types at column and row/table level and view the effects in the database metadata.

Uploaded by

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

Lab7 Constraints2

The document provides instructions for creating multiple database tables ("Account", "Account2", etc.) with various column constraints such as primary keys, unique constraints, default values and check constraints. It also has steps to describe the tables, view constraint details, insert sample data with potential errors, add and remove constraints. The goal is to practice applying different constraint types at column and row/table level and view the effects in the database metadata.

Uploaded by

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

Practical List – Constraints 2

Course: BCA
1. WAQ (write a query) to create an “Account” table with following constraints:
All constraints to be given ONLY at column level
AccountNo Number Primary Key
CustName Varchar2 Not Null
AccountType Varchar2 Default Value ‘Saving’
Balance Number >1000
PassportNo Varchar2 Unique

2. See and note the structure of above created table using “describe”. (Note structure carefully)
and write answers for the following questions:
a. Which constraints are displayed in the structure?
b. Can you tell from the structure which column is Unique?
c. Can you tell from the structure which column is Primary and Which Not Null?
d. Can you tell from the structure which column has check constrain?.

3. See the contents of “User_Constraints” table and note the constraint number and type
of constraints for your above table. (You can attach printout of this table)

4. Insert the following data in the above table (In case of Error , Correct the data yourself)

117501 Puneet Saving 1100 B9895


117502 Saving 2100 A9895
117507 Rohit Current 500 C9898
117507 Rohit Current 5000 C9898
117504 Kumar Saving 1100 C9898
117508 Shweta Saving 7100 A6789
117503 Deepak Current 12000

Write Each Query without using substitution and note the output of each.

Commit The Data

5. WAQ (write a query) to create an “Account2” table with following constraints:

AccountNo Number Primary Key


CustName Varchar2 Not Null
AccountType Varchar2 Default Value ‘Current’
Balance Number >5000
PassportNo Varchar2 Unique

6. See and note the structure of above created table using “describe”. (Note structure carefully)

7. WAQ (write a query) to create an “Account3” table with following constraints:

AccountNo Number Primary Key (at Row/Table Level)


CustName Varchar2 Not Null (Only at Table / Row Level)
(if an error comes, first note the error and then correct the query)

8. See the contents of “User_Constraints” table and note the constraint number and type
of constraints for your above tables.

9. Drop the NOT NULL Constraint from Account3 Table.

10. WAQ (write a query) to create an “Account4” table with following constraints:

AccountNo Number Primary Key (Constraint Name : PKey)


CustName Varchar2 Not Null (Constraint Name : NNull )
AccountType Varchar2 Default Value ‘Current’
Balance Number >5000 (Constraint Name : ChkBal)
PassportNo Varchar2 Unique (Constraint Name : UU)

11. See the contents of “User_Constraints” table and note the constraint number and type
of constraints for your above table.

12. Drop the Primary Key & Unique Constraint from Account4 Table.

13. WAQ (write a query) to create an “Account5” table without any constraints:

AccountNo Number (No constraint)


CustName Varchar2 (No constraint)
Balance Number (No constraint)
14. Insert the following data in the above table:

8111 Puneet 1000


8111 Mudit 2000
8114 Kumar 3000
8115 Shweta 500
8115 Deepak 6000

15. See the structure of Account5 table

16. Add the primary key constraint for AccountNo in Account5 Table
(If an error comes, note the error and write the reason)

17. In case of error in above ques, rectify the above table contents and repeat above Question
(Write all the steps and queries)

18. See the contents of “User_Constraints” table and search the name of Account5 table in it.

19. Add UNIQUE constraint in Account5 Table for CustName field.

20. Add Check constraint in Account5 Table for Balance field. ( Amount > 1500)

21. In case of error in above ques, rectify the above table contents and repeat above Question
(Write all the steps and queries)

22. See the contents of “User_Constraints” table and search the name of Account5 table in it.
(Note the constraint number for account5 table)

You might also like