0% found this document useful (0 votes)
37 views

SQL Structured Query Language

1) The document discusses SQL and relational database management systems (RDBMS). It provides information on data types in Oracle, DDL, DML, DCL and TCL commands in SQL. 2) Key topics covered include the history of databases and RDBMS, Oracle versions, Codd's rules for DBMS, data types in Oracle, operators, and commands for data definition, manipulation, control, and transactions. 3) The document is intended to provide an overview of concepts in SQL and relational databases including Oracle with examples of commands and their usage.

Uploaded by

manojprabhakar_m
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

SQL Structured Query Language

1) The document discusses SQL and relational database management systems (RDBMS). It provides information on data types in Oracle, DDL, DML, DCL and TCL commands in SQL. 2) Key topics covered include the history of databases and RDBMS, Oracle versions, Codd's rules for DBMS, data types in Oracle, operators, and commands for data definition, manipulation, control, and transactions. 3) The document is intended to provide an overview of concepts in SQL and relational databases including Oracle with examples of commands and their usage.

Uploaded by

manojprabhakar_m
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL Structured Query Language Software | ------------------------------------------------------------------------| | | Application S/w System s/w Programming Lang s/w (Eg.

. Inventory mgmt syst) (Eg., Windows,unix,dos) (Eg., C, C++, JAVA) Management Information System There will be a data flow Data Collection of unorganized data Information Collection of organized data Database A Database is an organized collection of information To manage a database we need a DataBase management system What we will do with the database Management?(DBMS) 1) 2) 3) 4) Adding data Modifying data Deleting data Querying data

How RDBMS came? 1) Initially the amount of data was small so the data are stored in text files using c etc., 2) As the amount of data increased it became necessary to store the data in a database, so DBMS emerged (eg., DBASE, FOXPRO etc.,) 3) Here the data is stored in the form of table Table collection of data arranged in row and column. 4) Due to some drawbacks of DBMS, RDBMS(Relational Database management system) Came. Here we can relate more than one table automatically but in DBMS we have to Do that manually. 5) Then came ORDBMS (Object Relational Database management System). Oracle 9i is an ORDBMS. This is the only database specifically designed for internet development. Oracle 7 is a Relational Database Management System(RDBMS) Oracle 8,8i & 9i are Object Relational Database Management system(ORDBMS)

Types of Relations There are three types of Relations 1) One to One 2) One to Many 3) Many to Many CODDs Rules Dr.E.F.CODD framed 12 rules for dbms. Oracle 7 versions satisfied only 11 rules Oracle 9i satisfies all the 12 rules. Rules are 1) Information Rule. 2) The rule of guaranteed access. 3) The systematic treatment of null values. 4) The database description rule. 5) Comprehensive data sub language. 6) The view updating rule. 7) The insert and update rule 8) The physical independence rule 9) The logical data independence rule 10) The integrity independence rule. 11) Distribution rule 12) Non subversion rule. SQL | ---------------------------------------------------------------------------------------------------------| | | | DDL DML DCL TCL (Data Definition Lang) (Data Manipulation Lang) (Data Control Lang) (Transaction Control Lang) CREATE INSERT GRANT COMMIT ALTER SELECT REVOKE SAVEPOINT DROP UPDATE ROLLBACK TRUNCATE DELETE RENAME Data Types in Oracle Data type 1) 2) 3) 4) 5) 6) Varchar2(size) char(size) number(p,s) Date Long CLOB Description Variable-length character data Fixed length character data Variable length numeric data Date Variable-length character data upto 2 GB Character data upto 4 GB

7) Raw and Long Raw 8) Blob 9) BFile 10)Rowid 11) Timestamp 12) Interval year to month Interval day to second Operators In Oracle

Raw Binary data Binary data upto 4 GB Binary data stored in an external file upto 4GB Hexadecimal string representing the unique address of a row in its table. Date with fractional seconds store as interval of years and months store as interval of days to hours minutes and seconds

