Microsoft Windows [Version 10.0.22621.
2428]
(c) Microsoft Corporation. All rights reserved.
C:\Windows\System32>mysql -u root -p
Enter password: **************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| school |
| sys |
| world |
+--------------------+
7 rows in set (0.00 sec)
mysql> desc school;
ERROR 1046 (3D000): No database selected
mysql> select * from school;
ERROR 1046 (3D000): No database selected
mysql> desc Student;
ERROR 1046 (3D000): No database selected
mysql> use school;
Database changed
mysql> desc Student;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| ID | int | YES | | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Age | int | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> alter table Student add(Address varchar(100));
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc Student;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| ID | int | YES | | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Age | int | YES | | NULL | |
| Address | varchar(100) | YES | | NULL | |
+---------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select * from Student;
+------+------+------+---------+
| ID | Name | Age | Address |
+------+------+------+---------+
| 100 | Ram | 22 | NULL |
| 200 | Vim | 21 | NULL |
| 300 | Raj | NULL | NULL |
| 400 | Amy | NULL | NULL |
+------+------+------+---------+
4 rows in set (0.00 sec)
mysql> alter table Student add(Email_ID varchar(100), Contact_No varchar(100));
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select * from Student;
+------+------+------+---------+----------+------------+
| ID | Name | Age | Address | Email_ID | Contact_No |
+------+------+------+---------+----------+------------+
| 100 | Ram | 22 | NULL | NULL | NULL |
| 200 | Vim | 21 | NULL | NULL | NULL |
| 300 | Raj | NULL | NULL | NULL | NULL |
| 400 | Amy | NULL | NULL | NULL | NULL |
+------+------+------+---------+----------+------------+
4 rows in set (0.00 sec)
mysql> alter table Student add(Test int default 100);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select * from Student;
+------+------+------+---------+----------+------------+------+
| ID | Name | Age | Address | Email_ID | Contact_No | Test |
+------+------+------+---------+----------+------------+------+
| 100 | Ram | 22 | NULL | NULL | NULL | 100 |
| 200 | Vim | 21 | NULL | NULL | NULL | 100 |
| 300 | Raj | NULL | NULL | NULL | NULL | 100 |
| 400 | Amy | NULL | NULL | NULL | NULL | 100 |
+------+------+------+---------+----------+------------+------+
4 rows in set (0.00 sec)
mysql> desc Student;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| ID | int | YES | | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Age | int | YES | | NULL | |
| Address | varchar(100) | YES | | NULL | |
| Email_ID | varchar(100) | YES | | NULL | |
| Contact_No | varchar(100) | YES | | NULL | |
| Test | int | YES | | 100 | |
+------------+--------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
mysql> alter table Student modify Contact_No int;
Query OK, 4 rows affected (0.02 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> desc Student;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| ID | int | YES | | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Age | int | YES | | NULL | |
| Address | varchar(100) | YES | | NULL | |
| Email_ID | varchar(100) | YES | | NULL | |
| Contact_No | int | YES | | NULL | |
| Test | int | YES | | 100 | |
+------------+--------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
mysql> alter table Student change Address Location varchar(100);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc Student;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| ID | int | YES | | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Age | int | YES | | NULL | |
| Location | varchar(100) | YES | | NULL | |
| Email_ID | varchar(100) | YES | | NULL | |
| Contact_No | int | YES | | NULL | |
| Test | int | YES | | 100 | |
+------------+--------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
mysql> alter table Student drop column Test;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc Student;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| ID | int | YES | | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Age | int | YES | | NULL | |
| Location | varchar(100) | YES | | NULL | |
| Email_ID | varchar(100) | YES | | NULL | |
| Contact_No | int | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> desc Faculty;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| Faculty_ID | int | NO | PRI | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Course | varchar(100) | NO | | NULL | |
| Salary | int | YES | | 10000 | |
+------------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select * from Faculty;
+------------+------+--------+--------+
| Faculty_ID | Name | Course | Salary |
+------------+------+--------+--------+
| 101 | SKS | OOPS | 90000 |
| 102 | SNL | OS | 80000 |
| 103 | NM | DLC | 70000 |
+------------+------+--------+--------+
3 rows in set (0.00 sec)
mysql>