0% found this document useful (0 votes)
19 views20 pages

Advanced SQL

A view can select data from one or more tables and present it as if it were a single table. Views allow for restricting and arranging rows from base tables. Indexes can be created on tables to improve query performance. Indexes like a book index help locate and retrieve data faster.

Uploaded by

21Siddhi Doke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views20 pages

Advanced SQL

A view can select data from one or more tables and present it as if it were a single table. Views allow for restricting and arranging rows from base tables. Indexes can be created on tables to improve query performance. Indexes like a book index help locate and retrieve data faster.

Uploaded by

21Siddhi Doke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Advance Features of SQL

A view: can contain all rows of a table or selected


rows from one or more tables. A view can be created
from one or many tables which depends on the
written SQL query to create a view.
• CREATE VIEW view_name AS SELECT column1,
column2..... FROM table_name WHERE
[condition];

CREATE VIEW COMPANY_VIEW AS


SELECT ID, NAME, AGE FROM COMPANY;
ID Name Age Address Salary
1 Ajay 25 PUNE 10,000
2 Rahul 36 Ambad 15,000
3 Seema 27 aurangabad 25,000
4 Jayshree 28 Jalna 35,000
5 KISAN 30 JALGAON 40,000

CREATE VIEW COMPANY_VIEW AS


SELECT ID, NAME, AGE FROM COMPANY;

SELECT * FROM COMPANY_VIEW;


ID Name Age
1 Ajay 25
2 Rahul 36
3 Seema 27
4 Jayshree 28
5 KISAN 30
ID Name Age Address Salary
1 Ajay 25 PUNE 10,000
2 Rahul 36 Ambad 15,000
3 Seema 27 aurangabad 25,000
4 Jayshree 28 Jalna 35,000
5 KISAN 30 JALGAON 40,000

CREATE VIEW V1 AS SELECT * FROM COMPANY


WHERE SAL >= 25000

SELECT * FROM V1
ID Name Age Address Salary

3 Seema 27 aurangabad 25,000


4 Jayshree 28 Jalna 35,000
5 KISAN 30 JALGAON 40,000
ID Name Age Address Salary
1 Ajay 25 PUNE 10,000
2 Rahul 36 Ambad 15,000
3 Seema 27 aurangabad 25,000
4 Jayshree 28 Jalna 35,000
5 KISAN 30 JALGAON 40,000

CREATE VIEW V2(eno ,Emp_name ,age ) AS SELECT id,name,age


FROM COMPANY
WHERE age > 27

SELECT * FROM V2
eno Emp_name age

2 Rahul 36
4 Jayshree 28
5 KISAN 30
Dropping Views

DROP VIEW view_name;


DROP VIEW COMPANY_VIEW;
Activity
• Create view called Stud_DBM of computer course student
• Display the content of Stud_DBM view
• Remove the view Stud_DBM
• Create Stud_vu view on student table
• Create view called emp_vu30 on employee number ,ename ,deptno
from EMP table
• Consider Schema Employee_Details (empname,eid,DOB,sal,job)
Create view on employee_Details table having attribute (empname ,
empid, DOB ,salary ,job) where salary is greater than 20.000
• Consider following Schema Depositor (Acc_no, name,PAN ,Balance )
Create view on depositor having attribute (Acc_no,PAN) where balance
is greater than 100000
• Person (Pid,name , address , city ,phone)
• Create view View_person containing details of person from city
‘Mumbai’ and ‘pune’
SYNONYM
• CREATE SYNONYM statement to create an
alternative name for a database object such
as a table, view, sequence, procedure,
stored function
• CREATE SYNONYM synonym_name
FOR object;
• CREATE SYNONYM s FOR inventories;
• CREATE SYNONYM s1 FOR app_suppliers;
SELECT * FROM s;
Drop SYNONYM

• DROP SYNONYM synonym_name;


• DROP SYNONYM stock;
Activity
• Create synonyms for class table .write a
steps to create synonyms
• Create synonym syn_person on table
person_details
• Delete synonym syn_person .
• Write syntax and example of create and
drop synonym
sequence
• which is a database object from which multiple
users may generate unique integers.
Syntax
CREATE SEQUENCE sequence_name
INCREMENT BY value
START WITH value
MINVALUE value
MAXVALUE value
CYCLE/ NOCYCLE

The following statement creates the sequence customers_seq


CREATE SEQUENCE customers_seq
START WITH 1
INCREMENT BY 2
NOCYCLE;
CREATE SEQUENCE dept_seq
MINVALUE 1
START WITH 1
INCREMENT BY 2

Dept(ID,Name)
Insert into dept values ( dept_seq.nextval,’IT’)
ALTER SEQUENCE seq_name
Alter sequence INCREMENT BY 124;

Alter sequence seq_name


increment by n Alter sequence dept_seq
Maxvalue n increment by 10
Cycle Maxvalue 100
Cycle
Drop Sequence

• DROP SEQUENCE sequence_name;


• DROP SEQUENCE supplier_seq;
Activity
• Create sequence dept_seq start with 50 and increment by 10
maxvalue 9999 nocycle
• Create sequence starting with 100
• Create sequence mytableidseq increment by 1 start with 1000
• Create a sequence srno_seq starting with 10 and increment by one
• Create sequence for employee table. also alter the created
sequence
• Create sequence seq1 with starting vlaue 1 and maximum value
20 with an increment of 1 . Consider Schema customer {custno ,
custname, pnoneno} And use seq1 sequence for inserting a row
in custemer table
• Create sequence seq_pid with starting vlaue 100 and maximum
value 150 with an increment of 1 . Consider Schema person
{personid , name, city ,phoneno) And use seq_pid sequence for
inserting a row in person table
• Create sequence for Dept. table. also alter the created sequence
Simple INDEX

• CREATE INDEX index_name


ON table_name(column1)

CREATE INDEX ind1


ON student (Stud_name)
Composite INDEX

• CREATE INDEX index_name


ON table_name(column1,column2….)

CREATE INDEX ind2 ON student (Stud_name, mark)


Unique INDEX
Unique index does not allow any
duplicate value to be inserted into table

• CREATE unique INDEX index_name


ON table_name(column1,column2….)

CREATE unique INDEX ind3


ON student (roll_no)
Implicit Index
• Implicit index are created
automatically by the database
when object is created . Such index
are created for primary key and
unique constraint
Drop Index

• DROP Index index_name;


• DROP index ind1;
Activity

• Describe simple and composite


index

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy