Experiment 2
Experiment 2
:0103IT181121 Date:06-01-2020
Experiment- 2
Aim: To write a query with a function of data definition language (DDL) commands
such as create, alter, rename, truncate in RDBMS
1. About DDL statements:
A data definition language (DDL) is a computer language used to create and modify the structure of database
objects in a database. These database objects include views, schemas, tables, indexes, etc.
This term is also known as data description language in some contexts, as it describes the fields and records
in a database table.
2. How to create table in database IT_4thB_Batch_2.
Syntax: Create table table_name(Col_name_1 data_type(length),
Col_name_2 data_type(length),
...Col_name_N data_type(length));
Example:Create table Student_LNCT_IT with attributes S_Name,S_Enroll,S_Semester,S_Mobile,S_City.
Command:Create table Student_LNCT_IT(S_Name char(16),
-> S_Enroll varchar(12),
-> S_Semester int(1),
-> S_Mobile int(10),
-> S_City char(10));
Query OK, 0 rows affected (0.07 sec)
3. How to show the structure or description of the table Student_LNCT_IT:
Syntax: Desc table_Name;
mysql> Desc Student_LNCT_IT;
+------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+-------+
| S_Enroll | varchar(12) | YES | | NULL | |
| S_Name | char(20) | YES | | NULL | |
| S_Semester | int(2) | YES | | NULL | |
| S_Mobile_No | int(10) | YES | | NULL | |
| S_City | char(10) | YES | | NULL | |
+------------------+--------------+-------+-----+---------+-------+
5 rows in set (0.00 sec)
4. How to alter previous created column data type and length:
Syntax: Alter table table_Name modify Column_Name New_Data_Type(New_Length);
Example: Change the datatype and length of S_Enroll to int & 14.
mysql> Alter table Student_LNCT_IT modify S_Enroll int(14);
Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0
5. How to check changes is made in table Student_LNCT_IT:
mysql> Desc Student_LNCT_IT;
+-----------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+------------+------+-----+---------+-------+
| S_Enroll | int(14) | YES | | NULL | |
| S_Name | char(20) | YES | | NULL | |
| S_Semester | int(2) | YES | | NULL | |
| S_Mobile_No | int(10) | YES | | NULL | |
| S_City | char(10) | YES | | NULL | |
+-----------------+-----------+------+-----+---------+-------+
6. How to change the name of the column in table Student_LNCT_IT:
Syntax: Alter table table_Name change Old Column_Name New Column_Name data_Type(Length);
Example: Change the column name S_Enroll to S_Id in table Student_LNCT_IT;
mysql> Alter table Student_LNCT_IT change S_Enroll S_Id int(14);
Query OK, 0 rows affected (0.17 sec)
Records: 0 Duplicates: 0 Warnings: 0
7. How to check changes is made in table Student_LNCT_IT:
mysql> Desc Student_LNCT_IT;
+------------------+----------+-------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------+-------+-----+----------+-------+
| S_Id | int(14) | YES | | NULL | |
| S_Name | char(20) | YES | | NULL | |
| S_Semester | int(2) | YES | | NULL | |
| S_Mobile_No | int(10) | YES | | NULL | |
| S_City | char(10) | YES | | NULL | |
+-----------------+-----------+-------+-----+----------+-------+
5 rows in set (0.00 sec)
8. How to add new column S_Branch in Student_LNCT_IT table.
Syntax: Alter table table_name add new column_name datatype(Length);
Date of Submission:
20-01-2020