Download presentation
Presentation is loading. Please wait.
1
DATA MANIPULATION andCONTROL
2
Data definition language(DDL)
DDL stands for “ data definition language”. It is the subset of SQL commands used to create, modify and destroy databases and database objects like –tables , views etc. A data Definition Language has a pre-defined syntax for describing data . For example – To built a new table using SQL syntax the CREATE command is used, followed by parameters for the table name and column definition . The DDL can also define the name of each column and the associated data type.
3
Once a table is created , it can be modified using the ALTER command .
If the table is no longer needed , the DROPcommand will delete the table. Some of the comman DDL statements in oracle include CREATE, ALTER, DROP, RENAME, TRUNCATE etc.
4
CREATING TABLES
5
CREATING TABLES The CREATE TABLE command is used to create tables to store data. Tables are owned by the user who creates them. The names of tables owned by a given user must be unique . The column names in the table must be unique . Specifying table name is compulsory while creating a table.
6
The syntax for the CREATE TABLE statement is :
CREATE TABLE table _name (column _name1 data type, Column _name2 data type, …column _nameN data type);
7
EXAMPLE: CREATE TABLE STUDENT _RECORD ( Name varchar2 (20) ,
Class varchar2 (10), Roll _no number(5), Section char (1), Marks number (5,2) );
8
STUDENT RECORD Column name Type Size Description Name Varchar2 20
Name of student Class 10 Class of student Roll no Number 5 Roll number of student Section Char 1 Section of student’s class Marks 5,2 Marks obtained by student
9
CREATING A TABLE WITH DATA FROM ANOTHER TABLE
10
CREATING A TABLE WITH DATA FROM ANOTHER TABLE
A table can be created by using CREATE TABLE statement with data, derived another table . The syntax is : CREATE TABLE NEW _TABLE_NAME [(Column_1, column_2,…. Column_n)] , AS SELECT Column _1 , column_2 ,…. Column _n From OLD_TABLE_NAME ;
11
TABLE STUDENT NAME CLASS ROLL NO AGE A BCA 1 17 B BSC 2 18 C MSC 3 19
MCA 4 20
12
FOR EXAMLE Create a table STUDENT1 from student table having student name and Rollno . CREATE TABLE STUDENT1 [( NAME , ROLLNO)] AS SELECT NAME , CLASS, ROLLNO, AGE FROM STUDENT
13
TABLE STUDENT 1 NAME ROLLNO A 1 B 2 C 3 D 4
14
INSERTING VALUES INTO TABLE
15
INSERT STATMENT It is used to insert new rows/records in a table.
Values can be inserted for all the columns or for selected columns of the table. We can insert data values into a table through different ways: Inserting the data direct to the table. Inserting the data to a table through a select statement.
16
The syntax for INSERT statement is:
INSERT INTO TABLE_NAME VALUES (value 1,value 2,value 3,…….value n); Example: class is a table name. Insert into class values(‘ram’, 20, ’bca’);
17
Following statements would create 4 records in CUSTOMERS table:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Ramesh', 32, 'Ahmedabad', ); VALUES (2, 'Khilan', 25, 'Delhi', ); VALUES (3, 'kaushik', 23, 'Kota', ); VALUES (4, 'Chaitali', 25, 'Mumbai', );
18
ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2 KHILAN 25 DELHI 3 KAUSHIK 23 KOTA 4 CHAITALI MUMBAI
19
UPDATING THE COLUMNS & ROWS:
20
UPDATE STATEMENT To update or modify the exiting rows in a table.
It modifies specific rows if the WHERE clause is specified. We can use WHERE clause with UPDATE query to update selected rows otherwise all the rows would be affected.
21
The basic syntax of UPDATE query with WHERE clause is as follows:
UPDATE table_name SET column1 = value1, column2 = value2...., column N = value N WHERE [condition]; Example: UPDATE EMP SET COMM=500; EMP is the table name.
22
Consider the CUSTOMERS table having the following records:
NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2 KHILAN 25 DELHI 3 KAUSHIK 23 KOTA 4 CHAITALI MUMBAI
23
SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune' WHERE ID = 4;
Following is an example, which would update ADDRESS for a customer whose ID is 6: SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune' WHERE ID = 4;
24
Now, CUSTOMERS table would have the following records:
ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2 KHILAN 25 DELHI 3 KAUSHIK 23 KOTA 4 CHAITALI PUNE
25
DELETING ROW FROM TABLE
26
DELETE STATEMENT It is used to delete rows from a table.
To delete rows from a table, table must be in your schema. We can use WHERE clause with DELETE query to delete selected rows, otherwise all the records would be deleted.
27
The basic syntax of DELETE query with WHERE clause is as follows:
DELETE FROM table_name WHERE [condition]; Example: DELETE FROM EMP WHERE JOB=‘ CLERK’; EMP is the table name.
28
Consider the CUSTOMERS table having the following records:
NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2 KAUSHIK 25 DELHI 3 KHILAN 23 KOTA 4 CHAITALI MUMBAI
29
Following is an example, which would DELETE a customer, whose ID is 6:
SQL> DELETE FROM CUSTOMERS WHERE ID = 4;
30
Now, CUSTOMERS table would have the following records:
ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2 KAUSHIK 25 DELHI 3 KHILAN 23 KOTA
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.