1) Arithmetic Operators 2) Relational Operators or Comparision Operators 3) Logical Operators. 1) Arithmetic Operators ( + , - , / , *) Examples: Select sal + 100 emp_salary from emp where empno = 7934; select sal - 100 from emp where empno = 7934; Select sal / 10 from emp where empno = 7934; Select sal * 0.10 from emp where empno = 7934; 2) Relational Operators ( < , <= , > , >= , <> , NOT, BETWEEN, LIKE , IS NULL , IN) Examples : Select empno from emp where sal <= 5000; Select * from emp where sal >= 5000; Select * from emp where job <> CLERK; Select * from emp where job NOT IN (CLERK,SALESMAN); Select * from emp where sal between 4000 and 5000; Select * from emp where ename like A%; Select * from emp where ename like A_A; Select * from emp where comm IS NULL; 3) Logical Opeator (AND , OR , NOT) select * from emp where job = CLERK AND sal <= 10000; select * from emp where job = CLERK OR job = SA_REP; select * from emp where empno NOT IN 7878;

DDL Data Definition Language (1) Create syntax: Create table <table name> (column datatype, [column datatype]) Example: Create table employee1(empno number(3),empname varchar2(25),deptno number(3),salary number(7,2)); Create table employee2 as select * from employee1; (2) Alter Alter can be used along with ADD, MODIFY, DROP COLUMN,RENAME COLUMN syntax : Alter table <table-name> column-name datatype Example: Alter table employee add doj date; Alter table employee modify empname varchar2(35); Alter table employee1 drop column doj; Alter table stu_dtl rename column tam to kan; (3) Drop Syntax : Drop table <table-name> Example : Drop table employee1; (4) Rename syntax : Rename <old-name> To <new-name> Example : Rename employee to empy; (5) Truncate Syntax : Truncate table <table-name> Example : Truncate table empy;

Removes all the rows , storage space is removed,structure remains the same. Cannot rollback the transaction . nonlogged. DML Data Manipulation Language (1)Insert Syntax : Insert into <table-name> values (column_value1,column_value2.); Example : Insert into empy values(101,yamini,201,9000); Insert into empy(empno,ename) values(103,yamini); Insert into empy values (&empno,&empname,&deptno,&salary); Insert into empy select * from employees; (2) Select Syntax : Select * from <table-name> where condition; Example : Select * from empy; Select empno,empname from empy where empno = 101; (3) Update syntax : update <table-name> set column-name = value; Example : update empy set sal = 10000 where empno = 101; (4) Delete syntax : Delete from <table-name> where condition; Example : Delete from empy where empno = 110; Delete will delete all the rows, storage space is not removed , structure remains the same. DCL Data Control Language (1)Grant syntax : Grant all on < table-name > to user-name; Example : Grant all on empy to scott; (2)Revoke syntax : Revoke all on <table-name> from user-name; Example : Revoke all on empy from scott;

TCL Transaction Control Language (1)commit syntax: commit; This will permanently store everything in the database. (2)Savepoint Savepoints are small intermediate transaction points. It will divide a long transaction into small units. (3)Rollback Rollback will undo all the transaction done previously upto last commits or upto the save point. More about Commit, Savepoint and Rollback How implicit automatic commit occurs 1) DDL statement is issued 2) DCL statement is issued 3) Normal exit from sql editor. How implicit rollback occurs 1) During an abnormal termination of sql editor. 2) During system failures When a transaction is interrupted by a system failure , the entire transaction is automatically rolled back. This prevents the error from causing unwanted changes to data and returns tables to the state of last commit. AUTOCOMMIT: Autocommit command in sql prompt can be set to ON and OFF. ON automatically commit after each DML statement. These transactions cannot be rollbacked. OFF explicitly we can use COMMIT command to permanently save everything to database. Before commit Explicitly Every transaction done is temporary until the transaction is committed. DML operations initially affect database buffer so previous state can be recovered. Current user who done the transaction can view the changes but other user cannot view the changes done by the current user. Also the affected rows are locked so that other user cannot change that rows. After commit

Changes are made permanent. Previous state is lost (cannot be rolled back) All users can view the result. Rows are unlocked for manipulation of other users.

You might also like