SlideShare a Scribd company logo
Basics of SQL
Table Definition 
• A table is uniquely identified by its name and consists of rows that 
contain the stored information, 
• each row containing exactly one tuple (or record ). A table can have 
one or more columns. 
• A column is made up of a column name and a data type, and it 
describes an attribute of the 
• tuples. The structure of a table, also called relation schema, thus is 
defined by its attributes. 
• The type of information to be stored in a table is defined by the data 
types of the attributes 
• at table creation time.
SQL 
• STRUCTURED QUERY LANGUAGE. 
• Non-Procedural Language. 
• Language for any RDBMS. 
• We can't Execute more than one statement at a 
time 
• Very simple. Easily understandable.
SQL 
DDL 
DML(DRL) 
TCL 
DCL
DDL 
• Data Definition Language. 
• To Create Objects, To Alter Objects & To Drop Objects. 
• Commands: 
CREATE 
ALTER 
DROP 
TRUNCATE 
• DDL Statements are Auto Commit Statements.
DML 
• Data Manipulation Language. 
• To Maintain information the following Commands: 
INSERT 
UPDATE 
DELETE
TCL 
• Transaction Control Language. 
• Transaction is Nothing But DML. 
• Transaction : A Series of INSERTs, UPDATEs, DELETEs 
etc., 
• Commands: 
 COMMIT 
 ROLLBACK 
 SAVEPOINT
DCL 
• Data Control Language. 
• To Deal with Privileges. 
• Commands: 
GRANT 
REVOKE
DRL 
• Data Retrieval Language. 
• To retrieve data from the Database. 
• Commands: 
SELECT
CREATE 
• DDL Command. 
• To create Objects. 
• Syntax : CREATE TABLE < TABLE_NAME > 
( COLUMN_NAME 1 DEFINITION, 
COLUMN_NAME 2 DEFINITION, 
............ 
COLUMN_NAME n DEFINITION ); 
 DEFINITION specifies DataType & Width. 
