Professional Documents
Culture Documents
2) Logical Schema
Describes the database design at the logical level.
3) Subschema
Describes different views of the database.
Database Subschema
A Subschema is a Subset of a Schema.
Staff
Staff Name Department Qualification Mobile.no Email_Id
Student
Name Roll_ No Enrollment _No Mobile No. Address
Library
OR
Integrity Constraints
Primary Foreign
Not Null Check Unique Reference
Key Key
1) Domain Integrity Constraints
Types:
a) NOT NULL
b) Check
a) NOT NULL
Types:
a) Primary Key
b) Unique
a) Primary Key
Types:
Super Key
Candidate Key
Primary Key
Foreign Key
Super Key
Super Key is defined as a set of attributes within a
table that uniquely identifies each record within a table.
Candidate Key
A Candidate Key is a set of one or more
fields/columns that can identify a record uniquely in a
table.
Primary Key
Primary Key is a one fields/columns of a table that
uniquely identify a record in database table.
Foreign Key
Primary Key of one table become a attributes of
another table is called Foreign Key.
Super Key
Customer
Example:
Customer
Example:
Customer
Example:
Customer{ Cust_ID},
Composite Key / Compound Key
Composite Key that consists of two or more
attributes that uniquely identify an entity is called
Composite key.
Cust-ID account_no
Customer
Example:
Customer{ Cust_ID,account_no.},
Foreign Key
Foreign key represents relationship between tables.
Customer
Relationship
Example:
Varchar2
Long
Number
Date
Char
Fixed length character string
store alphanumeric values
column name can vary between 1 to 2000
bytes
Varchar2
Variable length character string
store alphanumeric values
column name can vary between 1 to 4000
bytes
Long
store variable character length
maximum 2GB
only on column in the table can have long data
type
Date
store Date & Time in a table
fixed length of 7 bytes
default date format is ‘dd-mmm-yy’
sysdate()
Number
store positive no. , negative no. , zeroes , fixed point
no. , and floating point no. with a precision of 38.
(P= 38 , S=0)
where P is Precision
Total no. of digit ( 1 to 38)
&
S is Scale
No. of digit to the right of the decimal Point
( -84 to 127)
Eg: SSC Percentage (85.37%)
Limitation
maximum column limit of SQL is 30
characters.
maximum table name is 30 characters.
first letter start with alphabet.
SQL support three standard special
character ( _ , $ , #)
1) Data Definition Language (DDL)
1) Create table
2) Alter table
3) Truncate table
4) Rename table
5) Drop table
1) Create table
Syntax:
Alter Table
Syntax:
ALTER TABLE <table_name>
add (column_name1 datatype(size),
column_name2 datatype(size),
.
.
column_namen datatype(size)
);
Example:
Case 2: It is used to modify the existing columns in a
table.
Syntax:
ALTER TABLE <table_name>
modify (column_name1 datatype(size),
column_name2 datatype(size),
.
.
column_namen datatype(size)
);
Example:
DROP COLUMN is used to drop column
in a table. Deleting the unwanted columns
from the table.
Syntax:
ALTER TABLE <table_name>
drop column column_name;
Example:
3) Truncate table
Syntax:
Example:
4) Rename table
Syntax:
Example:
5) Drop table
Example:
Data Manipulation Language
(DML) Commands
1) Insert
2) Select
3) Update
4) Delete
1) Insert
Definition: insert data in to a table.
OR it creates a record.
Case a: To insert a row into a table by specifying all
attributes and its value:
Syntax:
insert into <table_name>
(attributes_name1, attributes_name2,…., attributes_name n)
values
(expression 1, expression 2,……., expression n));
Example of Employee table
1 Adam 34 13000
2 Alex 28 15000
3 Smith 20 18000
4 John 42 19020
Syntax:
insert into <table_name>
(attributes_name1, attributes_name2)
values
(expression 1, expression 2) );
Example:
Case c: To insert the values for all attributes in order
attributes declared in the table.
Syntax:
insert into <table_name>
values
(expression 1, expression 2,……., expression n));
Example:
Case d: To insert more than one row.
Syntax:
insert into <table_name>
values
(&attributes 1, ‘&attributes 2’,…..&attributes n) );
Example:
2) Select
Definition: Retrieve data from the a database.
Syntax:
Select *
from <table_name>;
Example:
Case b: To retrieve specific attributes from the table.
Syntax:
Select <attributes_name1,…. attributes_namen>
from <table_name>;
Example:
Case c: To list only those records from the table
which satisfies the given predicate.
Syntax:
Select <attributes_name1,…. attributes_namen>
from <table_name>
where <search condition>
Example:
Case d: To list distinct values in the column.
Syntax:
Select distinct <attributes_name1>
from <table_name>;
Example:
3) Update
Definition: Updates existing data within a table.
Syntax:
update <table_name>
set <attributes_name1= expression 1>;
Example:
Case b: To update selective rows from the table
where the specified condition gets satisfied.
Syntax:
update <table_name>
set <attributes_name1= expression 1>
where <search condition>;
Example:
4) Delete
Definition: Deletes all records from a table.
Syntax:
delete
from <table_name>
where <search condition>;
Example:
Case b: To delete all rows from the table.
Syntax:
delete
from <table_name>;
Example:
Consider the following schemas:
(i) Dept (Dept_no, Dept_name, Dept-loc)
(ii) Staff (Staff_id, Staff_name, Dept_no, Joint_date)
Draw and explain parent-child relationship for above schemas
and find out foreign key with justification.(S-19)
Winter-18
1) Define the term Database Schema.(2M)