Ankit Dixit 100420825160
EXPERIMENT NO:1
AIM: Table creation in SQL and populating it with data using desc table
command.
...
Ankit Dixit 100420825160
new 1:insert into department values(1,'CS')
1 row created.
SQL>/
Enter value for deptno:2
Enter v...
Ankit Dixit 100420825160
1 row created.
SQL>/
Enter value for empno:3
Enter value for empname:jammy
Enter value for deptna...
Ankit Dixit 100420825160
EXPERIMENT NO:2
AIM: Using drop table delete simple select queries,queries with where clause.
1) ...
Ankit Dixit 100420825160
-------------
2
6) Delete records of employee living in Goa.
SQL>delete from employee where city=...
Ankit Dixit 100420825160
EXPERIMENT NO: 3
AIM: Altering the schema and modifying contents of the table using update
comman...
Ankit Dixit 100420825160
EXPERIMENT NO:4
AIM: Applying data constraints (primary key, foreign key, check, not null,
unique...
Ankit Dixit 100420825160
Foreign key(p_name) references employee;
Table created.
Adding foreign key to table manager table...
Ankit Dixit 100420825160
EXPERIMENT NO. 5
AIM: Using arithmetic, logic operators in select in select statement, aggregate
...
Ankit Dixit 100420825160
TNAME TABNAME CLUSTERED
-------------------------------------------------------------------------...
Ankit Dixit 100420825160
4) find street, city of all employee whose name contain letter 'b'.
SQL > select street, city fro...
Ankit Dixit 100420825160
6 rows selected
EXPERIMENT NO. 6
AIM: Using nested queries in SELECT statement with IN, ALL, AVER...
Ankit Dixit 100420825160
EMPNO EMPNAME DEPTNAME STREET CITY SALARY
------------ --------------- ----------------- --------...
Ankit Dixit 100420825160
EXPERIMENT NO: 7
AIM: Displaying Data for multiple tables.
1) Find name,street,cities of all who ...
Ankit Dixit 100420825160
5) Give all employees of quarks a 10% salary rise.
SQL>select update works
2 set salary =salary+s...
Ankit Dixit 100420825160
EXPERIMENT NO.8
AIM: Various operations using DUAL TABLE.
1) CONVERSATION FUNCTION :
a)SYSDATE: I...
Ankit Dixit 100420825160
15
b)POWER(m,n):Returns 'm' raised to the 'nth' power such that 'n' must be an integer, else an
e...
Ankit Dixit 100420825160
david
b)INITCAP:Return string with initial letter in upper case.
SQL>select initcap('david') INIT...
Ankit Dixit 100420825160
*****david
i)RPAD(char1,n,[char2]):Returns 'char1',rigth padded to length 'n' with the
characters...
Ankit Dixit 100420825160
EXPERIMENT NO:9
AIM: Creation of Sequences and Indexes.
SEQUENCES
1) Create a sequence by the nam...
Ankit Dixit 100420825160
EXPERIMENT NO:10
AIM: Security management (grant ,revoke), view creation.
Security Management:
Or...
Ankit Dixit 100420825160
on student
from david;
Revoke succeeded;
VIEW:
After a table is created and populated with data,i...
Ankit Dixit 100420825160
aman 98
jatin 95
UPDATING VIEWS:
Views can also be used for data manipulation.Views on which data...
Ankit Dixit 100420825160
1) An INSERT operation is not allowed.
2) The DELETE or MODIFY operations do not affect the Maste...
Ankit Dixit 100420825160
Cache: It specifies how many values of sequence oracle pre-allocates and keeps in memory
for fast...
Upcoming SlideShare
Loading in...5
×

Dbms file

