This tutorial explains the DDL operations performed in SQL. In this tutorial I have selected the schema which I have already created. Look at the tutorial for “Database schema and Tables to create the schema”.
Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
- CREATE - to create objects in the database
- ALTER - alters the structure of the database
- DROP - delete objects from the database
- TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
Create:
Create statement is used to create the table in the database. Here we specify whether we are creating a column table or row table, then fields in the table and mark the primary key.
Choose a schema of your choice and write the following SQL Command
Query:
Result:
Execute the query and refresh the schema, you will see the new table created within the schema.
Right click on the data and click on open data definition.
You can see the table created with the fields specified by us.
Alter Table:
Now we have already created the table definition(Structure), now if we wanted to add or remove the existing column we can use the alter command to modify the table.
e.g. Insert a column, gross amount to the table.
Query:
Result:
Execute the query and open the data definition of the table.
You can see the column gross amount added.
Truncate:
Truncate is the DDL command which is used to remove all the contents of the table. In the table we have created I have added some content using the insert statement.
Data preview
Now let’s remove the contents in the table using SQL command Truncate.
Query:
Result:
Refresh the data preview.
Drop:
Unlike the truncate, the drop command remove the table from the database itself. The truncate removes the content of the table where as drop removes the table itself.
Query :
Result:
Refresh the schema and look in the tables:
In the next tutorials we will see the different DML statements.
may i know which tool you used to write the Queries .
ReplyDeleteHANA
DeleteAppreciating the persistence you put into your blog and detailed information you provide.
ReplyDeleteoracle training in bangalore
ReplyDeleteThanks for sharing the information
sap training center in delhi
sap training center in Noida
Great Article Artificial Intelligence Projects
ReplyDeleteProject Center in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai Project Centers in Chennai