Download presentation
Presentation is loading. Please wait.
1
ORACLE SQL
2
SQL*Plus commands Sqlplus username/password ALTER USER user-name IDENTIFIED BY newpassword START filename filename CLEAR SCREEN HELP <command> SAVE filename[.ext] REPLACE|APPEND EXIT
3
SQL Both an ANSI and ISO standard Types of commands:
Data Definition Language (DDL) : Create, Alter, Drop, Rename, Truncate Data Manipulation Language (DML): Insert, Delete, Update Data Retrieval: Select Transaction Control: Commit, Rollback, Savepoint Data Control Language (DCL): Grant, Revoke
4
DEPARTMENT POSITION QUALIFICATION Dept ID Name Location 10 Finance
Charlotte 20 Infosys New York 30 Marketing Woodbridge 40 Accountant California POSITION QUALIFICATION Position ID Description 1 President 2 Manager 3 Programmer 4 Accountant 5 Salesman Qualification ID Description 1 Doctorate 2 Masters 3 Bachelors 4 Associates
5
EMPLOYEE Emp ID Last Name First Position Super Hire Date Salary Comm
Dept Qual 111 Smith John 1 04/15/60 265000 3500 10 246 Houston Larry 2 05/19/67 150000 1000 40 123 Roberts Sandi 12/02/91 75000 433 McCall Alex 3 543 05/10/97 66500 20 4 Dev Dereck 03/15/95 80000 2000 200 Shaw Jinku 5 135 01/03/00 24500 3000 30 222 Chen Sunny 08/15/99 35000 Garner Stanley 02/29/96 45000 5000
6
Data Definition Language:
CREATE TABLE {table} ( {column datatype [DEFAULT expr] [column_constraint] ... | table_constraint} [, { column datatype [DEFAULT expr] [column_constraint] ... ) ALTER TABLE {table} [ADD|MODIFY {column datatype [DEFAULT expr] [column_constraint]} [DROP drop_clause] DROP TABLE {table} [cascade constraints] DESC {table}
7
empid Decimal(10) NOT NULL, positionid Number(2),
CREATE TABLE Emp ( empid Decimal(10) NOT NULL, positionid Number(2), supervisorid Number(3), deptid Number(2), qualid Number(1), lname varchar2(10), fname varchar2(10), salary Decimal(10,2), hiredate Date, commission Decimal(4,2), PRIMARY KEY (empid)) FOREIGN KEY (positionid) REFERENCES Position(positionid), FOREIGN KEY (deptid) REFERENCES Dept(deptid), FOREIGN KEY (qualid) REFERENCES Qualification(qualid) ); ALTER TABLE EMP MODIFY Commission decimal(7,2);
8
Data Manipulation Language:
INSERT INTO {table | view} [ (column [, column] ...) ] VALUES (expr,expr ...) UPDATE {table | view } SET { (column [, column] = { expr | } [WHERE condition] DELETE [FROM] {table | view} [WHERE condition]
9
INSERT INTO Dept( deptid,deptname,location)
VALUES(50,'IT','Dallas'); INSERT INTO Emp(empid, lname,fname,positionid, supervisorid,hiredate, salary,deptid,qualid) VALUES(227,'howser','Barbara',4,111,'25-AUG-83',45000,10,3); UPDATE dept SET deptname='Sales' WHERE deptID=50; DELETE FROM dept WHERE deptid='50';
10
Data Retrieval: SELECT [DISTINCT | ALL] {table|view}
FROM {table | view} [WHERE condition ] [GROUP BY expr [, expr]] [ORDER BY {expr} [ASC | DESC]] select * from dept; select deptname from dept where deptid='10'; select lname,fname from emp order by lname desc; select max(salary) from emp group by positionid; select deptname from dept,emp where dept.deptid=emp.deptid and emp.empid='111';
11
ROLLBACK [ to {savepoint}] SAVEPOINT {name}
Transaction Control: COMMIT ROLLBACK [ to {savepoint}] SAVEPOINT {name} commit; savepoint point1; rollback to point1;
12
Data Control Language:
GRANT [privileges] ON object TO user|public [WITH GRANT OPTION] REVOKE [privileges] ON object TO user|public [CASCADE CONSTRAINTS] grant select,update on emp to XYZ ; revoke update on emp to XYZ;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.