Skip to main content

DDL Queries

                        DDL(DATA DEFINITION LANGUAGE)

           DDL refers to "Data Definition Language", a subset of SQL statements that change the structure of the database schema in some way, typically by creating, deleting, or modifying schema objects such as databases, tables, and views.

   ➤CREATE
➤ALTER
➤DROP
➤TRUNCATE
  ➤RENAME


Create Query:-

➧    CREATE TABLE EMP(EMPID NUMBER(5),NAME VARCHAR2(15), SALARY  NUMBER(7,2),EMAIL VARCHAR(20));

➧    CREATE TABLE DEPT AS SELECT * FROM DEPARTMENTS;
"This Query will Create Table when we want to copy the data of any table into new table.Here old table is DEPARTMENTS.


Alter Query:- ALTER' COMMAND IS USED TO MODIFY TABLE STRUCTURE.
➧    ALTER TABLE EMP MODIFY EMPID NUMBER(10); 
"this will change the data type of any attribute in the table."

➧ ALTER TABLE EMP RENAME COLUMN NAME TO FIRST_NAME;

➧  ALTER TABLE EMP DROP COLUMN HIRE_DATE;


Drop Query:-DROP statement allows you to remove database, table, index or stored procedure.

➧  DROP TABLE TABLE_NAME;


Truncate Query:-TRUNCATE operation is used to delete all table records.
Differences between DELETE and TRUNCATE commands are:
  • TRUNCATE is really faster.
  • TRUNCATE cannot be rolled back.
  • TRUNCATE command does not invoke ON DELETE triggers.
➧  TRUNCATE TABLE TABLE_NAME;

Rename Query:-RENAME command is used to rename SQL table.

➧  RENAME EMP TO E;

Comments

Popular posts from this blog

Aggregate And Numeric Functions.

                   Aggregate And Numeric Functions SQL has many built-in functions for performing processing on string or numeric data. ➥ AGGREGATEE FUNCTIONS:-    ➧ Average function : Returns average value of 'n', ignoring null values.         Example: SE LECT AVG(sell_price) from product;      ➧ COUNT  :Counts rows in a specified table or view.        Example: SELECT    COUNT ( * ) FROM products ;     ➧ MIN  : G ets the minimum value in a set of values.         Example: SELECT MIN ( unitsinstock ) FROM   products ;     ➧ MAX  : Gets the maximum value in a set of values.         Example: SELECT    MAX ( unitsinstock ) FROM    products ;     ➧ SUM  :Ca lculates the sum of values       Example:SELECT ...