Вы находитесь на странице: 1из 26

ORACLE

H.K. Vedamurthy Asst Professor Dept of CSE CIT ,GUBBI

H.K. Vedamurthy, CSE ,CIT Gubbi

Data Definition Language -DDL


Create table command - To Create the table structure Alter table command - To Alter the table structure Truncate Table command
- To delete all the tuples but table structure remains.

Drop Table command - To delete the table structure


H.K. Vedamurthy, CSE ,CIT Gubbi 2

Data Manipulation Language- DML


Insert to insert rows into the table Select to retrieve rows from the table Update to make any to the row values

Delete to delete the rows in the table


H.K. Vedamurthy, CSE ,CIT Gubbi 3

Transaction Control Language- TCL


Commit - to save the transactions

Savepoint - like markers to divide lengthy transaction to smaller ones. Rollback used to undo the work done in the current transaction.
H.K. Vedamurthy, CSE ,CIT Gubbi 4

Data Control Language -DCL

Grant privilege command

Revoke privilege command

H.K. Vedamurthy, CSE ,CIT Gubbi

Data Definition Language DDL


Create command

To Create the table structure


Syntax:

Create table <table name > ( Columnname datatype constraints,);

H.K. Vedamurthy, CSE ,CIT Gubbi

Data Types
Number Char

Varchar2
Long Date
H.K. Vedamurthy, CSE ,CIT Gubbi 7

Null Value
Missing/unknown/inapplicable data

represented as a null value


NULL is not a data value. It is just an

indicator that the value is unknown

H.K. Vedamurthy, CSE ,CIT Gubbi

Types of Constraints
Column Level Unique Constraint Check Constraint Primary Key Constraint Table Level Foreign Key Constraint

H.K. Vedamurthy, CSE ,CIT Gubbi

Create Table Example


Implementing NOT NULL and Primary Key
CREATE TABLE Customer_Details( Cust_ID Number(5) CONSTRAINT Nnull1 NOT NULL, Cust_Last_Name VarChar2(20) CONSTRAINT Nnull2 NOT NULL, Cust_Mid_Name VarChar2(4), Cust_First_Name VarChar2(20), Account_No Number(5) CONSTRAINT Pkey1 PRIMARY KEY, Account_Type VarChar2(10) CONSTRAINT Nnull3 NOT NULL, Bank_Branch VarChar2(25) CONSTRAINT Nnull4 NOT NULL, Cust_Email VarChar2(30) );
H.K. Vedamurthy, CSE ,CIT Gubbi 10

Create Table Example contd..


Implementing Composite Primary Key
CREATE TABLE Customer_Details( Cust_ID Number(5) CONSTRAINT Nnull7 NOT NULL, Cust_Last_Name VarChar2(20) CONSTRAINT Nnull8 NOT NULL, Cust_Mid_Name VarChar2(4), Cust_First_Name VarChar2(20), Account_No Number(5) CONSTRAINT Nnull9 NOT NULL, Account_Type VarChar2(10) CONSTRAINT Nnull10 NOT NULL, Bank_Branch VarChar2(25) CONSTRAINT Nnull11 NOT NULL, Cust_Email VarChar2(30), CONSTRAINT PKey3 PRIMARY KEY (Cust_ID, Account_No) );
H.K. Vedamurthy, CSE ,CIT Gubbi 11

Create Table Example contd..


Implementation of Unique Constraint Create Table UnqTable(
ECode Number(6) Constraint PK11 Primary Key, EName Varchar2(25) Constraint NNull18 NOT NULL, EEmail Varchar2(25) Constraint Unq1 Unique

);

H.K. Vedamurthy, CSE ,CIT Gubbi

12

Create Table Example contd..


Implementation of Primary Key and Foreign Key Constraints CREATE TABLE EMPLOYEE_MANAGER( Employee_ID Number(6) CONSTRAINT Pkey2 PRIMARY KEY, Employee_Last_Name VarChar2(25), Employee_Mid_Name VarChar2(5), Employee_First_Name VarChar2(25), Employee_Email VarChar2(35), Department VarChar2(10), Grade Number(2), MANAGER_ID Number(6) CONSTRAINT Fkey2 REFERENCES EMPLOYEE_MANAGER(Employee_ID) );
H.K. Vedamurthy, CSE ,CIT Gubbi 13

Create Table Example contd..

