Resturent Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

mysql> create database Restaurant VIKAS;

Query OK, 1 row affected (0.10 sec)

mysql> use Restaurant VIKAS;


Database changed

mysql> create table Employee(


-> Fname char(20)NOT NULL,
-> Minit char(20)NOT NULL,
-> Lname char(20)NOT NULL,
-> Emp_id int(20)NOT NULL,
-> Gender char(10) DEFAULT'M',
-> Address varchar(30)UNIQUE,
-> primary key(Emp_id));
Query OK, 0 rows affected, 1 warning (0.91 sec)

mysql> desc Employee;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Fname | char(20) | NO | | NULL | |
| Minit | char(20) | NO | | NULL | |
| Lname | char(20) | NO | | NULL | |
| Emp_id | int | NO | PRI | NULL | |
| Gender | char(10) | YES | | M | |
| Address | varchar(30) | YES | UNI | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> create table Dish(


-> Dish_id int(20),
-> Dish_name char(20),
-> Dish_price int(20),
-> Emp_id int(20),
-> primary key(Dish_id),
-> foreign key(Emp_id)references employee(Emp_id));
Query OK, 0 rows affected, 3 warnings (0.40 sec)

mysql> desc Dish;


+------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| Dish_id | int | NO | PRI | NULL | |
| Dish_name | char(20) | YES | | NULL | |
| Dish_price | int | YES | | NULL | |
| Emp_id | int | YES | MUL | NULL | |
+------------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> create table Customer(


-> Customer_Name char(20),
-> Phone_Number int(20),
-> Customer_ID varchar(20),
-> Address varchar(30),
-> primary key(Customer_ID));
Query OK, 0 rows affected, 1 warning (0.21 sec)
mysql> desc Customer;

+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Customer_Name | char(20) | YES | | NULL | |
| Phone_Number | int | YES | | NULL | |
| Customer_ID | varchar(20) | NO | PRI | NULL | |
| Address | varchar(30) | YES | | NULL | |
| Total_Amount | int | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> desc Employee;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Fname | char(20) | NO | | NULL | |
| Minit | char(20) | NO | | NULL | |
| Lname | char(20) | NO | | NULL | |
| Emp_id | int | NO | PRI | NULL | |
| Gender | char(10) | YES | | M | |
| Address | varchar(30) | YES | UNI | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> desc Dish;


+------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| Dish_id | int | NO | PRI | NULL | |
| Dish_name | char(20) | YES | | NULL | |
| Dish_price | int | YES | | NULL | |
| Emp_id | int | YES | MUL | NULL | |
+------------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> desc Customer;

+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Customer_Name | char(20) | YES | | NULL | |
| Phone_Number | int | YES | | NULL | |
| Customer_ID | varchar(20) | NO | PRI | NULL | |
| Address | varchar(30) | YES | | NULL | |
| Total_Amount | int | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
EMPLOYEE
mysql> insert into Employee
values('Vinayak','v','Kala','781344','M','731 FondrenHouston');
Query OK, 1 row affected (0.34 sec)

mysql> insert into Employee


values('Vinayak','v','Basava','743536','M','638VossHouston');
Query OK, 1 row affected (0.08 sec)

mysql> insert into Employee


values('Adani','U','Gosi','77983','M','3321CastileSpring');
Query OK, 1 row affected (0.06 sec)

M
ysql> insert into Employee
values('Mukesh','A','Ambani','537352','M','291BerryBellaire');
Query OK, 1 row affected (0.20 sec)

mysql> insert into Employee


values('Harshad','R','Metha','1992','M','293Dehli');
Query OK, 1 row affected (0.06 sec)des

mysql> select * from Employee;


+---------+-------+--------+--------+--------+--------------------+
| Fname | Minit | Lname | Emp_id | Gender | Address |
+---------+-------+--------+--------+--------+--------------------+
| Harshad | R | Metha | 1992 | M | 293Dehli |
| Adani | U | Gosi | 77983 | M | 3321CastileSpring |
| Mukesh | A | Ambani | 537352 | M | 291BerryBellaire |
| Vinayak | v | Basava | 743536 | M | 638VossHouston |
| Vinayak | v | Kala | 781344 | M | 731 FondrenHouston |
+---------+-------+--------+--------+--------+--------------------+
5 rows in set (0.05 sec)

