0% found this document useful (0 votes)
31 views

Creating Database For Restaurant Final07

The document describes the creation of tables for a Restaurant database using MySQL. It creates tables for Employees, Dishes, Customers, and Bills. It also demonstrates the use of ALTER, UPDATE, DELETE, and DROP commands to modify the tables after their creation.

Uploaded by

Prasad Kalal
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)
31 views

Creating Database For Restaurant Final07

The document describes the creation of tables for a Restaurant database using MySQL. It creates tables for Employees, Dishes, Customers, and Bills. It also demonstrates the use of ALTER, UPDATE, DELETE, and DROP commands to modify the tables after their creation.

Uploaded by

Prasad Kalal
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/ 21

CREATING DATABASE FOR Restaurant

mysql> create database Restaurant;

Query OK, 1 row affected (0.18 sec)

mysql> use Restaurant;

Database changed
CREATION OF TABLES FOR Restaurant
Employee :-

create table Employe(

-> Fname char(10) NOT NULL,

-> Mname char(10) NOT NULL,

-> Lname char(10) NOT NULL,

-> PHNO int(10) NOT NULL,

-> Age int(10) NOT NULL,

-> DOJ date NOT NULL,

-> EMPI_ID int(20) NOT NULL UNIQUE,

-> primary key(EMPI_ID));

Query OK, 0 rows affected, 3 warnings (1.70 sec)

mysql> desc Employe;

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

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

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

| Fname | char(10) | YES | | NULL | |

| Mname | char(10) | NO | | NULL | |

| Lname | char(10) | NO | | NULL | |

| PHNO | int | NO | | NULL | |

| Age | int | NO | | NULL | |

| DOJ | date | NO | | NULL | |

| EMPI_ID | int | NO | PRI | NULL | |

+-------------+-------------+-------+------+----------+---------+
DISH:-
mysql> create table Dish(

-> SI int(20)NOT NULL,

-> Dish_Name char(20)NOT NULL,

-> Price int(20)NOT NULL,

-> primary key(SI)) ;

Query OK, 0 rows af

fected, 2 warnings (0.33 sec)

mysql> desc Dish;

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

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

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

| SI | int(20) | NO | PRI | NULL | |

| Dish_Name | char(20) | NO | | NULL | |

| Price | int(20) | NO | | NULL | |

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

3 rows in set (0.31 sec)


Customer:-
mysql> create table customer(

-> customer_Name char(10)NOT NULL,

-> customer_ID int(10)NOT NULL,

-> customer_Tableno int(10),

-> customer_PHno int(10),

-> primary key(customer_ID));

Query OK, 0 rows affected, 3 warnings (1.43 sec)

mysql> desc customer;

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

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

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

| customer_Name | char(10) | NO | | NULL | |

| customer_ID | int | NO | PRI | NULL | |

| customer_Tableno | int | YES | | NULL | | NULL | |

| customer_PHno | int | YES | | NULL | | NULL | |

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

4 rows in set (0.39 sec)


BILL:-
mysql> create table BILL(

-> Bill_No int(10)NOT NULL,

-> bill_date date NOT NULL,

-> Payment_method char(20)NOT NULL,

-> customer_ID int(10)NOT NULL,

-> primary key(Bill_No),

-> foreign key(customer_ID)REFERENCES customer(customer_ID));

Query OK, 0 rows affected, 1 warning (0.37 sec)

mysql> desc BILL;

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

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

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

| Bill_No | int(10) | NO | PRI | NULL | |

| bill_date | date | NO | | NULL | |

| Payment_method | char(20) | NO | | NULL | |

|customer_ID |int | NO | MUL | NULL | |

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

3 rows in set (0.00 sec)


USING ALTER COMMAND
BEFORE ALTERING BILL;

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

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

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

| Bill_No | int(10) | NO | PRI | NULL | |

| bill_date | date | NO | | NULL | |

| Payment_method | char(20) | NO | | NULL | |

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

3 rows in set (0.00 sec)

AFTER ALTERING BILL

mysql> ALTER TABLE BILL

-> ADD P_ID varchar(20)NOT NULL;

