SQL SERVER – Example of DDL, DML, DCL and TCL Commands

DML

DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.

SELECT – Retrieves data from a table
INSERT –  Inserts data into a table
UPDATE – Updates existing data into a table
DELETE – Deletes all records from a table

DDL

DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.

CREATE – Creates objects in the database
ALTER – Alters objects of the database
DROP – Deletes objects of the database
TRUNCATE – Deletes all records from a table and resets table identity to initial value.

DCL

DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.

GRANT – Gives user’s access privileges to database
REVOKE – Withdraws user’s access privileges to database given with the GRANT command

TCL

TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.

COMMIT – Saves work done in transactions
ROLLBACK – Restores database to original state since the last COMMIT command in transactions
SAVE TRANSACTION – Sets a savepoint within a transaction

Reference : Pinal Dave (https://blog.sqlauthority.com), Original Source

Database
Previous Post
SQLAuthority News – Gandhinagar SQL Server User Group Meeting April 24, 2009
Next Post
SQL SERVER – Add or Remove Identity Property on Column

Related Posts

62 Comments. Leave new

  • Brian Tkatch
    May 4, 2009 5:17 pm

    The terms DML and DDL are used commonly enough amongst developers trying to get a point across. DCL is something i rarely see outside of books.

    BTW, wouldn’t SAVE TRANSACTION also be part of TCL?

    Reply
  • What about the BackUP and Restore Command ?

    Reply
  • As a web developer, i find that info very intesting and benificail. never heard before.

    thanks for nice explanation.

    Reply
    • really a wonderful article. The information is very helpful.It cleared many doubts i was having.

      Reply
  • hi its a nice description abt sql server .. i want to need more points from this way

    Reply
  • hi pinaldave

    i want to create a single trigger which monitor the inserted, Updated and Deleted transaction records to my customer table, and the effected datas should be archive to a table with the following tag

    if a transaction Inserted TAG= INS
    if a transaction updated TAG= UPD
    if a Transaction Deleted TAG= DEL

    and also should send a notification mail to operator

    please help me.
    thanks

    Reply
  • Imran Mohammed
    March 10, 2010 11:01 am

    @Nusrath,

    You gave us your requirement which is good, but what is your question. What kind of help you want, please explain in detail and be very specific and provide more information if you want to notify through email on a scheduled basis or every occurrence of event (Insert, update, delete)

    ~ IM.

    Reply
  • thanks for your response Mr. Imran Mohamed

    Ok i’ll explain all.

    i have a Database call posdb and the database contains following tables

    1. customer table contains following columns

    ([cust_id] ,
    [name] ,
    [address] ,
    [city],
    [state],
    [zip])

    2. customer_archive table contains following columns

    ([cust_id] ,
    [name] ,
    [address] ,
    [city],
    [state],
    [zip],
    [IID],
    [Tdate],
    [user])

    now my question is

    1.how to create a DML trigger to accomplish following requirements.

    #if a user delete records on customer table, the deleted records are should be saved on customer_archive Table with IID value = ‘DEL’ and deleted user.

    #if a user update records on customer table, the updated records are should be saved on customer_archive Table with IID value = ‘UPD’ and deleted user.

    #if a user insert records on customer table, the inserted records are should be saved on customer_archive Table with IID value = ‘INS’and deleted user.

    and when the trigger fired notify the operator via email

    and i am sorry im not fluent in English
    please help me.

    Reply
  • Good Notes

    Reply
  • Its good and quite simple…
    Thanks

    Reply
  • quite simple to understand

    Reply
  • it,s good……but i export more

    Reply
  • Really good 1.. thanx for summing up everything in an easy to understand fashion

    Reply
  • really good easy to learning the steps

    Reply
  • Hello Sir,

    I always your articles and it always help me but now in this article i have little bit confuse because of “Select command”.

    1.) if select command comes in DML than which command comes in DQL ?

    Second thing is that in most interview normally interviewer always ask one question that “Can we use DML commands in Function ?”
    may be its answer is NO.

    because we can’t use insert,update,delete command in Function. Now what about in that answer is that wrong ?

    Please help me. in this

    Reply
  • Hi sir..
    Good Day….

    I wnated to ask some help from you, could you please give me some example of ddl (data definition language) its our assignment form our class database menagement.

    Thank you, God bless…

    Reply
  • Hi sir..

    Good Day….

    I wanted to ask some help from you, could you please give me some example of ddl(data definition language) its our assignment form our class database menagement.

    Thank you, God bless…

    Reply
  • I need some examples on TCL,DCL commands with syntax.

    Reply
  • hi ,
    i need more information on sql & plsql in interview point of view,can u suggest me on which topics i should be more perfect ..
    thanku verymuch

    Reply
  • Fahim Manzoor
    May 25, 2011 4:24 pm

    Hi,
    I have a logical issue which i am trying to solve from a long time but no success. Hopefully you will be able to help me.

    The thing is iam trying to move an Excel report to SSRS plateform, The data in excel is populated through formulaes and if the condition doesnt satisfy it return 0 but the same thing doesnt apply in Sql. if the Condition doesnt satisfy it doesnt return anything not even zero and beacuse of which the column is also not reflecting in the report. so is there any logic which you can help me with. if the data for the column is not there will i be able to atleast show the column heading.

    Thanks,
    Fahim.

    Reply
    • Fahim,
      What i understood from your question is that you need to return at least something whether you have or not any data for any particular column?

      ok, here you can simply go for ISNULL function which returns desired values of the developer if the value is null.

      e.g.

      Select ISNULL(ABC, “”)

      here abc is a column of varchar type datatype. if it has null value then ISNULL function will return a blank which will avoid throwing any exception.

      it depends on the columns datatype, if it is varchar, char then use double quotes and if int, double, decimal, float or similar datatypes then can go for 0.

      hope that helps!!! Cheers!!!

      Reply
  • venu gopal reddy
    August 25, 2011 11:41 pm

    hi sir..
    can u explain about GRANT command with EXAMPLES..please

    Reply

Leave a Reply