Ankitdbms 4
Ankitdbms 4
Data constraints: Besides the cell name, cell lengthand cell data type there are other parameters i.e.
other data constrains that canbe passed to the DBAat check creationtime. The constraints caneither be
placed at column level or at the table level.
i. Column Level Constraints: If the constraints are defined along with the column definition, it
is called a column level constraint.
ii. Table Level Constraints: If the data constraint attached to a specify cell in a table reference
the contents of another cell in the table then the user will have to use table levelconstraints.
NullValue Concepts:-while creating tables ifa rowlocksa datavalue for particular column that
value is said to be null . Column of any data types may contain null values unless the column
was defined as not null when the table was created
Syntax:
Primary Key: primary key is one or more columns is a table used to uniquickly identity each
row in the table. Primary key values must not be null and must be uni Question across the
column. A multicolumn primary key is called composite primary key.
Syntax:primarykeyasacolumn constraint
Createtabletablename
(columnnamedatatype(size)primarykey,….)
Primarykeyasatable constraint
Createtabletablename
(columnnamedatatype(size),columnnamedatatype(size)…
Primary key (columnname,columnname));
UniQuestion key concept:-A uniQuestion is similar to a primarykey except that the purpose
of a uniQuestion key is to ensure that information in the column for each record isuniQuestion
as with telephone or devices license numbers. A table may have many uniQuestion keys.
Syntax: UniQuestionasacolumnconstraint.
Createtabletablename
(columnnamedatatype(size)uniQuestion);
RajKumarGoelInstituteofTechnology,Ghaziabad
Department ofComputerScience&Engineering
UniQuestionastable constraint:
Createtabletablename
(columnname datatype (size),columnname datatype (size)…uniQuestion
(columnname,columnname));
Syntax:
Createtabletablename
(columnnamedatatype(size)default value,….);
Foreign Key Concept :Foreign key represents relationship between tables. A foreign key is
column whose values are derived from the primary key of the same of some other table . the
existence of foreign key implies that the table with foreign key is related to the primary key
table from which the foreign key is derived .A foreign key must have corresponding primary
key value in the primary key table to have meaning.
Foreignkeyas a columnconstraint
Syntax:
Createtabletablename
(columnnamedatatype(size)referencesanothertablename);
Foreignkeyasatableconstraint:
Syntax:
Create table
name(columnnamedatatype(siz
e)…. primary key
(columnname);
foreignkey(columnname)referencestablename);
Check Integrity Constraints: Use the check constraints when you need to enforce intergrity
rules that can be evaluated based on a logical expression following are a few examples of
appropriate check constraints.
A check constraints name column of the coient_master so that the name is entered in
upper case.
A check constraint on the client_no column of the client _master so that no client_no
value starts with ‘c’
Syntax:
Createtabletablename
(columnnamedatatype(size)CONSTRAINTconstraintname)
Check (expression));
RajKumarGoelInstituteofTechnology,Ghaziabad
Department ofComputerScience&Engineering
Experiment 4
Question.2Createthefollowing tables:
i. Sales_master
ii. Sales_order
I. Sales_order_details
Dataforsales_manmastertable
Salesman_no Salesman Address City Pin code State Salamt Tgt_ Ytd Remark
name to_ge Sales
t
500001 Kiran A/14worli Bomba 400002 Mah 3000 100 50 Good
y
500002 Manish 65,nariman Bomba 400001 Mah 3000 200 100 Good
y
500003 Ravi P-7Bandra Bomba 400032 Mah 3000 200 100 Good
y
500004 Ashish A/5 Juhu Bomba 400044 Mah 3500 200 150 Good
y
(i) Dataforsalesordertable:
(iii) Dataforsales_order_detailstable: