0% found this document useful (0 votes)
23 views6 pages

Ankitdbms 4

Uploaded by

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

Ankitdbms 4

Uploaded by

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

Theory and Concept

Objective:-To Implement the restrictions/constraints on the table.

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:

Create table tablename


(column name datatype(size)not null……)

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));

Default valueconcept: At the lineofcellcreationadefault valuecanbeassignedto it. When the


user is loading a recordwith values and leaves this cellempty, the DBAwilautomatically load
this cell withthe default value specified. The datatype ofthe default value should match the
data type of the column

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

Columnname Datatype Size Attributes


Salesman_no varchar2 6 Primarykey/firstletter
muststartwith‘s’
Sal_name varchar2 20 Notnull
Address varchar2 Notnull
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8,2 Notnull, cannotbe0
Tgt_to_get Number 6,2 Notnull, cannotbe0
Ytd_sales Number 6,2 Notnull, cannotbe0
Remarks Varchar2 30

ii. Sales_order

Columnname Datatype Size Attributes


S_order_no varchar2 6 Primary/firstlettermustbe0
S_order_date Date 6 Primarykeyreferenceclientnoof
client_master table
Client_no Varchar2 25
Dely_add Varchar2 6
Salesman_no Varchar2 6 Foreign key references
salesman_noofsalesman_masterta
ble
Dely_type Char 1 Deliverypart(p)/full(f),defaultf
Billed_yn Char 1
RajKumarGoelInstituteofTechnology,Ghaziabad
____________________________________________________
Department of Computer Science &Engineering

Order_status Varchar1 ComputerScience Engineering process’;’fulfilled’;backorder’;’can celed


department

I. Sales_order_details

Column Datatype Size Attributes

S_order_no Varchar2 6 Primarykey/foreignkey


referencess_order_no
of sales_order
Product_no Varchar2 6 Primarykey/foreignkey
references product_no
ofproduct_master
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2
 RajKumarGoelInstituteofTechnology,Ghaziabad
Department ofComputerScience&Engineering

Insertthe followingdataintotheirrespectivetablesusing insertstatement:

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:

S_orderno S_orderdate Clientno Dely Bill yn Salesmanno Delay Orderstatus


type date
019001 12-jan-96 0001 F N 50001 20-jan-96 Ip
019002 25-jan-96 0002 P N 50002 27-jan-96 C
016865 18-feb-96 0003 F Y 500003 20-feb-96 F
019003 03-apr-96 0001 F Y 500001 07-apr-96 F
046866 20-may-96 0004 P N 500002 22-may- C
96
010008 24-may-96 0005 F N 500004 26-may- Ip
96
 RajKumarGoelInstituteofTechnology,Ghaziabad
Department ofComputerScience&Engineering

(iii) Dataforsales_order_detailstable:

S_orderno Productno Qtyordered Qtydisp Product_rate


019001 P00001 4 4 525
019001 P07965 2 1 8400
019001 P07885 2 1 5250
019002 P00001 10 0 525
046865 P07868 3 3 3150
046865 P07885 10 10 5250
019003 P00001 4 4 1050
019003 P03453 2 2 1050
046866 P06734 1 1 12000
046866 P07965 1 0 8400
010008 P07975 1 0 1050
010008 P00001 10 5 525

You might also like