w3resource

SQL Data Definition Language (DDL) Exercises with Solutions


SQL Data Definition Language (DDL) exercises with solutions [15 exercises with solution]

1. Create a Table

Write a SQL query to create a table with specific columns and constraints.

Click me to see the solution

2. Add a New Column

Write a SQL query to add a new column to an existing table.

Click me to see the solution

3. Modify a Column's Data Type

Write a SQL query to change the data type of an existing column in a table.

Click me to see the solution

4. Drop a Column

Write a SQL query to remove a column from an existing table.

Click me to see the solution

5. Add a Unique Constraint

Write a SQL query to add a unique constraint to a column in an existing table.

Click me to see the solution

6. Add a Foreign Key

Write a SQL query to create a foreign key relationship between two tables.

Click me to see the solution

7. Drop a Table

Write a SQL query to permanently delete a table and all its data.

Click me to see the solution

8. Truncate a Table

Write a SQL query to remove all rows from a table while retaining its structure.

Click me to see the solution

9. Create an Index

Write a SQL query to create an index on a column to improve query performance.

Click me to see the solution

10. Drop an Index

Write a SQL query to remove an index from a table.

Click me to see the solution

11. Rename a Table

Write a SQL query to rename an existing table.

Click me to see the solution

12. Add a Default Value

Write a SQL query to assign a default value to a column in an existing table.

Click me to see the solution

13. Remove a Constraint

Write a SQL query to remove a constraint from an existing table.

Click me to see the solution

14. Create a Schema

Write a SQL query to create a new schema in the database.

Click me to see the solution

15. Move a Table to a Schema

Write a SQL query to move a table from one schema to another.

Click me to see the solution

More to Come !


Practice Online



Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.