0% found this document useful (0 votes)
10 views4 pages

Experiment 2

Uploaded by

nakkal732
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Experiment 2

Uploaded by

nakkal732
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Enrollment No.

: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);

Name of Student:Vaishnavi Khatri Class Roll No:120


Enrollment No.:0103IT181121 Date:06-01-2020

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);

Name of Student:Vaishnavi Khatri Class Roll No:120


Enrollment No.:0103IT181121 Date:06-01-2020

mysql> Alter table Student_LNCT_IT add S_Branch char(15);


Query OK, 0 rows affected (0.44 sec)
Records: 0 Duplicates: 0 Warnings: 0
9. 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 | |
| S_Branch | char(15) | YES | | NULL | |
+----------------+-----------+-------+-----+---------+-------+
6 rows in set (0.00 sec)
10. How to drop column S_Branch in Student_LNCT_IT table.
Syntax: Alter table table_name drop column_name;
mysql> Alter table Student_LNCT_IT drop S_Branch;
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
11. 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)
12. How to change the name of table Student_LNCT_IT to Student_LNCT_ITB.
Syntax: Rename table Current_table_name to new_table_name.

Name of Student:Vaishnavi Khatri Class Roll No:120


Enrollment No.:0103IT181121 Date:06-01-2020

mysql> Rename table Student_LNCT_IT to Student_LNCT_ITB;


Query OK, 0 rows affected (0.05 sec)
13. How to check changes is made in table Student_LNCT_IT:
mysql> SHOW TABLES;
+--------------------------+
| Tables_in_IT_4B_B1 |
+--------------------------+
| Student_LNCT_ITB |
+--------------------------+
1 row in set (0.00 sec)
14. How to truncate data in table Student_LNCT_ITB:
Syntax: Truncate table table_name;
15. How to drop table Student_LNCT_ITB:
Syntax: Drop table table_name;

Date of Submission:
20-01-2020

Name of Student:Vaishnavi Khatri Class Roll No:120

You might also like