409

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
409
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Dbms file"

  1. 1. Ankit Dixit 100420825160 EXPERIMENT NO:1 AIM: Table creation in SQL and populating it with data using desc table command. 1) Create the following tables:- a. department(deptno,deptname) b. employee(empno,empname,deptname,street,city,salary) a. Creating department table: SQL>create table department (deptno number(20),deptname varchar2(15)); Table created. b. Creating employee table: SQL>create table employee (empno number(20),empname varchar2(15),deptname varchar2(15),street varchar2(20),city varchar2(20),salary number(5,2)); Table created. 2)Give command to view the schema of department and employee table. SQL>desc department; Name Null? Type ------------------------------------------------------------------------------------------------------------- DEPTNO NUMBER(20) DEPTNAME VARCHAR2(15) SQL>desc employee; Name Null? Type ------------------------------------------------------------------------------------------------------------- EMPNO NUMBER(20) EMPNAME VARCHAR2(15) DEPTNAME VARCHAR2(15) STREET VARCHAR2(20) CITY VARCHAR2(20) SALARY NUMBER(5,2) 3) Use insert statement to populate the table created. a.Inserting data in department table. SQL>insert into department values(&deptno,'&deptname) 2; Enter value for deptno:1 Enter value for deptname:CS old 1:insert into department values(&deptno,'&deptname') 1 Information Technology
  2. 2. Ankit Dixit 100420825160 new 1:insert into department values(1,'CS') 1 row created. SQL>/ Enter value for deptno:2 Enter value for deptname:IT old 1:insert into department values(&deptno,'&deptname') new 1:insert into department values(2,'IT') 1 row created. SQL>/ Enter value for deptno:3 Enter value for deptname:ME old 1:insert into department values(&deptno,'&deptname') new 1:insert into department values(3,'ME') 1 row created. b. Inserting data in employee table. SQL>insert into employee values(&empno,'&empname','&deptname','&street','city','&salary'); Enter value for empno:1 Enter value for empname:david Enter value for deptname:IT Enter value for street:abc Enter value for city:Mumbai Enter value for salary:500 old 1:insert into employee values(&empno.'&empname','&deptname','&street','&city','&salary') new 1:insert into employee values(1,'david','IT','abc','Mumbai',500) 1 row created. SQL>/ Enter value for empno:2 Enter value for empname:sunny Enter value for deptname:IT Enter value for street:sd Enter value for city:Chd Enter value for salary:200 old 1:insert into employee values(&empno.'&empname','&deptname','&street','&city','&salary') new 1:insert into employee values(2,'sunny','IT','sd','Chd',200) 2 Information Technology
  3. 3. Ankit Dixit 100420825160 1 row created. SQL>/ Enter value for empno:3 Enter value for empname:jammy Enter value for deptname:IT Enter value for street:ef Enter value for city:Mumbai Enter value for salary:250 old 1:insert into employee values(&empno.'&empname','&deptname','&street','&city','&salary') new 1:insert into employee values(3,'jammy','IT','ef','Mumbai',250) 1 row created. SQL>/ Enter value for empno:4 Enter value for empname:salman Enter value for deptname:CS Enter value for street:viha Enter value for city:Ldh Enter value for salary:750 old 1:insert into employee values(&empno.'&empname','&deptname','&street','&city','&salary') new 1:insert into employee values(4,'salman','CS','viha','Ldh',750) 1 row created. 3 Information Technology
  4. 4. Ankit Dixit 100420825160 EXPERIMENT NO:2 AIM: Using drop table delete simple select queries,queries with where clause. 1) Find record of all employees. SQL>select*from employees; EMPNO EMPNAME DEPTNAME STREET CITY SALARY ------------------------------------------------------------------------------------------------------------- 1. David IT abc Goa 500 2. Gopal IT sd Chd 250 3. Ravi IT sd Ldh 300 4. Sunny CS de Goa 450 2) Find empno and empnameof all employees. SQL>select empno,empname from employees; EMPNO EMPNAME 1. David 2. Gopal 3. Ravi 4. Sunny 3) Find records of all employees living in Goa. SQL>select * from employees where city='Goa'; EMPNO EMPNAME DEPTNAME STREET CITY SALARY ------------------------------------------------------------------------------------------------------------- 1. David IT abc Goa 500 4. Sunny CS de Goa 450 4) List all department names SQL>select deptname from department DEPTNAME ------------------ CS IT 5) List deptno of 'IT' department. SQL>select deptno from department where deptname='IT'; DEPTNO 4 Information Technology
  5. 5. Ankit Dixit 100420825160 ------------- 2 6) Delete records of employee living in Goa. SQL>delete from employee where city='Goa' 2 rows deleted. 7) Delete all records of department . SQL>delete from department; 3 rows selected. 8) Drop department table with all its contents. SQL>drop table department; Table Dropped. 5 Information Technology
  6. 6. Ankit Dixit 100420825160 EXPERIMENT NO: 3 AIM: Altering the schema and modifying contents of the table using update commands. a) Create table department(deptno,deptname) SQL>Create table department. 2) (deptno number(20), 3) deptname varchar2(15) 4) ); Table created. b) Add a new column 'ranking' in department table. SQL>alter table department 2) add ranking number(5); Table created. c) Increase the length of department to20. SQL>alter table department 2) modify depart name varchar2(20); Table created. d)change the deptno of IT tol. SQL>update department set deptno=1, 2) where deptname='IT'; 1 row updated. e) Increase salary of the employees of accounts department by 200. SQL>update employee set salary=salary+200 2) where deptname='accounts'; 2 rows updated. 6 Information Technology
  7. 7. Ankit Dixit 100420825160 EXPERIMENT NO:4 AIM: Applying data constraints (primary key, foreign key, check, not null, unique). Create the following tables: Done below. Apply primary key constraints and check constraints as mentioned. Employee (p_name, street, city) primary key(p_name) SQL>create table employee (p_name varchar2(20) primary key, Street varchar2(20), City varchar2(20) ); Table created. Company(companyname,city) primary key(c_name) SQL>create table company (c_name varchar2(20) primary key, City varchar2(20) ); Table created. Works(p_name,c_name,salary) check salary>0,primary key(p_name) SQL>created table works (p_name varchar2(20) primary key, C_name varchar2(20), Salary number(10,2), Check (salary>0) ); Table created. Manage(p_name, m_name) primary key(p_name) SQL>created table manager (p_name varchar2(20) primary key, M_name varchar2(20) ); Table created. Alter the tables to show the following foreign key relation ship. Adding foreign key to the works table. SQL>alter table works Add constraints p_namefk 7 Information Technology
  8. 8. Ankit Dixit 100420825160 Foreign key(p_name) references employee; Table created. Adding foreign key to table manager table. SQL>ed Wrote file afiedt.buf Alter table manager Add constraint pl_namefk. * foreign key (p_namr) references employee ; Table created. SQL>alter table manager Add constraint m_namefk Foreign key(m_name) reference company ); Table altered. Apply unique constraint on deptno of department table. SQL>alter table department 2 add constrain depn_uk 3 unique(deptname); Table altered. Apply NOT NULL constrain to deptname of department table. SQL>alter table department 2 modify deptname not null; Table altered. 8 Information Technology
  9. 9. Ankit Dixit 100420825160 EXPERIMENT NO. 5 AIM: Using arithmetic, logic operators in select in select statement, aggregate function. 1) Apply foreign key relationship relationshop between depatment and emploee 1 tables. SQL> alter table employee 1 add constraint dep_ft foreing key(deptname) references department; Table altered. 2) Find all employees with salary more than 50000 or living in Mumbai; EMPNAME ---------------------- Vicky Param Rocky Jackie 3) Find all tables existing in your user. SQL > select* from tab; 9 Information Technology
  10. 10. Ankit Dixit 100420825160 TNAME TABNAME CLUSTERED -------------------------------------------------------------------------------------------------------------------- - BONUS TABLE COMPANY TABLE DEP TABLE DEPARTMENT TABLE DEP1 TABLE DEP2 TABLE DEP3 TABLE EMPLOYEE TABLE FREQUENTS TABLE LIKES TABLE TNAME TABTYPE CLUSTERED -------------------------------------------------------------------------------------------------------------------- --------- LOG TABLE MANAGER TABLE SALARY TABLE VW_STU VIEW WORKS TABLE 19 rows selected. 10 Information Technology
  11. 11. Ankit Dixit 100420825160 4) find street, city of all employee whose name contain letter 'b'. SQL > select street, city from employee 1 where empname like(%b%); STREET CITY -------------------------------------------------------------------------------------------------------- Aanad pta abc chd 5) List of employees alphabetically SQL> select * from employee1 Order by (empname); EMPNO EMPNAME DEPTNAME STREET CITY SALARY ------------------------------------------------------------------------------------------------------------- 2 SALMAN IT anand pta 200 5 jackie CS anand pta 1000 3 param ME sangam chd 26000 EMPNO EMPNAME DEPTNAME STREET CITY SALARY ------------------------------------------------------------------------------------------------------------- 4 rocky accounts sdc Mumbai 1200 6 sonu IT abc chd 10000 1 vicky IT abc chd 250000 11 Information Technology
  12. 12. Ankit Dixit 100420825160 6 rows selected EXPERIMENT NO. 6 AIM: Using nested queries in SELECT statement with IN, ALL, AVERAGE a ANY FUNCTION List all employees with salary in the range of 5000-10,000. SQL>select empname from employee 2 where salary between 5,000 and 10,000 ; EMPNAME ----------------- Jackie Sonu List all employee in decreasing order of salary. SQL>select empname,salary from employee 2 order by (salary) desc ; EMPNAME SALARY ---------------- ------------ Param 26,000 Vicky 25,000 Jackie 10,000 Sonu 10,000 Rocky 1,200 Salman 200 6 rows selected. Select records of employees,who neither live in Mumbai nor in Calcutta. SQL>select *from employee[ 2 where city<>'Mumbai' and city<>'Calcutta'] ; EMPNO EMPNAME DEPTNAME STREET CITY SALARY ----------- --------------- ----------------- -------------- -------- --------- 1 Vicky IT abc chd 25,000 2 Salman IT anand pta 200 3 Param ME Sangam chd 26,000 12 Information Technology
  13. 13. Ankit Dixit 100420825160 EMPNO EMPNAME DEPTNAME STREET CITY SALARY ------------ --------------- ----------------- ------------ -------- --------- 4 Jackie CS anand pta 10,000 5 Sonu IT abc chd 10,000 Find number of records in employee table. SQL>select count(*)COUNT from employee ; COUNT ----------- 6 Delete records of employee with salary of all employees. SQL>delete from employee [2 where salary <(select avg(salary) from employee] ; 4 rows are deleted. Find average salary for each department. SQL>select avg(salary)"AVERAGE SALARY" from works 2 group by (c_name); AVERAGE SALARY ----------------------------- 10,000 13,050 20666.6667 13 Information Technology
  14. 14. Ankit Dixit 100420825160 EXPERIMENT NO: 7 AIM: Displaying Data for multiple tables. 1) Find name,street,cities of all who works for 'quarks' and earn more than 10,000. SQL> select employee.p_name,street,city from employee, works 2 where employee.p_name=works.p_name 3 and c_name='quarks' and salary>'100000'; P_NAME STREET CITY ------------- ------------- --------- VICKY fgh chd 2) Find names of employees who earn more than every employee of quarks. SQL>select p_name from works 2 where salary >(select max(salary) from works 3 where c_name='quarks'); P_NAME ------------------ aman 3) Find names of all countries located in every city in which quarks is located. SQL>select c_name from company 2 where city in (select city from company 3 where c_name='quarks') 4 and c_name<>='quarks'; No rows selected 4) Find names of employees who live in rhe same city as the company for which they work . SQL>select employee.p_name employee,company,works 2 where employee.city=company.city 3 and employee.p_name=works.p_name; P_NAME -------------- vicky aman 14 Information Technology
  15. 15. Ankit Dixit 100420825160 5) Give all employees of quarks a 10% salary rise. SQL>select update works 2 set salary =salary+salary*0.1 3 where c_name='quarks'; 2 rows updated. 6) Find names of alll employees who don't work for infosys. SQL>select p_name from works 2 where c_name<> 'Infosys'; P_NAME -------------- vicky param salman jagdeep nitin 7) Delete al tuples in work selection for employees of Infosys. SQL>delete from works. 2 where c_name='Infosys'; 1 row selected. 15 Information Technology
  16. 16. Ankit Dixit 100420825160 EXPERIMENT NO.8 AIM: Various operations using DUAL TABLE. 1) CONVERSATION FUNCTION : a)SYSDATE: It returns current system date SQL>select sysdate from dual ; SYSDATE ------------------- 21-NOV-08 b)TO_DATE CONVERSION: TO-date(char,fmt) SQL>select To_Date(nov-23-88,'dd-mm-yy')from dual; TO_DATE ------------------- 23-nov-88 c)TO_NO(text/date): SQL>select To_No('567') from dual ; TO_NO ---------------------- 567 d)TO_char(no.,date,fmt):This function converts the no. or date value a varchar(10)character string with the format. SQL>select To_char(12214,'#99,999') from dual ; To_char ------------------ 12,214 2)NUMERIC FUNCTION: a)ABS:Return absolute value. SQL>select abs(-15)from dual; ABS(-15) --------------- 16 Information Technology
  17. 17. Ankit Dixit 100420825160 15 b)POWER(m,n):Returns 'm' raised to the 'nth' power such that 'n' must be an integer, else an error is returned. SQL>select power(7,3)from dual; POWER ------------------ 343 c)EXPRESSION SQL>select 7*2"MULTIPLY" from dual; MULTIPLY ---------------------- 14 d)ROUND(n,m): Returns 'n' rounded to 'm' place right of the decimal point. if 'm' is omitted,'n' is roundedto 0 place.'m'can be negative to round off digits left of the decimal point. 'm’ must be a integer. SQL> select round (12.129,2) from dual; ROUND(12.29.3) ................................. 12.13 e)SQRT:Returns square root. SQL>Select sqrt(36) from dual; SQRT(36) ................................. 6 f)LEAST(n1,n2,n3) SQL> select least(8,9,7) from dual; LEAST ---------- 7 3)STRING FUNCTIONS: a) LOWER:Returns char,with all letters in lower case. SQL>select lower('DAVID') LOWER from dual; LOWER ................. 17 Information Technology
  18. 18. Ankit Dixit 100420825160 david b)INITCAP:Return string with initial letter in upper case. SQL>select initcap('david') INITCAP from dual; INITCAP .................... David c)UPPER:Return char,with letter forced to uppercase. SQL>select upper('david') UPPER from dual; UPPER ................. DAVID d)SUBSTR(char,m,n):Returns a portion of char,begining at character 'm' exceeding upto the 'n' character. SQL>select substr('david',1,3)"substring" from dual; sub ... dav e)LENGTH(char):Returns the length of char. SQL>select length('david')"LENGTH" from dual; LENGTH .................... 5 f)LTRIM(char,[set]):Returns character from the left of char with initial characters removed upto the first character not in set. SQL>select ltrim('david','d')"Left" from dual; Lef ......... avid g)RTRIM(char,[set]):Returns character from the left of char with initial characters removed upto the first character not in set. SQL>select rtrim('david','d') "Right" from dual; Rig ...... Davi h)LPAD(char1,n,[char2]):Returns 'char1' left padded to length 'n' with the sequence of characters in 'char2' defaults to blanks. SQL>select lpad('david',10,'*') "LPAD" from dual; LPAD ..................... 18 Information Technology
  19. 19. Ankit Dixit 100420825160 *****david i)RPAD(char1,n,[char2]):Returns 'char1',rigth padded to length 'n' with the characters in 'char2',replicated as many times as necessary. RPAD ................... david***** j)CONCAT(ch1,ch2):where ch1 and ch2 are character string this function returns c2 appended to c1,if c1 is null then c2 is return and vice versa.If both are null then null is return. CONCAT ----------- Ietbhaddal k)CHR(x): where x is any number, it is inverse of ASCII. SQL>select CHR(97)from dual; CHR ------ a 4)CONVERSION FUNCTIONS: TO_CHAR: i)SQL>select to_char(sysdate,'DD-MONTH-YY')from dual; TO_CHAR(SYSDATE ........................... 21-NOVEMBER-08 ii)SQL>select to_char(sysdate,'DDTH-MON-YY')from dual; TO_CHAR(SYSDATE,'DDSP ............................ 21ST-NOV-08 iii)SQL>select to_char(sysdate,'DDSP-MON-YYYY)from dual; TO_CHAR(SYSDATE,'DDSP ............................... TWENTY-ONE-NOV-2008 iv)SQL>select to_char(sysdate,'DDSPTH-MON-YYYY')from dual; TO_CHAR(SYSDATE,'DDSPTH ................................ TWENTY-FIRST-NOV-2008 19 Information Technology
  20. 20. Ankit Dixit 100420825160 EXPERIMENT NO:9 AIM: Creation of Sequences and Indexes. SEQUENCES 1) Create a sequence by the name ADDR_SEQ . SQL>create sequence ADDR_SEQ start with 1; Sequence created. 2) Select next value for sequence. SQL> Select ADDR_SEQ .nextval from dual table; NEXTVAL --------- 1 3) View the current value for sequence. SQL>select ADDR_SEQ.currval from dual; CURRVAL --------- 1 INDEX 1) Create a simple index on VERI_EMP_NO column of the ACCT_MSTR table. SQL>create index idxVERI_EMP_NO on ACCT_MSTR(VERI_EMP_NO); Index created. 2) Create a composite index on the TRANS_MSTR table on columns TRANS_NO and ACCT_NO. SQL>create index idxTRANS_MSTR on TRANS_MSTR(TRANS_NO, ACCT_NO); Index created. 20 Information Technology
  21. 21. Ankit Dixit 100420825160 EXPERIMENT NO:10 AIM: Security management (grant ,revoke), view creation. Security Management: Oracle provides extensive security features in order to safegaurd information stored in its table from unauthorised viewing and damage. Depending on a user's status and responsibility, appropriate rights on oracle's resources can be assigned to the user. objects that are created by a user are owned and controlled by that user. If a user wishes to access any of the objects belonging for such access. This is called revoking of privileges. Granting privileges using the GRANT statement: syntax: grant {object privileges} on objectname to username [with grant option]; object privileges: Alter: allows the grantee to change the table defination with the ALTER TABLE command. delete: allows the grantee to remove the records from the table with the DELETE commands. Index: allows the grantee to create an index on the table with the CREATE INDEX command . Insert: allows the grantee to add records to the table with the INSERT command. Select: allows the grantee to query the table with the SELECT command . Update: alows the grantee to modify the records in the tables with the SELECT command. with grant option allows the grantee to in turn object privileges to other users. Example: SQL> grant all on stu to david; Grant succeeded. REVOLKING PRIVILEGES GIVEN The revoke statement is used to deny the grant given on an object. Syntax:revoke {object privileges} on object from username; Example: SQL>revoke update 21 Information Technology
  22. 22. Ankit Dixit 100420825160 on student from david; Revoke succeeded; VIEW: After a table is created and populated with data,it may become necessary to prevent all users from accessing all columns of a table,for security reasons. This would mean creating several tables having the appropriate number of columns and assigning the specific users to each table as required.This will answer data security requirements but will rise give to great deal of redundant data being resident in tables, in the database. To reduce the redundant data to the minimum possible.Oracle allows the creation of an object called view.A view is mapped to a SELECT sentence.It is stored only as a defination in Oracle's system catalogue. when a reference is made to a view, its defination is scanned,the base table is opened and the view created on top of the base table. Hence , a view holds no data untill a specific call to the view is made.This reduces redundant data on the database to a large extent. A query fired on the view run slower than a query fired on a table.Some views are only created for the purpose of looking at the base table data. REASONS FOR VIEW CREATION: 1. When data security is required. 2. When data redundancy is to be kept to the minimum while maintaining data security. CREATION OF VIEWS: Syntax: create view viewname as select columnname,columnname from tablename where columnname=expression list group by grouping criteria having predicate; Example: SQL>create view vw_st1 as select name, marks from stu; view created. SELECTING A DATA SET FROM A VIEW: Syntax:select columnname,columnname from viewname; Example: SQL>select * from vw_st1; NAME MARKS -------------- ------------------ vicky 100 22 Information Technology
  23. 23. Ankit Dixit 100420825160 aman 98 jatin 95 UPDATING VIEWS: Views can also be used for data manipulation.Views on which data manipulation can be done are called updateable views. Views defined from single table . If user wants to INSERT records with the help of view,then the primary key column and all NOT NULL columns are excluded from the view defination. Example: a) Inserting data into the view. SQL>insert into vw _st1 values ('param',98); 1 row created. b)Modify the view data. SQL> update vw_st1 set marks='100' where name='vicky'; 1 row is updated c) Delete data otem from view. SQL>delete from vw_st1 where name='nitin'; 1 row added. A view can be created from more than one table. For the purpose of creating the view these tables will be linked by join condition specified in the where clause of the view definition. View defined from multiple tables(with having no referencing clause): If view is crated from multiple tables,which were not crated using a ‘Referencing clause’,then though the primary key column as well as the NOT NULL columns are included in the view definition the view’s behavior will be as follows: The INSERT,UPDATE or DELETE operation is not allowed. If attempting then Oracle displays an error message. View defined from multiple tables(with having referencing clause): If view is created from multiple tables, which were created using a ‘Referencing clause’,then though the primary key column as well as the NOT NULL columns are included in the view definition the view’s behaviour will be as follows: 23 Information Technology
  24. 24. Ankit Dixit 100420825160 1) An INSERT operation is not allowed. 2) The DELETE or MODIFY operations do not affect the Master table. 3) The view can be used to MODIFY the columns of the detail table included in the view. 4) If a delete operation is executed on the view, the corresponding records from the detail table will be deleted. Example: SQL>create view vw_empl as 2 select p_name, c_name,deptname 3 from works, department; View created. Destroying a view: Syntax: drop view viewname; Example: SQL>drop view vw_empl; View dropped. SEQUENCES: The quickest way to retrieve the data from the table is to have a column in a table whose data uniquely identify a row,so oracle provide an object called a SEQUENCE that can generate numeric values. The value generated can have the maximum of 38 digits. A sequence can be defined to: 1. Generate numbers in ascending and descending order. 2. Provide intervals between numbers. 3. Caching of sequence number in memory to speed up their availability. so the minimum information required for generating numbers using sequence is: a. The starting number. b. The maximum number that can be generated by sequence. c. The increment value for generating the next number. SYNTAX: Create Sequence<Sequence name>[increment by[n]] [start with [n]] [min value<x>] [max value<y>] Increment by: It specifies the interval between sequence numbers. Default value is 1 and it is optional. Min/Max value: It specifies the sequence min value and max value that a sequence can generate. Start with: It specifies the first sequence number to be generated. 24 Information Technology
  25. 25. Ankit Dixit 100420825160 Cache: It specifies how many values of sequence oracle pre-allocates and keeps in memory for faster access. The min value for this is 2. SQL> create sequence seq_iet 2 increment by 1 3 start with 1 4 min value 1 5 max value 999; Sequence created. 25 Information Technology

×