DATA MANIPULATION and CONTROL Data definition languageDDL DDL
- Slides: 31
DATA MANIPULATION and. CONTROL
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.
§ 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.
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.
The syntax for the CREATE TABLE statement is : CREATE TABLE table _name (column _name 1 data type, Column _name 2 data type, …column _name. N data type);
EXAMPLE: CREATE TABLE STUDENT _RECORD ( Name varchar 2 (20) , Class varchar 2 (10), Roll _no number(5), Section char (1), Marks number (5, 2) );
Column name Type Size Description Name Varchar 2 20 Name of student Class Varchar 2 10 Class of student Roll no Number 5 Roll number of student Section Char 1 Marks Number 5, 2 Section of student’s class Marks obtained by student
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 ;
TABLE STUDENT NAME CLASS AGE BCA ROLL NO 1 A B BSC 2 18 C MSC 3 19 D MCA 4 20 17
FOR EXAMLE Create a table STUDENT 1 from student table having student name and Rollno. CREATE TABLE STUDENT 1 [( NAME , ROLLNO)] AS SELECT NAME , CLASS, ROLLNO, AGE FROM STUDENT
TABLE STUDENT 1 NAME ROLLNO A 1 B 2 C 3 D 4
INSERTING VALUES INTO TABLE
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.
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’);
Following statements would create 4 records in CUSTOMERS table: INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000. 00 ); INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (2, 'Khilan', 25, 'Delhi', 1500. 00 ); INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (3, 'kaushik', 23, 'Kota', 2000. 00 ); INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (4, 'Chaitali', 25, 'Mumbai', 6500. 00 );
ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2000. 00 2 KHILAN 25 DELHI 1500. 00 3 KAUSHIK 23 KOTA 2000. 00 4 CHAITALI 25 MUMBAI 6500. 00
UPDATING THE COLUMNS & ROWS:
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.
The basic syntax of UPDATE query with WHERE clause is as follows: UPDATE table_name SET column 1 = value 1, column 2 = value 2. . , column N = value N WHERE [condition]; Example: UPDATE EMP SET COMM=500; EMP is the table name.
Consider the CUSTOMERS table having the following records: ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2000. 00 2 KHILAN 25 DELHI 1500. 00 3 KAUSHIK 23 KOTA 2000. 00 4 CHAITALI 25 MUMBAI 6500. 00
Following is an example, which would update ADDRESS for a customer whose ID is 6: SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune' WHERE ID = 4;
Now, CUSTOMERS table would have the following records: ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2000. 00 2 KHILAN 25 DELHI 1500. 00 3 KAUSHIK 23 KOTA 2000. 00 4 CHAITALI 25 PUNE 6500. 00
DELETING ROW FROM TABLE
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.
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.
Consider the CUSTOMERS table having the following records: ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2000. 00 2 KAUSHIK 25 DELHI 1500. 00 3 KHILAN 23 KOTA 2000. 00 4 CHAITALI 25 MUMBAI 6500. 00
Following is an example, which would DELETE a customer, whose ID is 6: SQL> DELETE FROM CUSTOMERS WHERE ID = 4;
Now, CUSTOMERS table would have the following records: ID NAME AGE ADDRESS SALARY 1 RAMESH 32 AHEMDABAD 2000. 00 2 KAUSHIK 25 DELHI 1500. 00 3 KHILAN 23 KOTA 2000. 00
- Ddl language
- What encapsulates both data and data manipulation functions
- Ddl and dml
- Ddl base de datos
- Ddl lesson plan
- Contoh data manipulation language
- Create alter drop truncate are ddl commands
- Ddl ringraumdichtung
- Ddl practice questions
- Ddl naredbe
- Rodzaje sql
- Ddl diamond
- Biba n 445 ddl
- Comandos ddl mysql
- Challenges n 732 ddl
- Biba n 477 ddl
- Hyperstatisme
- Ddl stands for
- Drift away ddl
- Advantages of sql
- Otis ddl
- Nj driving manual
- Integrity constraints in sql
- Ddl compiler
- Biba ddl
- Biba integrity model example
- Biba ddl
- Biba ddl
- Regal n 89 ddl
- Database collection
- Biba n 445 ddl
- Ddl adalah