Theory and Concept Assignment #3: Objective:-To Implement The Restrictions On The Table
Theory and Concept Assignment #3: Objective:-To Implement The Restrictions On The Table
Assignment #3
Objective:- To Implement the restrictions on the table.
Data constraints: Besides the cell name, cell length and cell data type there are other parameters
i.e. other data constraints that can be passed to the DBA at check creation time. The constraints
can either 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 constraints.
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 level
constraints.
Null Value Concepts:- while creating tables if a row locks a data value 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 uniquely identify each row in
the table. Primary key values must not be null and must be Unique across the column. A
multicolumn primary key is called a composite primary key.
Unique key concept:-A Unique is similar to a primary key except that the purpose of a Unique key
is to ensure that information in the column for each record is Unique as with telephone or devices
license numbers. A table may have many Unique keys.
Default value concept: At the line of cell creation a default value can be assigned to it.
When the user is loading a record with values and leaves this cell empty, the DBA will
automatically load this cell with the default value specified. The data type of the default
value should match the data type of the column
Syntax:
Create table tablename
(columnname datatype (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.
Syntax :
Create table name (columnname datatype
(size)... primary key (columnname)
foreign key (columnname) references table name);
Check Integrity Constraints: Use the check constraints when you need to enforce
integrity 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 uppercase.
● A check constraint on the client_no column of the client _master so that no
client_no value starts with ‘c’
Syntax:
Create table tablename (columnname datatype (size)
CONSTRAINT constraint_name Check (expression));
Question.1 Create the following tables:
i. Sales_master
Columnname Datatype Size Attributes
Salesman_no varchar2 6 Primary key/first letter
must start with ‘s’
Sal_name varchar2 20 Not null
Address1 varchar2 30 Not null
Address2 varchar2 30 Not null
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8,2 Not null, cannot be 0
Tgt_to_get Number 6,2 Not null, cannot be 0
Ytd_sales Number 6,2 Not null
Remarks Varchar2 60
ii. Sales_order
Columnname Datatype Size Attributes
S_order_no varchar2 6 Primary/first letter must be 0
order_date Date Not null
Question 2: Insert the following data into their respective tables using insert statement: