Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Enter password: *******

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 12

Server version: 8.0.35 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> use krishna;

Database changed

mysql> show tables;

+-------------------+

| Tables_in_krishna |

+-------------------+

| book |

| comics |

| employee |

| sem4 |

| student |

| transaction |

+-------------------+

6 rows in set (0.00 sec)

mysql> create table patients(Pid int primary key,Age int);


Query OK, 0 rows affected (0.02 sec)

mysql> insert into patients value(101,23),(102,24),(103,25);

Query OK, 3 rows affected (0.01 sec)

Records: 3 Duplicates: 0 Warnings: 0

mysql> create table hospitals(name varchar(20),city varchar(20),foreign key(Pid) references


Patients(Pid),foreign key(Pid) references Patients(Pid));

ERROR 1072 (42000): Key column 'Pid' doesn't exist in table

mysql> create table hospitals(name varchar(20),city varchar(20),foreign key(Pid) references


Patients(Pid));

ERROR 1072 (42000): Key column 'Pid' doesn't exist in table

mysql> desc patients;

+-------+------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+------+------+-----+---------+-------+

| Pid | int | NO | PRI | NULL | |

| Age | int | YES | | NULL | |

+-------+------+------+-----+---------+-------+

2 rows in set (0.00 sec)

mysql> create table hospitals(name varchar(20),pid int,city varchar(20),foreign key(Pid) references


Patients(Pid));

Query OK, 0 rows affected (0.03 sec)

mysql> insert into hospital values("krishna","Delhi");

ERROR 1146 (42S02): Table 'krishna.hospital' doesn't exist

mysql> insert into hospital values("krishna",,"Delhi");

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ',"Delhi")' at line 1
mysql> insert into hospital values("krishn",101,"Delhi");

ERROR 1146 (42S02): Table 'krishna.hospital' doesn't exist

mysql> insert into hospitals values("krishn",101,"Delhi");

Query OK, 1 row affected (0.03 sec)

mysql> select * from hospitals;

+--------+------+-------+

| name | pid | city |

+--------+------+-------+

| krishn | 101 | Delhi |

+--------+------+-------+

1 row in set (0.00 sec)

mysql> alter table hospitals rename column hospitals to doctors;

ERROR 1054 (42S22): Unknown column 'hospitals' in 'hospitals'

mysql> alter table hospitals rename hospitals to doctors;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'to doctors' at line 1

mysql> rename table Hospitals to Doctors;

Query OK, 0 rows affected (0.02 sec)

mysql> alter table doctors rename column Pid to Did;

Query OK, 0 rows affected (0.02 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc patients;

+-------+------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+------+------+-----+---------+-------+
| Pid | int | NO | PRI | NULL | |

| Age | int | YES | | NULL | |

+-------+------+------+-----+---------+-------+

2 rows in set (0.00 sec)

mysql> desc hospitals;

ERROR 1146 (42S02): Table 'krishna.hospitals' doesn't exist

mysql> desc doctors;

+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| name | varchar(20) | YES | | NULL | |

| Did | int | YES | MUL | NULL | |

| city | varchar(20) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.00 sec)

mysql>truncate table doctors;

You might also like