SQL DDL (Data Definition Language) queries with examples:
- Get link
- X
- Other Apps
DDL stands for Data Definition Language. It
is a subset of SQL (Structured Query Language) used for defining and managing
the structure of a relational database. DDL commands enable database
administrators and users to create, modify, and delete database objects such as
tables, indexes, and views.
Here are details of some SQL DDL (Data Definition
Language) queries with examples:
- CREATE TABLE:
- Description: Used to create a new table in
the database.
- Example:
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
emp_name VARCHAR(50),
emp_salary DECIMAL(10, 2)
);
- ALTER TABLE:
- Description: Used to modify the structure of
an existing table.
- Example:
ALTER TABLE employees
ADD COLUMN emp_department VARCHAR(30);
- DROP TABLE:
- Description: Used to delete an entire table
along with its data and structure.
- Example:
DROP TABLE employees;
- CREATE INDEX:
- Description: Used to create an index to
improve data retrieval efficiency.
- Example:
CREATE INDEX emp_name_index ON
employees (emp_name);
- ALTER INDEX:
- Description: Used to modify the structure of
an existing index.
- Example:
ALTER INDEX emp_name_index RENAME TO
emp_full_name_index;
- DROP INDEX:
- Description: Used to remove an existing
index.
- Example:
DROP INDEX emp_full_name_index;
- TRUNCATE:
· Description: Used to remove all rows from a table
but retain its structure for future use.
- Example:
TRUNCATE TABLE employees;
- COMMENT:
·
Description Used to add comments to the data
dictionary.
· Example:
COMMENT ON TABLE employees IS 'Table
storing employee information';
DDL commands
are powerful and have a significant impact on the database structure. They are
typically executed by database administrators or users with the necessary
privileges to manage the database schema.
Comments
Post a Comment