• Syntax for creation of Objects : 
CREATE < OBJECT > <OBJECT_NAME>
CREATE (...CONTINUED) 
RULES FOR NAMING OBJECT 
• Should start with Alphabet. 
Error Message : Invalid Table Name 
• Object name should have Maximum Length of 30 
characters. 
Error Message : Identifier too Long 
• No special symbols and spaces except '_' 
Error Message : Missing / Invalid option 
• Reserved Words cannot be used. 
Error Message : Invalid table name 
• Case insensitive. 
The above rules also apply to column names
CREATE (...CONTINUED) 
• Example : CREATE TABLE EMP 
( EMPNO NUMBER(4), 
ENAME VARCHAR2(15), 
JOB VARCHAR2(10), 
DOB DATE, 
SAL NUMBER(7,2), 
DEPT NUMBER(7,2) ); 
• On completion of creation of the Table " Table created " Message will be 
displayed. 
• Every SQL Statement is terminated by semicolon ';' . 
• When ever SQL Statement is terminated it will be placed in " afiedt.buf ". 
Later if there are no errors Transaction will be carried out. Otherwise error 
message will be displayed.
INSERT 
• DML Command. 
• To insert rows in to Table. 
• Syntax 1 : INSERT INTO < TABLE_NAME > VALUES (VAL1,VAL2, 
...........,Val n); 
Example : INSERT INTO EMP VALUES (1001,'BABU','MANAGER','20- 
JAN-2004',8000,20); 
To insert Multiple rows in to a Table with this Syntax we have type the 
Command repeatedly. 
• Syntax 2 : INSERT INTO < TABLE_NAME > VALUES (&VAL1,&VAL2, 
...........,&VALn); 
Example : INSERT INTO EMP VALUES 
(&ENO,'&ENAME','&JOB','&HDATE',&SAL,&DEPT); 
To insert Multiple rows in to a Table with this Syntax we need not type the 
Command repeatedly, instead we have type / symbol repeatedly.
INSERT(…CONTINUED) 
• Syntax 3 : INSERT INTO < TABLE_NAME > 
(COL1,COL2,..........,COLn) VALUES (&VAL1,&VAL2, 
...........,&VALn); 
Example : INSERT INTO EMP (EMPNO,ENAME,JOB) 
VALUES (&ENO,'&ENAME','&JOB'); 
To insert information regarding only few columns of the 
table. 
• In any Syntax CHAR and DATE data types must be 
specified with in single Quotes.
SELECT 
• DRL Command. 
• To retrieve information from the Tables. 
• Syntax : SELECT * FROM < TABLE_NAME >; 
Example : SELECT * FROM EMP;
ALTER 
• DDL Command. 
• To Modify any Existing Tables. 
• Syntax : ALTER TABLE < TABLE_NAME > 
[ADD | MODIFY | DROP | DISABLE | ENABLE] 
(COL_NAME1 DEFINITION, 
COL_NAME2 DEFINITION, 
........ 
COL_NAME n DEFINITION )
ALTER (...CONTINUED) 
ADD 
• Adding Column to Table by ADD Command. 
• Example : ALTER TABLE EMP ADD (COMM 
NUMBER(7,2), DOB DATE);
ALTER (...CONTINUED) 
MODIFY 
• Change Data type and Increase / Decrease width by 
MODIFY Command. 
• We can’t Modify the column when there is already some 
information in the Column. 
Error Message : Column to be Modified must be empty to 
Decrease precision / scale. 
Error Message : Column to be Modified must be empty to 
Change Data type. 
• We cannot Modify Table Name using Alter Command. 
• Example : ALTER TABLE EMP MODIFY (JOB 
VARCHAR2(25), SAL NUMBER(9,2));
ALTER (...CONTINUED) 
DROP 
• Drop the Column by DROP Command. 
• Example : ALTER TABLE EMP DROP COLUMN 
DOB; 
• ORACLE 9 provides the feature of dropping Multiple 
Column. 
Example : ALTER TABLE EMP SET UNUSED DOB 
COLUMN; 
Example : ALTER TABLE EMP DROP UNUSED 
COLUMNS; 
Drops all columns which are set to UNUSED.
ALTER (...CONTINUED) ENABLE / 
DISABLE 
• Enable and Disable Constraints by ENABLE and 
DISABLE Commands respectively. 
• Example : ALTER TABLE EMP ENABLE 
CONSTRAINT PK1; 
• Example : ALTER TABLE EMP DISABLE 
CONSTRAINT PK1;
DROP 
• DDL Command. 
• To remove any object from schema. 
• Drops both Information and Structure of the Table. 
• Syntax : DROP < OBJECT_TYPE > < 
OBJECT_NAME >; 
• Example : DROP TABLE EMP;
TRUNC 
• DDL Command. 
• Removes rows in the Table Permanently. 
• Syntax : TRUNC TABLE < TABLE_NAME >; 
• Example : TRUNC TABLE EMP; 
• WHERE Clause cannot be used with TRUNC. 
• Only information deleted, Not Structure. 
• Auto-Commit Command. 
• EXIT and QUIT are Implicit Commit statements.
UPDATE 
• DML Command. 
• To Modify any existing information in the table. 
• Syntax : UPDATE < TABLE_NAME > SET < 
COLUMN_NAME > = < VALUE > [ WHERE 
<CONDITION> ]; 
• Example : UPDATE EMP SET SAL = 9000 WHERE 
EMPNO=1002; 
• To UPDATE multiple columns with in a row separate 
them by Commas. 
• Example: UPDATE EMP SET SAL = 
9000,COMM=1000 WHERE EMPNO=1002;
DELETE 
• DML Command. 
• To Delete rows from the Table. 
• Syntax : DELETE FROM < TABLE_NAME > [ WHERE 
<CONDITION> ]; 
• If Condition not specified all rows of the table will be 
deleted. 
• Example : DELETE FROM EMP; 
• If Condition specified all rows of the table satisfying the 
Condition will be deleted. 
• Example : DELETE FROM EMP WHERE JOB = 
'MANAGER‘;
COMMIT & ROLL BACK 
• TCL Commands. 
• Whenever we update data it will be first placed in o buffer. 
• If we COMMIT the buffer information will be stored 
permanently in physical location. 
• If we ROLLBACK we get previous values. 
• DDL Commands are AUTO-COMMIT statements. 
• If DDL Commands are used after Transactions all those 
transactions will Automatically Commit.
SAVEPOINT 
• Suppose there are 'N' transactions after COMMIT Point. 
• If 'Nth' transaction is to be ROLLED BACK all previous 
N-1 transactions will also get ROLLED BACK. 
• To avoid this we have SAVEPOINT. 
• If we have SAVEPOINT in between Transactions, If we 
ROLLBACK only transactions after specified 
SAVEPOINT will be ROLLED BACK. 
• On using COMMIT there will be no more SAVEPOINTs.
SAVEPOINT (...CONTINUED) 
• Example : 
• UPDATE EMP SET SAL = 9000 WHERE EMPNO=1002; 
SAVEPOINT A; 
UPDATE EMP SET SAL = 8000 WHERE EMPNO=1002; 
SAVEPOINT B; 
UPDATE EMP SET SAL = 7000 WHERE EMPNO=1002; 
SAVEPOINT C; 
UPDATE EMP SET SAL = 6000 WHERE EMPNO=1002; 
SAVEPOINT D; 
• If Error occurred in Third UPDATE statement we can ROLLBACK to c 
• Example : ROLLBACK TO B;
GRANT 
• DCL Command. 
• To Grant Permission to user to any Table. 
• The Data Dictionary Tables related to Privileges: 
• USER_TAB_PRIVS_MADE : What privileges are 
given? 
• USER_TAB_PRIVS_RECD : Who gave the privileges?
GRANT (...CONTINUED) 
• To give all the privileges to user. 
Syntax : GRANT ALL ON < TABLE_NAME > TO <USER_NAME 
>; 
ALL means INSERT, DELETE, SELECT, ALTER & INDEX. 
• To give single privilege to user. 
Syntax : GRANT SELECT ON < TABLE_NAME > TO 
<USER_NAME >; 
Read only permission Granted. 
• To give privilege of GRANTing privileges to user by WITH GRANT 
OPTION. 
Syntax : GRANT ALL ON < TABLE_NAME > TO <USER_NAME 
> WITH GRANT OPTION; 
Example : GRANT ALL ON EMP TO USER1 WITH GRANT 
OPTION;
GRANT (...CONTINUED) 
• If 'X' is the Owner of a particular table 'TABLE', all users who 
received privileges can access 'TABLE' by X.TABLE. 
• Example : SELECT * FROM SCOTT.EMP; 
SCOTT is Owner. 
• OWNER: GRANT ALL ON EMP TO USER1 WITH GRANT 
OPTION; 
USER1 : SELECT * FROM SCOTT.EMP; 
GRANT ALL ON EMP TO USER2; 
USER2 : SELECT * FROM SCOTT.EMP;
REVOKE 
• DCL Command. 
• To take back the privileges GRANTED. 
• Syntax : REVOKE ALL ON < TABLE_NAME > 
FROM < USER_NAME >; 
• Example : REVOKE ALL ON EMP FROM USER1; 
• Example : REVOKE INSERT ON EMP FROM 
USER1; 
• CASCADING REVOKE.
Database Objects 
Description 
Basic unit of storage; composed of rows 
and columns 
Logically represents subsets of data from 
one or more tables 
Generates primary key values 
Improves the performance of some queries 
Alternative name for an object 
Object 
Table 
View 
Sequence 
Index 
Synonym
Querying a View 
Oracle Server 
USER_VIEWS 
EMPVU30 
SELECT EMPNO, 
ENAME, SAL 
FROM EMP 
WHERE DEPTNO=30; 
iSQL*Plus 
SELECT * 
FROM EMPVU30; 
EMP
What is an Index? 
An index: 
• Is a schema object 
• Is used by the Oracle server to speed up the retrieval of 
rows by using a pointer 
• Can reduce disk I/O by using a rapid path access method to 
locate data quickly 
• Is independent of the table it indexes 
• Is used and maintained automatically by the Oracle server
How Are Indexes Created? 
• Automatically: A unique index is created automatically when 
you define a PRIMARY KEY or UNIQUE constraint in a 
table definition. 
• Manually: Users can create nonunique indexes on columns to 
speed up access to the rows.
CONSTRAINTS 
• NOT NULL 
• UNIQUE 
• PRIMARY KEY 
• CHECK 
• REFERENTIAL
LEVELS OF CONSTRAINTS 
• COLUMN LEVEL 
SYNTAX: CONSTRAINT <CONSTRAINT_NAME> 
<CONSTRAINT_TYPE> 
• TABLE LEVEL 
SYNTAX: CONSTRAINT <CONSTRAINT_NAME> 
<CONSTRAINT_TYPE> (COLUMN_NAME) 
 
Functionally no difference between Column level and 
Table level constraints.
CONSTRAINTS(…Contd) 
• NOT NULL is Column level constraint. 
• To add NOT NULL constraint after table creation use 
MODIFY. For others we use ADD. 
• If constraint name is not given, the system will provide its 
own name. 
• The constraints information will be stored under 
USER_CONSTRAINTS ,USER_CONS_COLUMN. 
• Only one Primary Key is allowed per table. 
• On a single column four types of constraints can be 
enforced at a time 
• Two or more check constraints can be enforced on a 
column at a time.
COLUMN LEVEL CONSTRAINT 
• CREATE TABLE EMP 
(EMPNO NUMBER(4) CONSTRAINT PK1 PRIMARY KEY, 
ENAME VARCHAR2(15) CONSTRAINT N1 NOTNULL, 
JOB VARCHAR2(15) CONSTRAINT N2 NOTNULL, 
DOJ DATE, 
SAL NUMBER(7,2) CONSTRAINT C1 CHECK(SAL>2000), 
COMM NUMBER(7,2), 
PHONENO NUMBER(10) CONSTRAINT U1 UNIQUE, 
DEPTNO NUMBER(2)); 
 
NOT NULL IS THE ONLY COLUMN LEVELCONSTRAINT.
TABLE LEVEL CONSTRAINT 
• CREATE TABLE EMP 
(EMPNO NUMBER(4), 
ENAME VARCHAR2(15) CONSTRAINT N1 NOTNULL, 
JOB VARCHAR2(15) CONSTRAINT N2 NOTNULL, 
DOJ DATE, 
SAL NUMBER(7,2), 
COMM NUMBER(7,2), 
PHONENO NUMBER(10), 
DEPTNO NUMBER(2) 
CONSTRAINT PK1 PRIMARY KEY(EMPNO), 
CONSTRAINT C1 CHECK(SAL>2000), 
CONSTRAINT U1 UNIQUE(PHONENO));
CONSTRAINTS (…Contd) 
• After creation of table if we want to enforce constraints 
– If it is NOT NULL use MODIFY 
– If other constraints use ADD 
• Example: 
ALTER TABLE EMP MODIFY 
( ENAME VARCHAR2(15) CONSTRAINT N1 NOT NULL); 
 
ALTER TABLE EMP ADD 
(CONSTRAINT K1 PRIMARY KEY(EMPNO), 
CONSTRAINT C1 CHECK(SAL>2000), 
CONSTRAINT U1 UNIQUE(PHONENO));
COMPOSITE PRIMARY KEY 
• If two or more attributes together form Primary Key then it is 
called Composite Key. 
• The combination of columns values should be unique. 
• Composite Primary Key is always a Table level constraint. We 
cannot go for column level. 
• Example: 
CREATE TABLE PRODUCT_DETAILS 
( PRODUCT_NO NUMBER(5), 
PRODUCT_NAME VARCHAR2(25), 
PRODUCT_PRICE NUMBER(11,2), 
CONSTRAINT PK1 PRIMARY KEY(PRODUCT_NO, 
PRODUCT_NAME, PRODUCT_PRICE));
DROPING CONSTRAINTS 
• First find constraint name from USER_CONSTRAINTS. 
• SELECTCONSTRAINT_NAME FROM USER_CONSTRAINTS; 
• If name is given by us we can identify it easily. 
• If it is system generated we have to know Table name from 
USER_CONSTRAINTS and column details from 
USER_CONS_COLUMNS. 
• Then DROP that constraint by constraint name. 
• Example : ALTER TABLE EMP DROP PRIMARY KEY; 
• Example : ALTER TABLE EMP DROP CONSTRAINT U1;
ENABLE & DISABLE 
• ALTER TABLE EMP DISABLE CONSTRAINT C1; 
• ALTER TABLE EMP ENABLE CONSTRAINT C1; 
• By Default constraint will be in enabled form.
REFERENTIAL INTEGRITY 
• To create relationships between tables and avoiding redundancy. 
• Example: 
CREATE TABLE DEPT 
(DEPTNO NUMBER(2), 
DNAME VARCHAR2(20), 
LOC VARCHAR2(25), 
CONSTRAINT PK2 PRIMARY KEY(DEPTNO));
REFERENTIAL INTEGRITY 
(…Contd) 
• CREATE TABLE EMP 
(EMPNO NUMBER(4) CONSTRAINT PK1 PRIMARY KEY, 
ENAME VARCHAR2(15) CONSTRAINT N1 NOTNULL, 
JOB VARCHAR2(15) CONSTRAINT N2 NOTNULL, 
DOJ DATE, 
SAL NUMBER(7,2) CONSTRAINT C1 CHECK(SAL>2000), 
COMM NUMBER(7,2), 
DNO NUMBER(2), 
CONSTRAINT R1 REFERENCES DEPT(DEPTNO)); 
 
DNO,DEPTNO SHOULD BE OF SAME DATATYPE AND 
WIDTH.
REFERENTIAL INTEGRITY 
(…Contd) 
• To enforce Referential Integrity constraint after table creation 
• We cannot delete the master record without deleting the corresponding 
Detail records. 
• ALTER TABLE EMP CONSTRAINT R1 FOREIGN KEY(DNO) 
REFERENCES DEPT(DEPTNO); 
• If we delete the master record the corresponding dependent records 
should also be deleted. 
• ALTER TABLE EMP CONSTRAINT R1 FOREIGN KEY(DNO) 
REFERENCES DEPT(DEPTNO) ON DELETE CASCADE;

More Related Content

What's hot

sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
Ankit Dubey
 
SQL
SQLSQL
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
Punjab University
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Languagepandey3045_bit
 
SQL
SQLSQL
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
Naimul Arif
 
Alter table command
Alter table commandAlter table command
Alter table command
ravikhandelwal41
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
Abdelhay Shafi
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
DataminingTools Inc
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
Shubham Shukla
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
AnjaliJain167
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Sabana Maharjan
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
arpit bhadoriya
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
Ram Kedem
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
Dhananjay Goel
 

What's hot (20)

sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 
SQL
SQLSQL
SQL
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Language
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
SQL
SQLSQL
SQL
 
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
 
Alter table command
Alter table commandAlter table command
Alter table command
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
Mysql
MysqlMysql
Mysql
 

Viewers also liked

Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In SqlAnurag
 
Relational databe
Relational databeRelational databe
Relational databe
Samwel Charles
 
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
Marco M. Kiesewetter, MBA
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint home
 
Basic oracle-database-administration
Basic oracle-database-administrationBasic oracle-database-administration
Basic oracle-database-administration
sreehari orienit
 
SQL Tutorial - Table Constraints
SQL Tutorial - Table ConstraintsSQL Tutorial - Table Constraints
SQL Tutorial - Table Constraints
1keydata
 
Présentation Oracle DataBase 11g
Présentation Oracle DataBase 11gPrésentation Oracle DataBase 11g
Présentation Oracle DataBase 11g
Cynapsys It Hotspot
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
DataminingTools Inc
 
Oracle Database Overview
Oracle Database OverviewOracle Database Overview
Oracle Database Overviewhonglee71
 
Sql database object
Sql database objectSql database object
Sql database object
Young Alista
 

Viewers also liked (13)

Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Relational databe
Relational databeRelational databe
Relational databe
 
Sql xp 05
Sql xp 05Sql xp 05
Sql xp 05
 
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint
 
Basic oracle-database-administration
Basic oracle-database-administrationBasic oracle-database-administration
Basic oracle-database-administration
 
SQL Tutorial - Table Constraints
SQL Tutorial - Table ConstraintsSQL Tutorial - Table Constraints
SQL Tutorial - Table Constraints
 
Creating database
Creating databaseCreating database
Creating database
 
Présentation Oracle DataBase 11g
Présentation Oracle DataBase 11gPrésentation Oracle DataBase 11g
Présentation Oracle DataBase 11g
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle Database Overview
Oracle Database OverviewOracle Database Overview
Oracle Database Overview
 
Sql database object
Sql database objectSql database object
Sql database object
 
Error localization
Error localizationError localization
Error localization
 

Similar to 8. sql

UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
SaurabhLokare1
 
ii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docxii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docx
lakshmi77
 
SQL LECTURE.pptx
SQL LECTURE.pptxSQL LECTURE.pptx
SQL LECTURE.pptx
TechnoSavage
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
suriyae1
 
Structured Query Language(SQL)
Structured Query Language(SQL)Structured Query Language(SQL)
Structured Query Language(SQL)
PadmapriyaA6
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
naveen
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
naveen
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tables
siavosh kaviani
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select Topics
Jay Coskey
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
Farhan Aslam
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
Lab
LabLab
SQL: Introduction and its Basic Commands
SQL: Introduction and its Basic CommandsSQL: Introduction and its Basic Commands
SQL: Introduction and its Basic Commands
niyantadesai7
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10Umair Amjad
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
Nitesh Singh
 

Similar to 8. sql (20)

UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
 
ii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docxii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docx
 
SQL LECTURE.pptx
SQL LECTURE.pptxSQL LECTURE.pptx
SQL LECTURE.pptx
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Structured Query Language(SQL)
Structured Query Language(SQL)Structured Query Language(SQL)
Structured Query Language(SQL)
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tables
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select Topics
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Lab
LabLab
Lab
 
SQL: Introduction and its Basic Commands
SQL: Introduction and its Basic CommandsSQL: Introduction and its Basic Commands
SQL: Introduction and its Basic Commands
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
SQL Notes
SQL NotesSQL Notes
SQL Notes
 

More from khoahuy82

13. case study
13. case study13. case study
13. case study
khoahuy82
 
20. quiz
20. quiz20. quiz
20. quiz
khoahuy82
 
7. transaction mang
7. transaction mang7. transaction mang
7. transaction mang
khoahuy82
 
6. normalization
6. normalization6. normalization
6. normalization
khoahuy82
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
khoahuy82
 
4. case study
4. case study4. case study
4. case study
khoahuy82
 
Cac phuong phap tim kiem tham do
Cac phuong phap tim kiem tham doCac phuong phap tim kiem tham do
Cac phuong phap tim kiem tham do
khoahuy82
 
07 2 chapter7-cross-section diagrams in 3 dimentions part 2-2
07 2 chapter7-cross-section diagrams in 3 dimentions part 2-207 2 chapter7-cross-section diagrams in 3 dimentions part 2-2
07 2 chapter7-cross-section diagrams in 3 dimentions part 2-2
khoahuy82
 
01 begin & chapter1
01 begin & chapter101 begin & chapter1
01 begin & chapter1
khoahuy82
 
06 chuong 6 moi truong ngam
06 chuong 6 moi truong ngam06 chuong 6 moi truong ngam
06 chuong 6 moi truong ngam
khoahuy82
 

More from khoahuy82 (19)

13. case study
13. case study13. case study
13. case study
 
20. quiz
20. quiz20. quiz
20. quiz
 
1. intro
1. intro1. intro
1. intro
 
19. quiz
19. quiz19. quiz
19. quiz
 
7. transaction mang
7. transaction mang7. transaction mang
7. transaction mang
 
6. normalization
6. normalization6. normalization
6. normalization
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
 
4. case study
4. case study4. case study
4. case study
 
Ch6
Ch6Ch6
Ch6
 
Ch7
Ch7Ch7
Ch7
 
Ch5
Ch5Ch5
Ch5
 
Ch4
Ch4Ch4
Ch4
 
Ch3
Ch3Ch3
Ch3
 
Ch1
Ch1Ch1
Ch1
 
Ch2
Ch2Ch2
Ch2
 
Cac phuong phap tim kiem tham do
Cac phuong phap tim kiem tham doCac phuong phap tim kiem tham do
Cac phuong phap tim kiem tham do
 
07 2 chapter7-cross-section diagrams in 3 dimentions part 2-2
07 2 chapter7-cross-section diagrams in 3 dimentions part 2-207 2 chapter7-cross-section diagrams in 3 dimentions part 2-2
07 2 chapter7-cross-section diagrams in 3 dimentions part 2-2
 
01 begin & chapter1
01 begin & chapter101 begin & chapter1
01 begin & chapter1
 
06 chuong 6 moi truong ngam
06 chuong 6 moi truong ngam06 chuong 6 moi truong ngam
06 chuong 6 moi truong ngam
 

Recently uploaded

一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
NABLAS株式会社
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
MaleehaSheikh2
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
v3tuleee
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
mbawufebxi
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
vcaxypu
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
Tiktokethiodaily
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
vcaxypu
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 

Recently uploaded (20)

一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 

8. sql

  • 2. Table Definition • A table is uniquely identified by its name and consists of rows that contain the stored information, • each row containing exactly one tuple (or record ). A table can have one or more columns. • A column is made up of a column name and a data type, and it describes an attribute of the • tuples. The structure of a table, also called relation schema, thus is defined by its attributes. • The type of information to be stored in a table is defined by the data types of the attributes • at table creation time.
  • 3. SQL • STRUCTURED QUERY LANGUAGE. • Non-Procedural Language. • Language for any RDBMS. • We can't Execute more than one statement at a time • Very simple. Easily understandable.
  • 4. SQL DDL DML(DRL) TCL DCL
  • 5. DDL • Data Definition Language. • To Create Objects, To Alter Objects & To Drop Objects. • Commands: CREATE ALTER DROP TRUNCATE • DDL Statements are Auto Commit Statements.
  • 6. DML • Data Manipulation Language. • To Maintain information the following Commands: INSERT UPDATE DELETE
  • 7. TCL • Transaction Control Language. • Transaction is Nothing But DML. • Transaction : A Series of INSERTs, UPDATEs, DELETEs etc., • Commands:  COMMIT  ROLLBACK  SAVEPOINT
  • 8. DCL • Data Control Language. • To Deal with Privileges. • Commands: GRANT REVOKE
  • 9. DRL • Data Retrieval Language. • To retrieve data from the Database. • Commands: SELECT
  • 10. CREATE • DDL Command. • To create Objects. • Syntax : CREATE TABLE < TABLE_NAME > ( COLUMN_NAME 1 DEFINITION, COLUMN_NAME 2 DEFINITION, ............ COLUMN_NAME n DEFINITION );  DEFINITION specifies DataType & Width. • Syntax for creation of Objects : CREATE < OBJECT > <OBJECT_NAME>
  • 11. CREATE (...CONTINUED) RULES FOR NAMING OBJECT • Should start with Alphabet. Error Message : Invalid Table Name • Object name should have Maximum Length of 30 characters. Error Message : Identifier too Long • No special symbols and spaces except '_' Error Message : Missing / Invalid option • Reserved Words cannot be used. Error Message : Invalid table name • Case insensitive. The above rules also apply to column names
  • 12. CREATE (...CONTINUED) • Example : CREATE TABLE EMP ( EMPNO NUMBER(4), ENAME VARCHAR2(15), JOB VARCHAR2(10), DOB DATE, SAL NUMBER(7,2), DEPT NUMBER(7,2) ); • On completion of creation of the Table " Table created " Message will be displayed. • Every SQL Statement is terminated by semicolon ';' . • When ever SQL Statement is terminated it will be placed in " afiedt.buf ". Later if there are no errors Transaction will be carried out. Otherwise error message will be displayed.
  • 13. INSERT • DML Command. • To insert rows in to Table. • Syntax 1 : INSERT INTO < TABLE_NAME > VALUES (VAL1,VAL2, ...........,Val n); Example : INSERT INTO EMP VALUES (1001,'BABU','MANAGER','20- JAN-2004',8000,20); To insert Multiple rows in to a Table with this Syntax we have type the Command repeatedly. • Syntax 2 : INSERT INTO < TABLE_NAME > VALUES (&VAL1,&VAL2, ...........,&VALn); Example : INSERT INTO EMP VALUES (&ENO,'&ENAME','&JOB','&HDATE',&SAL,&DEPT); To insert Multiple rows in to a Table with this Syntax we need not type the Command repeatedly, instead we have type / symbol repeatedly.
  • 14. INSERT(…CONTINUED) • Syntax 3 : INSERT INTO < TABLE_NAME > (COL1,COL2,..........,COLn) VALUES (&VAL1,&VAL2, ...........,&VALn); Example : INSERT INTO EMP (EMPNO,ENAME,JOB) VALUES (&ENO,'&ENAME','&JOB'); To insert information regarding only few columns of the table. • In any Syntax CHAR and DATE data types must be specified with in single Quotes.
  • 15. SELECT • DRL Command. • To retrieve information from the Tables. • Syntax : SELECT * FROM < TABLE_NAME >; Example : SELECT * FROM EMP;
  • 16. ALTER • DDL Command. • To Modify any Existing Tables. • Syntax : ALTER TABLE < TABLE_NAME > [ADD | MODIFY | DROP | DISABLE | ENABLE] (COL_NAME1 DEFINITION, COL_NAME2 DEFINITION, ........ COL_NAME n DEFINITION )
  • 17. ALTER (...CONTINUED) ADD • Adding Column to Table by ADD Command. • Example : ALTER TABLE EMP ADD (COMM NUMBER(7,2), DOB DATE);
  • 18. ALTER (...CONTINUED) MODIFY • Change Data type and Increase / Decrease width by MODIFY Command. • We can’t Modify the column when there is already some information in the Column. Error Message : Column to be Modified must be empty to Decrease precision / scale. Error Message : Column to be Modified must be empty to Change Data type. • We cannot Modify Table Name using Alter Command. • Example : ALTER TABLE EMP MODIFY (JOB VARCHAR2(25), SAL NUMBER(9,2));
  • 19. ALTER (...CONTINUED) DROP • Drop the Column by DROP Command. • Example : ALTER TABLE EMP DROP COLUMN DOB; • ORACLE 9 provides the feature of dropping Multiple Column. Example : ALTER TABLE EMP SET UNUSED DOB COLUMN; Example : ALTER TABLE EMP DROP UNUSED COLUMNS; Drops all columns which are set to UNUSED.
  • 20. ALTER (...CONTINUED) ENABLE / DISABLE • Enable and Disable Constraints by ENABLE and DISABLE Commands respectively. • Example : ALTER TABLE EMP ENABLE CONSTRAINT PK1; • Example : ALTER TABLE EMP DISABLE CONSTRAINT PK1;
  • 21. DROP • DDL Command. • To remove any object from schema. • Drops both Information and Structure of the Table. • Syntax : DROP < OBJECT_TYPE > < OBJECT_NAME >; • Example : DROP TABLE EMP;
  • 22. TRUNC • DDL Command. • Removes rows in the Table Permanently. • Syntax : TRUNC TABLE < TABLE_NAME >; • Example : TRUNC TABLE EMP; • WHERE Clause cannot be used with TRUNC. • Only information deleted, Not Structure. • Auto-Commit Command. • EXIT and QUIT are Implicit Commit statements.
  • 23. UPDATE • DML Command. • To Modify any existing information in the table. • Syntax : UPDATE < TABLE_NAME > SET < COLUMN_NAME > = < VALUE > [ WHERE <CONDITION> ]; • Example : UPDATE EMP SET SAL = 9000 WHERE EMPNO=1002; • To UPDATE multiple columns with in a row separate them by Commas. • Example: UPDATE EMP SET SAL = 9000,COMM=1000 WHERE EMPNO=1002;
  • 24. DELETE • DML Command. • To Delete rows from the Table. • Syntax : DELETE FROM < TABLE_NAME > [ WHERE <CONDITION> ]; • If Condition not specified all rows of the table will be deleted. • Example : DELETE FROM EMP; • If Condition specified all rows of the table satisfying the Condition will be deleted. • Example : DELETE FROM EMP WHERE JOB = 'MANAGER‘;
  • 25. COMMIT & ROLL BACK • TCL Commands. • Whenever we update data it will be first placed in o buffer. • If we COMMIT the buffer information will be stored permanently in physical location. • If we ROLLBACK we get previous values. • DDL Commands are AUTO-COMMIT statements. • If DDL Commands are used after Transactions all those transactions will Automatically Commit.
  • 26. SAVEPOINT • Suppose there are 'N' transactions after COMMIT Point. • If 'Nth' transaction is to be ROLLED BACK all previous N-1 transactions will also get ROLLED BACK. • To avoid this we have SAVEPOINT. • If we have SAVEPOINT in between Transactions, If we ROLLBACK only transactions after specified SAVEPOINT will be ROLLED BACK. • On using COMMIT there will be no more SAVEPOINTs.
  • 27. SAVEPOINT (...CONTINUED) • Example : • UPDATE EMP SET SAL = 9000 WHERE EMPNO=1002; SAVEPOINT A; UPDATE EMP SET SAL = 8000 WHERE EMPNO=1002; SAVEPOINT B; UPDATE EMP SET SAL = 7000 WHERE EMPNO=1002; SAVEPOINT C; UPDATE EMP SET SAL = 6000 WHERE EMPNO=1002; SAVEPOINT D; • If Error occurred in Third UPDATE statement we can ROLLBACK to c • Example : ROLLBACK TO B;
  • 28. GRANT • DCL Command. • To Grant Permission to user to any Table. • The Data Dictionary Tables related to Privileges: • USER_TAB_PRIVS_MADE : What privileges are given? • USER_TAB_PRIVS_RECD : Who gave the privileges?
  • 29. GRANT (...CONTINUED) • To give all the privileges to user. Syntax : GRANT ALL ON < TABLE_NAME > TO <USER_NAME >; ALL means INSERT, DELETE, SELECT, ALTER & INDEX. • To give single privilege to user. Syntax : GRANT SELECT ON < TABLE_NAME > TO <USER_NAME >; Read only permission Granted. • To give privilege of GRANTing privileges to user by WITH GRANT OPTION. Syntax : GRANT ALL ON < TABLE_NAME > TO <USER_NAME > WITH GRANT OPTION; Example : GRANT ALL ON EMP TO USER1 WITH GRANT OPTION;
  • 30. GRANT (...CONTINUED) • If 'X' is the Owner of a particular table 'TABLE', all users who received privileges can access 'TABLE' by X.TABLE. • Example : SELECT * FROM SCOTT.EMP; SCOTT is Owner. • OWNER: GRANT ALL ON EMP TO USER1 WITH GRANT OPTION; USER1 : SELECT * FROM SCOTT.EMP; GRANT ALL ON EMP TO USER2; USER2 : SELECT * FROM SCOTT.EMP;
  • 31. REVOKE • DCL Command. • To take back the privileges GRANTED. • Syntax : REVOKE ALL ON < TABLE_NAME > FROM < USER_NAME >; • Example : REVOKE ALL ON EMP FROM USER1; • Example : REVOKE INSERT ON EMP FROM USER1; • CASCADING REVOKE.
  • 32. Database Objects Description Basic unit of storage; composed of rows and columns Logically represents subsets of data from one or more tables Generates primary key values Improves the performance of some queries Alternative name for an object Object Table View Sequence Index Synonym
  • 33. Querying a View Oracle Server USER_VIEWS EMPVU30 SELECT EMPNO, ENAME, SAL FROM EMP WHERE DEPTNO=30; iSQL*Plus SELECT * FROM EMPVU30; EMP
  • 34. What is an Index? An index: • Is a schema object • Is used by the Oracle server to speed up the retrieval of rows by using a pointer • Can reduce disk I/O by using a rapid path access method to locate data quickly • Is independent of the table it indexes • Is used and maintained automatically by the Oracle server
  • 35. How Are Indexes Created? • Automatically: A unique index is created automatically when you define a PRIMARY KEY or UNIQUE constraint in a table definition. • Manually: Users can create nonunique indexes on columns to speed up access to the rows.
  • 36. CONSTRAINTS • NOT NULL • UNIQUE • PRIMARY KEY • CHECK • REFERENTIAL
  • 37. LEVELS OF CONSTRAINTS • COLUMN LEVEL SYNTAX: CONSTRAINT <CONSTRAINT_NAME> <CONSTRAINT_TYPE> • TABLE LEVEL SYNTAX: CONSTRAINT <CONSTRAINT_NAME> <CONSTRAINT_TYPE> (COLUMN_NAME)  Functionally no difference between Column level and Table level constraints.
  • 38. CONSTRAINTS(…Contd) • NOT NULL is Column level constraint. • To add NOT NULL constraint after table creation use MODIFY. For others we use ADD. • If constraint name is not given, the system will provide its own name. • The constraints information will be stored under USER_CONSTRAINTS ,USER_CONS_COLUMN. • Only one Primary Key is allowed per table. • On a single column four types of constraints can be enforced at a time • Two or more check constraints can be enforced on a column at a time.
  • 39. COLUMN LEVEL CONSTRAINT • CREATE TABLE EMP (EMPNO NUMBER(4) CONSTRAINT PK1 PRIMARY KEY, ENAME VARCHAR2(15) CONSTRAINT N1 NOTNULL, JOB VARCHAR2(15) CONSTRAINT N2 NOTNULL, DOJ DATE, SAL NUMBER(7,2) CONSTRAINT C1 CHECK(SAL>2000), COMM NUMBER(7,2), PHONENO NUMBER(10) CONSTRAINT U1 UNIQUE, DEPTNO NUMBER(2));  NOT NULL IS THE ONLY COLUMN LEVELCONSTRAINT.
  • 40. TABLE LEVEL CONSTRAINT • CREATE TABLE EMP (EMPNO NUMBER(4), ENAME VARCHAR2(15) CONSTRAINT N1 NOTNULL, JOB VARCHAR2(15) CONSTRAINT N2 NOTNULL, DOJ DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), PHONENO NUMBER(10), DEPTNO NUMBER(2) CONSTRAINT PK1 PRIMARY KEY(EMPNO), CONSTRAINT C1 CHECK(SAL>2000), CONSTRAINT U1 UNIQUE(PHONENO));
  • 41. CONSTRAINTS (…Contd) • After creation of table if we want to enforce constraints – If it is NOT NULL use MODIFY – If other constraints use ADD • Example: ALTER TABLE EMP MODIFY ( ENAME VARCHAR2(15) CONSTRAINT N1 NOT NULL);  ALTER TABLE EMP ADD (CONSTRAINT K1 PRIMARY KEY(EMPNO), CONSTRAINT C1 CHECK(SAL>2000), CONSTRAINT U1 UNIQUE(PHONENO));
  • 42. COMPOSITE PRIMARY KEY • If two or more attributes together form Primary Key then it is called Composite Key. • The combination of columns values should be unique. • Composite Primary Key is always a Table level constraint. We cannot go for column level. • Example: CREATE TABLE PRODUCT_DETAILS ( PRODUCT_NO NUMBER(5), PRODUCT_NAME VARCHAR2(25), PRODUCT_PRICE NUMBER(11,2), CONSTRAINT PK1 PRIMARY KEY(PRODUCT_NO, PRODUCT_NAME, PRODUCT_PRICE));
  • 43. DROPING CONSTRAINTS • First find constraint name from USER_CONSTRAINTS. • SELECTCONSTRAINT_NAME FROM USER_CONSTRAINTS; • If name is given by us we can identify it easily. • If it is system generated we have to know Table name from USER_CONSTRAINTS and column details from USER_CONS_COLUMNS. • Then DROP that constraint by constraint name. • Example : ALTER TABLE EMP DROP PRIMARY KEY; • Example : ALTER TABLE EMP DROP CONSTRAINT U1;
  • 44. ENABLE & DISABLE • ALTER TABLE EMP DISABLE CONSTRAINT C1; • ALTER TABLE EMP ENABLE CONSTRAINT C1; • By Default constraint will be in enabled form.
  • 45. REFERENTIAL INTEGRITY • To create relationships between tables and avoiding redundancy. • Example: CREATE TABLE DEPT (DEPTNO NUMBER(2), DNAME VARCHAR2(20), LOC VARCHAR2(25), CONSTRAINT PK2 PRIMARY KEY(DEPTNO));
  • 46. REFERENTIAL INTEGRITY (…Contd) • CREATE TABLE EMP (EMPNO NUMBER(4) CONSTRAINT PK1 PRIMARY KEY, ENAME VARCHAR2(15) CONSTRAINT N1 NOTNULL, JOB VARCHAR2(15) CONSTRAINT N2 NOTNULL, DOJ DATE, SAL NUMBER(7,2) CONSTRAINT C1 CHECK(SAL>2000), COMM NUMBER(7,2), DNO NUMBER(2), CONSTRAINT R1 REFERENCES DEPT(DEPTNO));  DNO,DEPTNO SHOULD BE OF SAME DATATYPE AND WIDTH.
  • 47. REFERENTIAL INTEGRITY (…Contd) • To enforce Referential Integrity constraint after table creation • We cannot delete the master record without deleting the corresponding Detail records. • ALTER TABLE EMP CONSTRAINT R1 FOREIGN KEY(DNO) REFERENCES DEPT(DEPTNO); • If we delete the master record the corresponding dependent records should also be deleted. • ALTER TABLE EMP CONSTRAINT R1 FOREIGN KEY(DNO) REFERENCES DEPT(DEPTNO) ON DELETE CASCADE;