Chapter 3
Chapter 3
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.
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:
Winter-18
1) Define the term Database Schema.(2M)