Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views3 pages

DDL Commands

The document details a series of SQL commands executed on a database named 'college'. It includes creating a table, inserting records, altering the table structure, and finally dropping the table. The commands demonstrate basic database operations such as SELECT, INSERT, ALTER, TRUNCATE, and DROP.

Uploaded by

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

DDL Commands

The document details a series of SQL commands executed on a database named 'college'. It includes creating a table, inserting records, altering the table structure, and finally dropping the table. The commands demonstrate basic database operations such as SELECT, INSERT, ALTER, TRUNCATE, and DROP.

Uploaded by

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

use college;

Database changed

//CREATE COMMAND n

mysql> create table college(college_id int(3),college_name varchar(20),college_dept


varchar(10),college_fees int(5));
Query OK, 0 rows affected, 2 warnings (0.06 sec)

//SELECT COMMAND

mysql> select * from college;


Empty set (0.01 sec)

insert into college values(101,'madhu','cs',12000);


Query OK, 1 row affected (0.01 sec)

mysql> select * from college;


+------------+--------------+--------------+--------------+
| college_id | college_name | college_dept | college_fees |
+------------+--------------+--------------+--------------
| 101 | madhu | cs | 12000 |
+------------+--------------+--------------+--------------+
1 row in set (0.00 sec)

mysql> insert into college values(102,'preetha','cs',15000);


Query OK, 1 row affected (0.01 sec)

mysql> select * from college;


+------------+--------------+--------------+--------------+
| college_id | college_name | college_dept | college_fees |
+------------+--------------+--------------+--------------+
| 101 | madhu | cs | 12000 |
| 102 | preetha | cs | 15000 |
+------------+--------------+--------------+--------------+
2 rows in set (0.00 sec)

mysql> insert into college values(103,'dharmavathi','cs',12000);


Query OK, 1 row affected (0.01 sec)

mysql> select * from college;


+------------+--------------+--------------+--------------+
| college_id | college_name | college_dept | college_fees |
+------------+--------------+--------------+--------------+
| 101 | madhu | cs | 12000 |
| 102 | preetha | cs | 15000 |
| 103 | dharmavathi | cs | 12000 |
+------------+--------------+--------------+--------------+
3 rows in set (0.00 sec)

//ALTER ADD COMMAND

alter table college add college_phoneNumber int(10);


Query OK, 0 rows affected, 1 warning (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 1

mysql> select * from college;


+------------+--------------+--------------+--------------+---------------------+
| college_id | college_name | college_dept | college_fees | college_phoneNumber |
+------------+--------------+--------------+--------------+---------------------+
| 101 | madhu | cs | 12000 | NULL |
| 102 | preetha | cs | 15000 | NULL |
| 103 | dharmavathi | cs | 12000 | NULL |
+------------+--------------+--------------+--------------+---------------------+
3 rows in set (0.00 sec)

desc college;
+---------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+-------------+------+-----+---------+-------+
| college_id | int | YES | | NULL | |
| college_name | varchar(20) | YES | | NULL | |
| college_dept | varchar(10) | YES | | NULL | |
| college_fees | int | YES | | NULL | |
| college_phoneNumber | int | YES | | NULL | |
+---------------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

//ALTER MODIFY COMMAND

alter table college modify column college_name varchar(30);


Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc college;


+---------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+-------------+------+-----+---------+-------+
| college_id | int | YES | | NULL | |
| college_name | varchar(30) | YES | | NULL | |
| college_dept | varchar(10) | YES | | NULL | |
| college_fees | int | YES | | NULL | |
| college_phoneNumber | int | YES | | NULL | |
+---------------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

//ALTER RENAME COMMAND

alter table college rename column college_fees to Fees;


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc college;


+---------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+-------------+------+-----+---------+-------+
| college_id | int | YES | | NULL | |
| college_name | varchar(30) | YES | | NULL | |
| college_dept | varchar(10) | YES | | NULL | |
| Fees | int | YES | | NULL | |
| college_phoneNumber | int | YES | | NULL | |
+---------------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

//TRUNCATE COMMAND

truncate table college;


Query OK, 0 rows affected (0.07 sec)
mysql> select * from college;
Empty set (0.00 sec)

mysql> desc college;


+---------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+-------------+------+-----+---------+-------+
| college_id | int | YES | | NULL | |
| college_name | varchar(30) | YES | | NULL | |
| college_dept | varchar(10) | YES | | NULL | |
| Fees | int | YES | | NULL | |
| college_phoneNumber | int | YES | | NULL | |
+---------------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

//DROP COMMAND

drop table college;


Query OK, 0 rows affected (0.07 sec)

mysql> select * from college;


ERROR 1146 (42S02): Table 'college.college' doesn't exist
ygdsyutgdf

You might also like