DISH
mysql> insert into Dish values('1','Neer Dosa','80','1992');
Query OK, 1 row affected (0.15 sec)

mysql> insert into Dish values('2','Korri Gassi','100','1992');


Query OK, 1 row affected (0.07 sec)

mysql> insert into Dish values('3','Jolada Rotti','60','77983');


Query OK, 1 row affected (0.06 sec)

mysql> insert into Dish values('4','Veg Biryani','120','537352');


Query OK, 1 row affected (0.14 sec)

mysql> insert into Dish values('5','Egg Biryani','150','537352');


Query OK, 1 row affected (0.08 sec)
mysql> select * from Dish;
+---------+--------------+------------+--------+
| Dish_id | Dish_name | Dish_price | Emp_id |
+---------+--------------+------------+--------+
| 1 | Neer Dosa | 80 | 1992 |
| 2 | Korri Gassi | 100 | 1992 |
| 3 | Jolada Rotti | 60 | 77983 |
| 4 | Veg Biryani | 120 | 537352 |
| 5 | Egg Biryani | 150 | 537352 |
+---------+--------------+------------+--------+
5 rows in set (0.00 sec)

CUSTOMER

mysql> insert into Customer values('Vijay


Devarakonda','000001','VIP@001','USA','1000');
Query OK, 1 row affected (0.09 sec)

mysql> insert into Customer values('Rajinikanth


Ka','73781','MIP@145','USA','200');
Query OK, 1 row affected (0.07 sec)

mysql> insert into Customer values('Kabir


Singh','523428','MIP@877','USA','330');
Query OK, 1 row affected (0.08 sec)

mysql> insert into Customer values('Allu


Arjun','82321','MIP@897','USA','1200');
Query OK, 1 row affected (0.07 sec)

mysql> insert into Customer values('Sudeep


K','622476','TAM@123','USA','350');
Query OK, 1 row affected (0.08 sec)

+-------------------+--------------+-------------+---------+--------------+
| Customer_Name | Phone_Number | Customer_ID | Address | Total_Amount |
+-------------------+--------------+-------------+---------+--------------+
| Vijay Devarakonda | 00001 | VIP@001 | USA | 1000 |
| Rajinikanth Ka | 73781 | MIP@145 | USA | 200 |
| Kabir Singh | 523428 | MIP@877 | USA | 330 |
| Allu Arjun | 82321 | MIP@897 | USA | 1200 |
| Sudeep K | 622476 | TAM@123 | USA | 350 |
+-------------------+--------------+-------------+---------+--------------+
5 rows in set (0.00 sec)
ALTER COMMAND
mysql> desc Customer;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Customer_Name | char(20) | YES | | NULL | |
| Phone_Number | int | YES | | NULL | |
| Customer_ID | varchar(20) | NO | PRI | NULL | |
| Address | varchar(30) | YES | | NULL | |
| Total_Amount | int | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

AFTER

mysql> ALTER TABLE Customer


-> add Supplier_ID int(30);
Query OK, 0 rows affected, 1 warning (0.35 sec)
Records: 0 Duplicates: 0 Warnings: 1

mysql> desc Customer;


+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Customer_Name | char(20) | YES | | NULL | |
| Phone_Number | int | YES | | NULL | |
| Customer_ID | varchar(20) | NO | PRI | NULL | |
| Address | varchar(30) | YES | | NULL | |
| Total_Amount | int | YES | | NULL | |
| Supplier_ID | int | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

UPDATE COMMAND

mysql> desc Employee;


+---------+-------+--------+--------+--------+--------------------+
| Fname | Minit | Lname | Emp_id | Gender | Address |
+---------+-------+--------+--------+--------+--------------------+
| Harshad | R | Metha | 1992 | M | 293Dehli |
| Adani | U | Gosi | 77983 | M | 3321CastileSpring |
| Mukesh | A | Ambani | 537352 | M | 291BerryBellaire |
| Vinayak | v | Basava | 743536 | M | 638VossHouston |
| Vinayak | v | Kala | 781344 | M | 731 FondrenHouston |
+---------+-------+--------+--------+--------+--------------------+
5 rows in set (0.05 sec)

AFTER

mysql> UPDATE Employee


-> set Fname='Nita'
-> where Emp_id='743536';
Query OK, 1 row affected (0.20 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> UPDATE Employee
-> set Gender='F'
-> where Emp_id='743536';
Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from employee;


+---------+-------+--------+--------+--------+--------------------+
| Fname | Minit | Lname | Emp_id | Gender | Address |
+---------+-------+--------+--------+--------+--------------------+
| Harshad | R | Metha | 1992 | M | 293Dehli |
| Adani | U | Gosi | 77983 | M | 3321CastileSpring |
| Mukesh | A | Ambani | 537352 | M | 291BerryBellaire |
| Nita | v | Basava | 743536 | F | 638VossHouston |
| Vinayak | v | Kala | 781344 | M | 731 FondrenHouston |
+---------+-------+--------+--------+--------+--------------------+
5 rows in set (0.00 sec)

DELETE COMMAND

mysql> select * from Employee;


+---------+-------+--------+--------+--------+--------------------+
| Fname | Minit | Lname | Emp_id | Gender | Address |
+---------+-------+--------+--------+--------+--------------------+
| Harshad | R | Metha | 1992 | M | 293Dehli |
| Adani | U | Gosi | 77983 | M | 3321CastileSpring |
| Mukesh | A | Ambani | 537352 | M | 291BerryBellaire |
| Nita | v | Basava | 743536 | F | 638VossHouston |
| Vinayak | v | Kala | 781344 | M | 731 FondrenHouston |
+---------+-------+--------+--------+--------+--------------------+
5 rows in set (0.00 sec)

AFTER

mysql> DELETE from Employee


-> where Lname='Kala';
Query OK, 1 row affected (0.09 sec)

mysql> select * from Employee;


+---------+-------+--------+--------+--------+-------------------+
| Fname | Minit | Lname | Emp_id | Gender | Address |
+---------+-------+--------+--------+--------+-------------------+
| Harshad | R | Metha | 1992 | M | 293Dehli |
| Adani | U | Gosi | 77983 | M | 3321CastileSpring |
| Mukesh | A | Ambani | 537352 | M | 291BerryBellaire |
| Nita | v | Basava | 743536 | F | 638VossHouston |
+---------+-------+--------+--------+--------+-------------------+
4 rows in set (0.00 sec)
DROP COMMAND
+---------+-------+--------+--------+--------+-------------------+
| Fname | Minit | Lname | Emp_id | Gender | Address |
+---------+-------+--------+--------+--------+-------------------+
| Harshad | R | Metha | 1992 | M | 293Dehli |
| Adani | U | Gosi | 77983 | M | 3321CastileSpring |
| Mukesh | A | Ambani | 537352 | M | 291BerryBellaire |
| Nita | v | Basava | 743536 | F | 638VossHouston |
+---------+-------+--------+--------+--------+-------------------+
4 rows in set (0.00 sec)

mysql>DROP table Employee;


Query OK, 1 row affected (0.30sec)
mysql>select * from Employee;
ERROR 1146 (42s02): Table ‘Restaurant .employee’ doesn’t exist

DROP DATABASE
mysql> DROP database Restaurant ;
Query OK, 3 rows affected (2.46 sec)
PRIMARY KEY CONSTRAINT
mysql> desc Employee;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Fname | char(20) | YES | | NULL | |
| Minit | char(20) | YES | | NULL | |
| Lname | char(20) | YES | | NULL | |
| Emp_id | int | NO | PRI | NULL | |
| Gender | char(3) | YES | | NULL | |
| Address | varchar(30) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.55 sec)

mysql> insert into Employee


values('Harshad','R','Metha','1992','M','293Dehli');
Query OK, 1 row affected (0.06 sec)des

mysql> insert into Employee


values('Harshad','R','Metha','1992','M','293Dehli');
ERROR 1062 (23000): Duplicate entry '1992' for key 'Employee.PRIMARY'

FOREIGN KEY CONSTRAINT


mysql> desc Dish;
+------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| Dish_id | int | NO | PRI | NULL | |
| Dish_name | char(20) | YES | | NULL | |
| Dish_price | int | YES | | NULL | |
| Emp_id | int | YES | MUL | NULL | |
+------------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql>insert into Dish values('1','Neer Dosa','80','1992');


Query OK, 1 row affected (0.09 sec)

mysql> insert into Dish values('6','Neer Dosa','80','68785');


ERROR 1452 (23000):Cannot add or update a child row:a foreign key
constraint fails
(`Restaurant VIKAS `.`Dish`,CONSTRAINT`Dish_ibfk_1`FOREIGN
KEY(`Emp_id`)REFERENCES`Employee`(`Emp_id`))
NOT NULL KEY CONSTRAINT
mysql> desc Employee;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Fname | char(20) | NO | | NULL | |
| Minit | char(20) | NO | | NULL | |
| Lname | char(20) | NO | | NULL | |
| Emp_id | int | NO | PRI | NULL | |
| Gender | char(10) | YES | | M | |
| Address | varchar(30) | YES | UNI | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> insert into Employee


values('Mukesh','A','Ambani','537352','M','291BerryBellaire');

mysql> insert into Employee(Fname,Minit) values('Mukesh',’A');


ERROR 1364 (HY000): Field 'Lname’ doesn't have a default value

DEFAULT KEY CONSTRAINT


mysql> desc Employee;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Fname | char(20) | NO | | NULL | |
| Minit | char(20) | NO | | NULL | |
| Lname | char(20) | NO | | NULL | |
| Emp_id | int | NO | PRI | NULL | |
| Gender | char(10) | YES | | M | |
| Address | varchar(30) | YES | UNI | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> insert into Employee(Fname,Minit,Lname,Emp_id,Address)


values('Mukesh','A','Ambani','537352','291BerryBellaire');
Query OK, 1 row affected (0.12 sec)
UNIQUE KEY CONSTRAINT
mysql> desc Employee;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Fname | char(20) | NO | | NULL | |
| Minit | char(20) | NO | | NULL | |
| Lname | char(20) | NO | | NULL | |
| Emp_id | int | NO | PRI | NULL | |
| Gender | char(10) | YES | | M | |
| Address | varchar(30) | YES | UNI | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> insert into Employee


values('Mukesh','A','AmbANI','552','M','29BerryBellaire');
Query OK, 1 row affected (0.07 sec)

mysql> insert into Employee


values('MukeSh','A','Ambani','5763','M','291BerryBellaire');
ERROR 1062 (23000): Duplicate entry '291BerryBellaire' for key
'Employee.Address'

CHECK KEY CONSTRAINT


mysql> desc Customer;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Customer_Name | char(20) | YES | | NULL | |
| Phone_Number | int | YES | | NULL | |
| Customer_ID | varchar(20) | NO | PRI | NULL | |
| Address | varchar(30) | YES | | NULL | |
| Total_Amount | int | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> insert into Customer values('Vijay


Devarakonda','000001','VIP@001','USA','888');
Query OK, 1 row affected (0.04 sec)

mysql> insert into Customer values('Vijay


Devarakonda','000001','VIP@001','USA','1020');
ERROR 3819 (HY000): Check constraint 'customer_chk_1' is violated.
SCHEAM

Employee
Fname Minit Lname Emp_id Gender Address

Dish
Dish_id Dish_name Dish_pice Emp_id

Customer
Customer_Name Phone_Number Customer_ID Address
DATABASE FOR RESTAURANT

mysql> create database Restaurant VIKAS;

Query OK, 1 row affected (0.18 sec)

mysql> use Restaurant VIKAS;

Database changed

You might also like