Basic Queries:: Insert Into Persons Values (&P - Id,'&Lastname','&Firstname', &Address','&City')
Basic Queries:: Insert Into Persons Values (&P - Id,'&Lastname','&Firstname', &Address','&City')
DDL :
1. create
2. Alter
3. drop
DML :
1. insert
2. select
3. delete
4. update
Table Creation:
Create table persons (p_id number(2),
LastName varchar(20),
FirstName varchar(20),
Address varchar(20),
City varchar(2));
To delete record:
Delete from persons where p_Id=2;
To modify/update Record:
Update persons set p_id=10 where p_id=3;
To delete complete Table:
Drop table persons;
ALTER :
To delete attribute:
Alter table persons drop(contact);
To modify Attribute :
Alter table persons modify(contact number(15));
Adding Constraints:
3. Domain Constraint:
i. not null
ii. unique
iii. default
iv. check
Saving Work:
Special Operators:
2. select * from product where price NOT BETWEEN 1000 and 2500;
LIKE :
IN / NOT IN:
EXISTS:
ORDERING A LISTING :
AGGREGATE FUNCTIONS:
FUNCTION OUTPUT
COUNT The number of rows containing non null values
MIN The minimum value for given attribute
MAX The maximum value for given attribute
SUM The sum of all values for given attribute
AVG The arithmetic mean for given attribute values
ARITHMETIC OPERATORS:
HAVING CLAUSE :
student11;
Student12
30 rows selected.
Natural Join:
Inner Join:
CROSS JOIN:
30 rows selected.
SELF JOIN:
ROLLNO ROLLNO
---------- ----------
1 1
2 2
3 3
3 3
4 4
3 3
3 3
5 5
ROLLNO NEW_ROLL
---------- ----------
1 1
2 2
3 3
3 3
4 4
3 3
3 3
5 5
Outer Join:
1. Left Outer Join
2. Right outer Join
3. Full Outer Join
1. Left Outer Join:
6 rows selected.
6 rows selected.
3. Full Outer Join :
9 rows selected.
SET OPERATORS:
Operators Description
Union Displays all rows selected by either query
Union all Displays all rows selected by either query along with
the duplicates.
Intersect Displays all distinct rows selected by both queries.
Minus Displays all rows present in one table but not in
another.
1. Union :
ROLLNO
----------
1
2
3
4
5
10
12
13
8 rows selected.
SQL> select rollno from student11 union all select rollno from
student12;
ROLLNO
----------
1
2
3
4
3
5
10
12
13
2
3
11 rows selected.
2. Intersect :
ROLLNO
----------
2
3
3. Minus:
ROLLNO
----------
1
4
5
ROLLNO
----------
10
12
13
ARITHMETIC FUNCTIONS:
Arithmetic Description
Function
ABS(n) Returns the absolute values of numeric n.
D
-
X
34
TRUNC(5.67689,2)
----------------
5.67
ROUND(5.67689,2)
----------------
5.68
FLOOR(3.1234)
-------------
3
CHARACTER FUNCTIONS:
Character Description
Function
CHR(n) Returns the character that is binary
equivalent to n.
CONCAT(‘a’,’b’) Returns the concatenation of stirng ‘a’ with
string ‘b’
INITCAP(‘a’) Returns the first character of each word in
uppercase.
LOWER(‘a’) Returns all characters in upper case.
LPA
---
rup
LPA
---
CCR
SQL> select rpad('rupali',3,'c') from dual;
RPA
---
rup
RPA
---
RCC
LTRI
----
fdfd
LTRI
----
sfdfd
RTRIM
-----
dsfdf
SQL> select substr('MMCOE',1,3) from dual;
SUB
---
MMC
DATE FUNCTIONS:
VIEWS:
Creating Views:
Dropping view:
SEQUENCE :
About Indexes :
• More indexes = better performance?
• Indexes take space
• Indexes need to be maintained when data is updated
• Indexes have one more level of indirection.
• Perhaps not a problem for main memory, but can be
problematic for disk
• Automatic index selection is still an area of active
research