Query OK, 0 rows affected (0.42 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc BILL;

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

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

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

| Bill_No | int(10) | NO | PRI | NULL | |

| bill_date | date | NO | | NULL | |

| Payment_method | char(20) | NO | | NULL | |

|customer_ID |int | NO | MUL | NULL | |

| P_ID | varchar(20) | NO | | NULL | |

+-------------------------+-----------------+-------+-------+-----------+-----+
USING UPDATE COMMAND
BEFORE ALTERING DISH
+----+----------------------------+-------+

| SI | Dish_Name | Price |

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

| 1 | Neer Dosa | 80 |

| 2 | Korri Gassi | 100 |

| 3 | Mysore Masala Dosa | 150 |

| 4 | Jolada rotti | 50 |

| 5 | Veg Biryani | 120 |

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

5 rows in set (0.00 sec)

AFTER ALTERING DISH

mysql> UPDATE dish

-> set Dish_Name='IDLI VADA'

-> where Price='150';

Query OK, 1 row affected (0.16 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from dish;

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

| SI | Dish_Name | Price|

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

| 1 | Neer Dosa | 80 |

| 2 | Korri Gassi | 100 |

| 3 | IDLI VADA | 150 |

| 4 | Jolada rotti | 50 |

| 5 | Veg Biryani | 120 |


USING DELETE COMMAND
BEFORE ALTERING DISH
+----+------------------+-------+

| SI | Dish_Name | Price |

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

| 1 | Neer Dosa | 80 |

| 2 | Korri Gassi | 100 |

| 3 | IDLI VADA | 150 |

| 4 | Jolada rotti | 50 |

| 5 | Veg Biryani | 120 |

AFTER ALTERING DISH


DELETE from dish

-> where Price=150;

Query OK, 1 row affected (0.34 sec)

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

| SI | Dish_Name | Price |

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

| 1 | Neer Dosa | 80 |

| 2 | Korri Gassi | 100 |

| 4 | Jolada rotti | 50 |

| 5 | Veg Biryani | 120 |


USING DROP COMMAND
BEFORE ALTERING DISH

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

| SI | Dish_Name | Price |

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

| 1 | Neer Dosa | 80 |

| 2 | Korri Gassi | 100 |

| 4 | Jolada rotti | 50 |

| 5 | Veg Biryani | 120 |

AFTER ALTERING DISH


mysql>DROP table dish;

Query OK, 1 row affected (0.30sec)

mysql>select * from dish;

ERROR 1146 (42s02): Table ‘Restaurant .dish’ doesn’t exist


DESCRIBE Employe :-
+-------------+-------------+-------+------+----------+---------+

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

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

| Fname | char(10) | YES | | NULL | |

| Mname | char(10) | NO | | NULL | |

| Lname | char(10) | NO | | NULL | |

| PHNO | int | NO | | NULL | |

| Age | int | NO | | NULL | |

| DOJ | date | NO | | NULL | |

| EMPI_ID | int | NO | PRI | NULL | |

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

DESCRIBE DISH:-
+-----------------+------------+-------+-------+-----------+-----+

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

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

| SI | int(20) | NO | PRI | NULL | |

| Dish_Name | char(20) | NO | | NULL | |

| Price | int(20) | NO | | NULL | |

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

3 rows in set (0.31 sec)


DESCRIBE Customer:-

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

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

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

| customer_Name | char(10) | NO | | NULL | |

| customer_ID | int | NO | PRI | NULL | |

| customer_Tableno | int | YES | | NULL | | NULL | |

| customer_PHno | int | YES | | NULL | | NULL | |

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

4 rows in set (0.39 sec)

DESCRIBE BILL:-

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

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

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

| Bill_No | int(10) | NO | PRI | NULL | |

| bill_date | date | NO | | NULL | |

| Payment_method | char(20) | NO | | NULL | |

|customer_ID |int | NO | MUL | NULL | |

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

3 rows in set (0.00 sec)


VARIFYING THE DIFFERENT TYPES OF CONSTRAINTS
+------------+------------+------+-----+------------+-----+

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

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

| Fname | char(10) | YES | | NULL | |

| Mname | char(10) | NO | | NULL | |

| Lname | char(10) | NO | | NULL | |

| PHNO | int | NO | | NULL | |

| Age | int | NO | | NULL | |

| DOB | date | NO | | NULL | |

| EMPI_ID | int | NO | PRI | NULL | |

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

7 rows in set (1.61 sec)

PRIMARY KEY CONSTRAINTS

mysql> insert into employee values('vikas','v','Annigeri','781317','17','2006-3-5','104');

Query OK, 1 row affected (0.60 sec)

mysql> insert into employee values('vinayak','v','kala','781344','14','2006-8-8','104');

ERROR 1062 (23000): Duplicate entry '104' for key 'employee.PRIMARY'


FOREIGN KEY CONSTRAINTS

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

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

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

| Bill_No | int | NO | PRI | NULL | |

| Bill_date | date | NO | | NULL | |

| Payment_method | char(20) | NO | | NULL | |

| customer_ID | int | NO | MUL | NULL | |

| customer_PHno | int | NO | | NULL | |

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

5 rows in set (0.00 sec)

mysql> insert into bill3 values('1','1998-09-08','Gpay','12345','6789');

Query OK, 1 row affected (0.50 sec)

mysql> insert into bill3 values('1','1998-09-08','Gpay','45677','6789');

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails
(`oo`.`bill3`, CONSTRAINT `bill3_ibfk_1` FOREIGN KEY (`customer_ID`) REFERENCES
`customer` (`customer_ID`))
UNIQUE KEY CONSTRAINTS

mysql> insert into employe3 values('vinayak','v','kala','781344','14','2006-8-


8','104');

Query OK, 1 row affected (0.18 sec)

mysql> insert into employe values('vinayak','v','kala','34567','14','2006-8-


8','104');

ERROR 1062 (23000): Duplicate entry '104' for key 'employe3.PRIMARY'

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

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

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

| fname | char(10) | NO | | NULL | |

| mname | char(10) | NO | | NULL | |

| lname | char(10) | NO | | NULL | |

| PH_NO | int | NO | UNI | NULL | |

| age | int | NO | | NULL | |

| DOJ | date | YES | | NULL | |

| EMP_ID | int | NO | PRI | NULL | |

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

7 rows in set (0.00 sec)


NOT NULL KEY CONSTRAINTS

mysql> insert into employe values('vinayak','v','kala','781344','14','2006-8-


8','104');

Query OK, 1 row affected (0.18 sec)

mysql> insert into employe values('vinayak','v','781344','14','2006-8-8','104');

ERROR 1136 (21S01): Column count doesn't match value count at row 1

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

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

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

| fname | char(10) | NO | | NULL | |

| mname | char(10) | NO | | NULL | |

| lname | char(10) | NO | | NULL | |

| PH_NO | int | NO | UNI | NULL | |

| age | int | NO | | NULL | |

| DOJ | date | YES | | NULL | |

| EMP_ID | int | NO | PRI | NULL | |

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

7 rows in set (0.00 sec)


DESCRIBE EMPLOYE

DESCRIBE Employe :-
+-------------+-------------+-------+------+----------+---------+

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

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

| Fname | char(10) | YES | | NULL | |

| Mname | char(10) | NO | | NULL | |

| Lname | char(10) | NO | | NULL | |

| PHNO | int | NO | | NULL | |

| Age | int | NO | | NULL | |

| DOJ | date | NO | | NULL | |

| EMPI_ID | int | NO | PRI | NULL | |

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

VALUES ASSIGNED TO TABLE


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

| fname | mname | lname | PH_NO | age | DOJ | EMP_ID |

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

| vinayak | v | kala | 781344 | 14 | 2006-08-08 | 104 |

| vinayak | v | Basava | 743536 | 18 | 2006-03-09 | 105 |

| Adani | u | Gosi | 77983 | 26 | 2000-08-09 | 3432 |

| Mukesh | y | Ambani | 537352 | 20 | 2000-07-09 | 5684 |

| vikas | v | Annigeri | 6789 | 19 | 2006-03-05 | 12345 |

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

5 rows in set (0.00 sec)


DESCRIBE DISH:-
+-----------------+------------+-------+-------+-----------+-----+

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

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

| SI | int(20) | NO | PRI | NULL | |

| Dish_Name | char(20) | NO | | NULL | |

| Price | int(20) | NO | | NULL | |

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

3 rows in set (0.31 sec)

VALUES ASSIGNED TO TABLE

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

| SI | Dish_Name | Price |

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

| 1 | Neer Dosa | 80 |

| 2 | Korri Gassi | 100 |

| 3 | Jolada rotti | 50 |

| 4 | Veg Biryani | 120 |

| 5 | Egg Biryani | 100 |

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

4 rows in set (0.00 sec)


DESCRIBE Customer:-

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

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

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

| customer_Name | char(10) | NO | | NULL | |

| customer_ID | int | NO | PRI | NULL | |

| customer_Tableno | int | YES | | NULL | | NULL | |

| customer_PHno | int | YES | | NULL | | NULL | |

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

4 rows in set (0.39 sec)

VALUES ASSIGNED TO TABLE

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

| customer_Name | customer_ID | customer_Tableno | customer_PHno |

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

| raja | 6789 | 2 | 12345 |

| Akashay | 7460 | 6 | 62623 |

| vikas | 12345 | 1 | 6789 |

| Akash | 67890 | 5 | 23456 |

| Amogh | 225087 | 7 | 23320 |

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

5 rows in set (0.00 sec)


DESCRIBE BILL:-

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

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

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

| Bill_No | int(10) | NO | PRI | NULL | |

| bill_date | date | NO | | NULL | |

| Payment_method | char(20) | NO | | NULL | |

|customer_ID |int | NO | MUL | NULL | |

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

3 rows in set (0.00 sec)

VALUES ASSIGNED TO TABLE


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

| Bill_No | Bill_date | Payment_method | customer_ID | customer_PHno |

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

| 1 | 1998-09-08 | Gpay | 12345 | 6789 |

| 2 | 1999-09-08 | Gpay | 7460 | 6789 |

| 3 | 2023-09-08 | Gpay | 67890 | 23456 |

| 4 | 2023-05-09 | Fanpay | 225087 | 23320 |

| 5 | 2023-05-09 | Fanpay | 6789 | 12345 |

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

5 rows in set (0.00 sec)

You might also like