SQL DDL vs DML Commands Quiz
12 Questions
3 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the primary objective of the Data Definition Language (DDL) in SQL?

  • Manipulate data in the tables
  • Query the database for information
  • Insert new records into tables
  • Create and modify the database structure (correct)
  • Which DDL operation is used to remove specified database objects like tables?

  • Drop (correct)
  • Truncate
  • Alter
  • Create
  • In SQL, which DDL command would you use to add explanatory text to the database definitions?

  • Alter
  • Comment (correct)
  • Drop
  • Truncate
  • After executing a CREATE command in SQL to create a table, what is the primary database object that is generated?

    <p>Tables</p> Signup and view all the answers

    Which DDL operation is responsible for modifying the structure of an already existing table by adding or removing columns?

    <p>Alter</p> Signup and view all the answers

    What does the Truncate DDL command do in SQL?

    <p>Remove all records from a table</p> Signup and view all the answers

    What SQL command should you use to add a new column called emp_address to the employees table?

    <p>ALTER TABLE employees ADD COLUMN emp_address VARCHAR(100)</p> Signup and view all the answers

    If you want to completely delete the employees table, which SQL command would you use?

    <p>DROP TABLE employees</p> Signup and view all the answers

    Which SQL command is used to insert a new row of data into a table?

    <p>INSERT INTO employees VALUES (101, 'John', 'Software Engineer', 80000)</p> Signup and view all the answers

    Suppose you need to update the emp_salary for an employee with emp_id 101. Which SQL command would you use?

    <p>UPDATE employees SET emp_salary = 90000 WHERE emp_id = 101</p> Signup and view all the answers

    What does the SQL TRUNCATE command do?

    <p>Delete all rows from a table</p> Signup and view all the answers

    Which of the following commands is NOT part of DML in SQL?

    <p><strong>Drop</strong></p> Signup and view all the answers

    Study Notes

    SQL DDL and DML

    In SQL, two fundamental broad categories of commands exist: Data Definition Language (DDL) and Data Manipulation Language (DML). Both sets of commands serve distinct purposes. However, understanding their differences begins with recognizing the similarities between them.

    SQL DDL

    The main objective of Data Definition Language (DDL) is to shape the database's structure. It provides a means to describe, create, and manipulate the metadata, including tables, indices, and other database objects. Some common DDL operations are:

    • Create: Used to establish new database objects, such as tables, indexes, procedures, or functions.
    • Alter: Essentially used for modifying the structure of an already present table by adding or removing columns or modifying their parameters.
    • Drop: Execution of this command results in the removal of specified database objects, like tables.
    • Truncate: Removal of all records from a particular table while keeping the table structure intact.
    • Comment: Adds explanatory text to the database definitions.

    For instance, let's say you have a database with a table named employees. Using the CREATE command, you could create a table for employees with their respective columns:

    CREATE TABLE employees (
        emp_id INT PRIMARY KEY,
        emp_name VARCHAR(50),
        emp_salary FLOAT
    )
    

    After successfully executing this command, a new table called employees would be created. Now, assuming you wish to add a new column called emp_address to this table, you would use the ALTER command:

    ALTER TABLE employees ADD COLUMN emp_address VARCHAR(100)
    

    If you decide to delete the table entirely, you can utilize the DROP command:

    DROP TABLE employees
    

    Finally, if you need to remove all records from the employees table, you can employ the TRUNCATE command:

    TRUNCATE TABLE employees
    

    SQL DML

    On the other hand, Data Manipulation Language (DML) enables the interaction with data stored within the database. It focuses on performing operations involving CRUD (Create, Read, Update, Delete) actions. Specifically, DML includes the following commands:

    • Select: This command retrieves data from the database, returning information from tables or views.
    • Insert: Utilized to introduce new rows of data into the table.
    • Update: Facilitates modification of existing rows in a table.
    • Delete: Erases selected rows from the table.

    As an example, suppose we have an employees table containing details about each employee. With the INSERT command, you can add a new entry for a new hire:

    INSERT INTO employees VALUES (101, 'John', 'Software Engineer', 80000)
    

    To update an existing entry, say you want to increase the emp_salary of employee 101, you can apply the UPDATE command:

    UPDATE employees SET emp_salary = 90000 WHERE emp_id = 101
    

    Lastly, if you wish to remove an employee with emp_id 101, you can utilize the DELETE command:

    DELETE FROM employees WHERE emp_id = 101
    

    In conclusion, understanding the difference between DDL and DML is crucial for effectively utilizing SQL commands. While DDL deals with database structure definition, DML facilitates data manipulation within the established structural framework.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your knowledge on SQL Data Definition Language (DDL) and Data Manipulation Language (DML) commands. Learn about creating, altering, and dropping database objects with DDL, as well as inserting, updating, and deleting data with DML. Understand the key differences between DDL and DML in SQL.

    More Like This

    SQL DDL and DML Basics Quiz
    10 questions

    SQL DDL and DML Basics Quiz

    ChasteHummingbird7953 avatar
    ChasteHummingbird7953
    Data Definition Language (DDL) Overview
    26 questions
    Use Quizgecko on...
    Browser
    Browser