Implementation of Check Constraint CREATE TABLE EMPLOYEE( EmpNo NUMBER(5) CONSTRAINT PKey4 Primary Key, EmpName Varchar(25) NOT NULL, EmpSalary Number(7) Constraint chk Check (EmpSalary > 0 and EmpSalary <1000000) );
H.K. Vedamurthy, CSE ,CIT Gubbi 14

Create Table Example contd..

Implementation of Default CREATE TABLE TABDEF( Ecode Number(4) Not Null, Ename Varchar2(25) Not Null, ECity char(10) DEFAULT Mysore );

H.K. Vedamurthy, CSE ,CIT Gubbi

15

Alter Table command


- To Alter the table structure

add modify and drop column Syntax: ALTER TABLE tablename (ADD/MODIFY/DROP column_name)

H.K. Vedamurthy, CSE ,CIT Gubbi

16

Alter Table Examples


Add/Drop column ALTER TABLE Customer_Details ADD Contact_Phone Char(10); ALTER TABLE Customer_Details DROP column Contact_Phone; ALTER TABLE Customer_Details MODIFY Contact_Phone Char(12);
H.K. Vedamurthy, CSE ,CIT Gubbi 17

Alter Table Examples


Add/Drop Primary key ALTER TABLE Customer_Details ADD CONSTRAINT Pkey1 PRIMARY KEY (Account_No); ALTER TABLE Customer_Details DROP PRIMARY KEY; Or ALTER TABLE Customer_Details DROP CONSTRAINT Pkey1;

ALTER TABLE Customer_Details ADD CONSTRAINT Pkey2 PRIMARY KEY (Account_No, Cust_ID);
H.K. Vedamurthy, CSE ,CIT Gubbi 18

Alter Table Examples


ALTER TABLE Customer_Transaction ADD CONSTRAINT Fkey1 FOREIGN KEY (Account_No) REFERENCES Customer_Details (Account_No); ALTER TABLE Customer_Transaction DROP CONSTRAINT Fkey1;
H.K. Vedamurthy, CSE ,CIT Gubbi 19

Truncate Table command


- To delete all the rows but table structure remains.

TRUNCATE TABLE Customer_Details

H.K. Vedamurthy, CSE ,CIT Gubbi

20

Drop Table command


DROP TABLE Deletes table structure Cannot be recovered Use with caution Example DROP TABLE UnqTable;

H.K. Vedamurthy, CSE ,CIT Gubbi

21

Data Manipulation Language- DML


Insert to insert rows into the table

Syntax: Insert into <tablename>(column list) values (a list of data values separated by commas);

Eg: 1) insert into vendor_master values(v001,Frances,10,first at,


korattur,611892);

2) insert into vendor_master (vencode,venname,tel_no) values(


v003,Ramesh,231218);

3)insert into vendor_master values


(v004,somesh,null,null,null,542879);

4)insert into vendor_master


values(&vencode,&venname,&venadd1,&venadd2, &venadd3,&tel_no);
H.K. Vedamurthy, CSE ,CIT Gubbi 22

Operators
Arithmetic operators like +, -, *, /
Logical operators: AND, OR, NOT Relational operators: =, <=, >=, < >, < , >

H.K. Vedamurthy, CSE ,CIT Gubbi

23

Update to make any to the row values


Syntax: DELETE FROM tablename WHERE condition Example:
Deleting All Rows DELETE FROM Customer_Details Deleting Specific Rows DELETE FROM Customer_Details
WHERE Cust_ID = 102
H.K. Vedamurthy, CSE ,CIT Gubbi 24

Delete to delete the rows in the table


SYNTAX: UPDATE tablename SET column_name =value [ WHERE condition] Example:

Updating All Rows UPDATE Customer_Fixed_Deposit SET Rate_of_Interest_in_Percent = NULL; Updating Particular rows
UPDATE Customer_Fixed_Deposit SET Rate_of_Interest_in_Percent = 7.3 WHERE Amount_in_Dollars > 3000;
H.K. Vedamurthy, CSE ,CIT Gubbi 25

Update contd.
Updating Multiple Columns

UPDATE Customer_Fixed_Deposit
SET Cust_Email = Quails_Jack@rediffmail.com , Rate_of_Interest_in_Percent = 7.3 WHERE Cust_ID = 104

H.K. Vedamurthy, CSE ,CIT Gubbi

26

Вам также может понравиться