Data Definition Language (DDL) Flashcards
6 cards from real SQL practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Data Definition Language (DDL) flashcards as text
Which of the following SQL statements is NOT considered a Data Definition Language (DDL) command?
Answer: UPDATE
DDL commands are used to define and manage the structure of database objects. CREATE, ALTER, and DROP are all DDL commands used to create, modify, and delete tables respectively. UPDATE is a Data Manipulation Language (DML) command used to modify existing records within a table.
A database administrator needs to remove all rows from a large table named `LogData` but wants to keep the table structure for future use. Which DDL command is the most efficient for this task?
Answer: TRUNCATE TABLE LogData;
The TRUNCATE TABLE command is designed to quickly delete all rows from a table. It is more efficient than DELETE because it deallocates the data pages without logging each individual row deletion. DROP TABLE would remove the entire table structure, which is not the desired outcome.
You are tasked with adding a new column named `Email` with a data type of `VARCHAR(255)` to an existing table called `Employees`. Which is the correct DDL syntax to accomplish this?
Answer: ALTER TABLE Employees ADD Email VARCHAR(255);
The `ALTER TABLE` statement is used to modify the structure of an existing table. The `ADD` clause is used specifically to add a new column, followed by the column name and its data type.
Which DDL statement is used to define a new table, including its columns, data types, and constraints?
Answer: CREATE TABLE
The `CREATE TABLE` statement is the fundamental DDL command used to create a new table in a database. Its syntax allows for the definition of the table's name, the names of its columns, the data type for each column, and any applicable constraints like PRIMARY KEY or NOT NULL.
A developer wants to change the name of an existing table from `tbl_Users` to `Users`. Which of the following commands should be used?
Answer: RENAME TABLE tbl_Users TO Users;
The `RENAME TABLE` command is the standard DDL statement used to change the name of an existing table. While some database systems might use a variation like `ALTER TABLE ... RENAME TO`, `RENAME TABLE` is also a common and direct syntax.
What is the primary difference between the `DROP TABLE` and `TRUNCATE TABLE` commands?
Answer: DROP TABLE removes the entire table structure and its data, while TRUNCATE TABLE only removes the data.
`DROP TABLE` is a DDL command that permanently removes the entire table, including its structure, data, indexes, and constraints. `TRUNCATE TABLE` is also a DDL command, but it only removes all the data rows from the table, leaving the table structure intact for future use.