Data Definition Language (CREATE, ALTER, DROP)
Data Definition Language (CREATE, ALTER, DROP) The CREATE, ALTER, DROP keywords are used in SQL to perform operations on data objects, such as tables an...
Data Definition Language (CREATE, ALTER, DROP) The CREATE, ALTER, DROP keywords are used in SQL to perform operations on data objects, such as tables an...
Data Definition Language (CREATE, ALTER, DROP)
The CREATE, ALTER, DROP keywords are used in SQL to perform operations on data objects, such as tables and views. These commands allow you to define new data structures, modify existing ones, and remove them altogether.
CREATE
The CREATE keyword is used to create a new data object, such as a table or view.
Example:
sql
CREATE TABLE customers (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL
);
ALTER
The ALTER keyword is used to modify an existing data object. For example, you can:
Modify the data type of a column
Add or remove constraints
Rename a table or view
Example:
sql
ALTER TABLE orders MODIFY column order_date DATE;
DROP
The DROP keyword is used to remove a data object, such as a table or view.
Example:
sql
DROP TABLE orders;
Additional Notes
You can use the CREATE, ALTER, DROP keywords together to perform multiple operations. For example, you could create a table, add a column to it, and then drop the table later.
The CREATE, ALTER, DROP keywords are used by data administrators and developers to manage data objects.
These keywords are essential for understanding and using SQL effectively