0 votes
220 views
in DataBase Management System by (98.9k points)
edited
Explain any four DDL commands with an example.

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

DDL (Data Definition Language) commands are used to create, modify, and delete database objects such as tables, indexes, and constraints. Here are four common DDL commands with examples of their use:

  1. CREATE: The CREATE command is used to create a new database object, such as a table or index. The syntax for creating a table is:

    CREATE TABLE table_name ( column1 datatype constraints, column2 datatype constraints, ... );

    For example, to create a table called "Students" with columns for name, age, and GPA, we might use the following command:

    CREATE TABLE Students ( Name varchar(255) NOT NULL, Age int NOT NULL, GPA float, PRIMARY KEY (Name) );

    This command creates a table with three columns and a primary key constraint on the "Name" column.

  2. ALTER: The ALTER command is used to modify an existing database object. The syntax for altering a table is:

    ALTER TABLE table_name action;

    where "action" is the modification to be made. For example, to add a new column to the "Students" table, we might use the following command:

    ALTER TABLE Students ADD COLUMN Major varchar(255);

    This command adds a new column called "Major" to the "Students" table.

  3. DROP: The DROP command is used to delete an existing database object. The syntax for dropping a table is:

    DROP TABLE table_name;

    For example, to delete the "Students" table, we might use the following command:

    DROP TABLE Students;

    This command deletes the "Students" table and all of its data.

  4. TRUNCATE: The TRUNCATE command is used to delete all the data from a table. The syntax for truncating a table is:

    TRUNCATE TABLE table_name;

    For example, to remove all the data from the "Students" table, we might use the following command:

    TRUNCATE TABLE Students;

    This command deletes all the rows in the "Students" table, but leaves the table structure intact

Related questions

0 votes
1 answer 111 views
0 votes
1 answer 142 views
0 votes
1 answer 144 views
0 votes
1 answer 159 views
0 votes
1 answer 128 views
0 votes
1 answer 117 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...