Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
SAP HANA

Data Definition language

 

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:

clip_image002[4]

 

Result:

Execute the query and refresh the schema, you will see the new table created within the schema.

clip_image004[4]

 

Right click on the data and click on open data definition.

clip_image006[4]

 

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:

clip_image007[4]

 

Result:

Execute the query and open the data definition of the table.

clip_image008[4]

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.

clip_image010[4]

Data preview

clip_image011[4]

 

Now let’s remove the contents in the table using SQL command Truncate.

Query:

clip_image012[4]

Result:

Refresh the data preview.

clip_image014[4]

 

 

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 :

clip_image015[4]

 

Result:

Refresh the schema and look in the tables:

clip_image017[4]

 

 

In the next tutorials we will see the different DML statements.

 

 

About Arun

3 Comments:

  1. may i know which tool you used to write the Queries .

    ReplyDelete
  2. Appreciating the persistence you put into your blog and detailed information you provide.

    oracle training in bangalore


    ReplyDelete

Powered by Blogger.