๐Ÿ”ผDDL Commands

What are DDL Commands?

DDL or Data Definition Language commands are used to define and manage the structure of database objects like tables, indexes, views etc.

๐Ÿ“š Rules for DDL Commands ๐Ÿ“š

SQL DDL commands are used to define and modify database schema objects like tables, indexes etc.

๐Ÿ—’๏ธ Rules for CREATE Command ๐Ÿ—’๏ธ

The CREATE command is used to create a new database object.

  • Specify object type (TABLE, INDEX etc.) after CREATE

  • Object name must follow standard naming conventions

  • Columns, data types, constraints etc. defined within parentheses

CREATE TABLE users (
  id INT PRIMARY KEY, 
  name VARCHAR(50) NOT NULL
);

This creates a new table called users with two columns.

โœ๏ธ Rules for ALTER Command โœ๏ธ

The ALTER command modifies an existing database object.

  • Specify object name after ALTER

  • Add, remove, or modify columns, constraints etc.

  • Can rename objects using RENAME TO

ALTER TABLE users 
ADD email VARCHAR(100);

This adds a new column to the existing users table.

โŒ Rules for DROP Command โŒ

The DROP command is used to delete objects from the database.

  • Specify object type and name after DROP

  • Removed object and all associated data are deleted

  • Cannot be undone, use with caution

DROP TABLE users;

This permanently deletes the users table from the database.

So those are some key rules for the main SQL DDL commands like CREATE, ALTER and DROP. Following SQL standards allows portable DDL across database systems.

Last updated