1 / 31

DATA MANIPULATION andCONTROL

DATA MANIPULATION andCONTROL. 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.

renee-frye
Download Presentation

DATA MANIPULATION andCONTROL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  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

  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

  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', 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 );

  18. UPDATING THE COLUMNS & ROWS:

  19. 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.

  20. 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.

  21. Consider the CUSTOMERS table having the following records:

  22. Following is an example, which would update ADDRESS for a customer whose ID is 6: SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune' WHERE ID = 4;

  23. Now, CUSTOMERS table would have the following records:

  24. DELETING ROW FROM TABLE

  25. 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.

  26. 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.

  27. Consider the CUSTOMERS table having the following records:

  28. Following is an example, which would DELETE a customer, whose ID is 6: SQL> DELETE FROM CUSTOMERS WHERE ID = 4;

  29. Now, CUSTOMERS table would have the following records:

More Related