0% found this document useful (0 votes)
15 views49 pages

Chapter 3

Chapter 3 diploma information technology

Uploaded by

zeeshansari.390
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
15 views49 pages

Chapter 3

Chapter 3 diploma information technology

Uploaded by

zeeshansari.390
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 49

Chapter 3

Interactive SQL Programming


Tuning
SQL /
Working with RDMS
Structure Query Language (SQL)

 It is also called ‘Query Language’.


 It can define the Structure of the database,
modify data in the database and specify
Security & Constraint.
 developed by IBM in 1970’s.
 It was first named as ‘Sequal’.
Data Types in SQL
 Char
 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 one 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 ( _ , $ , #)
Database Languages
1) Data Definition Language (DDL)
 It is used to create and modify the structure of database
objects in database. or
 to define the structure or schema of a database
 Commands are
Create: To create new table or database
Alter: It is used to add new attributes or to
modify the existing attributes in the table.

Truncate: It is used to removes all the rows from a table


Rename: Rename statement is used to rename a table.
Drop: removes the data as well as definition(Structure)
of an oracle table.
Data dictionary / Data directory
Data dictionary or Data directory is a
file that contains data about data(meta
data).
2) Data Manipulation Language
(DML)

• It is used to retrieve, store, modify, delete,


insert and update data in database.
• Commands are
Insert: It create a new record
Select: It retrieve records from table
Update: It modifies records
Delete: It deletes records
3) Data Control Language
(DCL)

• Data Control Language commands are used to


control the database objects.
• Commands are
Grant
Revoke
4) Transaction Control Language
(TCL)

• It is used to manage different transactions


occurring within a database.
• Command are
Commit
Roll back
Save point
1) Data Definition Language (DDL)

• It is used to create and modify the structure of


database objects in database.
or
• to define the structure or schema of a database
• Commands are
Create
Alter
Truncate
Rename
Drop
Data Definition Language (DDL) Commands

1) Create table
2) Alter table
3) Truncate table
4) Rename table
5) Drop table
1) Create table

Definition: To create new table or database

Syntax:

CREATE TABLE <table_name>


(column_name1 datatype(size),
column_name2 datatype(size),
.
.
column_namen datatype(size)
);
Example of Employee table

ID Name Age Salary

Fig : Employee Table


Example:
2) Alter table

Definition: It is used to add new attributes or


to modify the existing attributes in the table.

Alter Table

Add clause Modify clause


Case 1: ADD is used to add columns into the
existing 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

Definition: The TRUNCATE TABLE statement


removes all the rows from a table, but the table
structure and its columns are remain intact.

Syntax:

TRUNCATE TABLE <table_name>;

Example:
4) Rename table

Definition: Rename statement is used to


rename a table.

Syntax:

RENAME <oldtable_name> to <newtable_name> ;

Example:
5) Drop table

Definition: The drop table command removes


the data as well as definition(Structure) of an
oracle table.
Syntax:

DROP table <table_name> ;

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

ID Name Age Salary

1 Adam 34 13000

2 Alex 28 15000

3 Smith 20 18000

4 John 42 19020

Fig : Employee Table


Example:
Case b: To insert values for selected attributes in a
table.

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.

Case a: To display all attributes from the table

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.

Case a: To update all rows from the 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.

Case a: To delete specific rows from the 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:
Winter-18
1) Define the term Database Schema.(2M)

2) Define the term Foreign Key. (2M)

3) Explain Integrity constraints with example. (4M)

4) Explain primary key and candidate key with example. (4M)

5) Explain various types of Relational constraints. (4M)

6) Consider ‘student’ database with appropriate details. Write a

procedure to manipulate given database by adding, modifying and

deleting records. (6M)


Summer-19
1) Define Constraint.(2M)
2) Explain any four Codd’s rule. (4M)
3) Explain different operations performed with Data Definition
Language. (4M)
.

4) Explain terms Primary Key and Candidate Key with example.(4M)


5) Explain entity integrity constraint with example . (4M)
6) 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.(6M)
7) Consider Employee database with appropriate details. Write a procedure to
manipulate given database by adding, modifying and deleting records.
Winter-19
1) Define primary key and candidate key.(2M)
2) Define constraints, list types. (2M)
3) Write Syntax for create table.(2M)
4) Explain Domain constraints with Syntax and example (4M)
.

5) Explain any 4 Codd’s rules. (4M)


6) Consider the following schema
student (R_No, Name, DOB, Percentage, D_No).
Write procedure to manipulate given database by adding,
modifying and deleting records.(6M)
7) Consider the following schemas:
(i) Dept (Dept_No, DName, LOC)
(ii) Emp (Emp_No, Ename, Job, Sal, Dept_No)
Draw and explain parent child relationship for above schemas
and apply referential integrity constraint.

You might also like