Thursday, February 29, 2024

DDL command in sql

DATA DEFINITION LANGUAGE



DBMS language

database language are used to read,update and store data in a database.There are several such language that can be used for this purpose : one of them is SQL (Structured Query Language).

    DDL



  • is used for specifying the database schema.It is used for creating tables,schema,indexes,constraint etc.And its used to buld and modify the structure of our table and other objects in the database.When we execute a ddl statement it take effects immediatly.DDLis a subset of Sql and the part of DBMS
  • DDL changes the structure of the table it is work whole table
  • All command of ddl are auto-committed that means it permanently save all the changes in the database.
  • There are some comands:
    1. CREATE
    2. ALTER
    3. DROP
    4. TRUNCATE
    5. RENAME

    1.CREATE

    it is used to create the object,database,tables,views and stored procedure.

    creating Database
    CREATE database demo;

    Explanations

    • CREATE is the syntax
    • database is the syntax follow attribute
    • demo is the database name (its user defined one)
    creating Table
    CREATE TABLE DEMO_TAB (NAME VARCHAR (20),EMAIL VARCHAR(30),DOB DATE);

    Explanations

    • CREATE is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)
    • Inside in parenthesis name is the variable object.That corresponding datatype is very mandatory
    • if the datatype or the variable have any restriction is in size is mentioned in this (0).

    2.DROP

    This command it is used to delete both the structure and record stored in the table.And we can able to drop the database too.

    Drop Database
    DROP database demo;

    Explanations

    • DROP is the syntax.
    • database is the syntax follow attribute
    • demo is the database name (its user defined one)
    DROP Table
    DROP TABLE DEMO_TAB;

    Explanations

    • DROP is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)

    3.ALTER

    it is used to Alter the structure of th database.This change could be either to modify the charectristucs of an existing attribute or probably to add a new attributes.

    Using alter command to ADD colums
    ALTER table demo_tab add si_no int;

    Explanations

    • ALTER is the syntax
    • table is the syntax follow attribute
    • demo_tab is the database name (its user defined one)
    • ADD or add alter requires
    • si_no is the variable objects.
    • As well us variable objects with the corresponding data type
    Using alter command to DROP column
    ALTER table demo_tab drop si_no;

    Explanations

    • ALTER is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)
    • DROP command is the alter requires

    4.TRUNCATE

    it is used to delete an entire objects .delete all records from a table but does not delete the table structure.

    TRUNCATE the table
    TRUNCATE table demo_tab;

    Explanations

    • TRUNCATE is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)


    All of those commands either defines or update the database schema that why they come under Data Definition Language


    DDL command in sql

    DATA DEFINITION LANGUAGE DBMS language database language are used to read,update and store data in a database.There are several suc...