Database Languages

We have already understood how a database and its management is done and why is it used.
Suppose you are browsing your internet suppose for downloading image of an apple.That image is residing somewhere in computer database.Now the question comes, how you are going to retrieve that image?
Check following steps:
Step 1: you will type “image of apple” in browser.
Step 2: system has to search in database to find the image
Step 3: system will give you back the image.

But unlike us humans, our computer won’t understand basic languages and commands. So for commanding the database(for any work like updating any value or retrieving any information etc) some standard languages are used. These are called database languages. Based on the action to be performed, these languages are categorized into following categories:
1. DDL
2. DML
3. DCL
4. TCL
We will go through each of these languages in depth.
1. DDL(Data Definition Language):
As the name suggests, this language is used to define the basic structure of database. In database, all the data are stored in table format. To create those table or to define in which row and column which data has to be stored, what to be stored, what to be deleted DDL or Data Definition Language is used.
The following commands are used as a part of Data Definition Language.
1.CREATE :To create the table , Create command is used.

Syntax : Create table table_name(col_name1 datatype,col_name2 datatype…);
Example : Suppose You are creating a table student_information in which you want to store student’s name and roll number:
Create table student_information(Name varchar(20),Roll No int(12));
Following table shall get created:

Table name: Student_information

1

2.ALTER : alters the structure of the database
As you have already created the above table student_information, suppose you want to
1.Add a new column branch
2.Delete the existing column Roll_no
3.Change the table name
4.Change the Column name

For all these tasks, Alter command is used.
We will see how we can use Alter command to complete our task:

1. To add a new column:
Syntax : Alter table table name add column column_name data type;
Example : Alter table student_information add column branch varchar(20);

Following table shall get created:

Table name: Student_information

2
2. Deleting the existing column:
Syntax : Alter table table name drop column column_name;
Example : Alter table student_information drop column Roll No.;

Following table shall get created:
Table name: Student_information

1
3.Change the table name:
Syntax : ALTER TABLE table_name RENAME TO new_table_name;
Example : Alter table student_information RENAME TO student;

Following table shall get created:
Table name: Student

1
4.Change the Column name:
Syntax: ALTER TABLE table_name

RENAME COLUMN old_Column_name

to new_Column_name;
Example : Alter table student RENAME COLUMN Branch TO Branch_student;

Following table shall get created:
Table name: Student

1
2. DROP : Drop command is used to remove the entire table from database.
Syntax : Drop table table_name;
Example : Drop table Student;
Will remove the entire table from the database.

3. TRUNCATE : When a truncate command is used, all the data for a given table gets deleted.

Syntax : Truncate table table_name;
Example : Truncate table Student;
4. RENAME : Rename command is used to rename a given database table.
Syntax: Rename table old_tablename to new_tablename;
Example : Rename table Student to information_stud;

Leave a comment