Skip to content

Commit 5aef645

Browse files
Update Creating_Database(Room_Managment_system.py
1 parent 52f5e35 commit 5aef645

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

Creating Database(Room_Managment_system.py

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,74 @@
11
import mysql.connector as sql
2-
con=sql.connect(host='localhost', user='root', passwd='Your Password')
3-
b=con.cursor()
2+
con=sql.connect(host='localhost', user=input("Enter your account name:"), passwd=input('Enter your password:'), auth_plugin='mysql_native_password')
3+
cursor_var=con.cursor()
44

5-
def creation():
6-
c='CREATE DATABASE ROOM_MANAGEMENT_SYSTEM'
7-
b.execute(c)
5+
def database_creation():
6+
"""
7+
Creating database using and tables (CHECK_IN and CHECK_OUT).
8+
"""
9+
create='CREATE DATABASE ROOM_MANAGEMENT_SYSTEM'
10+
cursor_var.execute(create)
811
print("DATABASE CREATED SUCCESSFULLY!!!")
9-
d='USE ROOM_MANAGEMENT_SYSTEM'
10-
b.execute(d)
11-
e='CREATE TABLE CHECK_IN(ROOM_TYPE VARCHAR(20), NO_OF_DAYS INT, NAME VARCHAR(20), AADHAAR_CARD_NO VARCHAR(12), MOBILE_NO VARCHAR(13), DATE VARCHAR(20), ROOM_NO INT)'
12-
b.execute(e)
12+
13+
use='USE ROOM_MANAGEMENT_SYSTEM'
14+
cursor_var.execute(use)
15+
create_checkin='CREATE TABLE CHECK_IN(ROOM_TYPE VARCHAR(20), NO_OF_DAYS INT, NAME VARCHAR(20), AADHAAR_CARD_NO VARCHAR(12), MOBILE_NO VARCHAR(13), DATE VARCHAR(20), ROOM_NO INT)'
16+
cursor_var.execute(create_checkin)
1317
print("CHECK_IN TABLE CREATED SUCCESSFULLY!!!")
14-
f='CREATE TABLE CHECK_OUT(ROOM_TYPE VARCHAR(30), ROOM_NO INT, NAME VARCHAR(20), MOBILE_NO VARCHAR(13), AADHAAR_CARD_NO VARCHAR(12), NO_OF_DAYS INT, TOTAL_BILL FLOAT, DATE_OF_BILLING VARCHAR(20))'
15-
b.execute(f)
18+
19+
create_checkout='CREATE TABLE CHECK_OUT(ROOM_TYPE VARCHAR(30), ROOM_NO INT, NAME VARCHAR(20), MOBILE_NO VARCHAR(13), AADHAAR_CARD_NO VARCHAR(12), NO_OF_DAYS INT, TOTAL_BILL FLOAT, DATE_OF_BILLING VARCHAR(20))'
20+
cursor_var.execute(create_checkout)
1621
print("CHECK_OUT TABLE CREATED SUCCESSFULLY!!!")
22+
1723
con.commit()
1824
main()
1925

20-
def deletion():
21-
k='DROP DATABASE ROOM_MANAGEMENT_SYSTEM'
22-
b.execute(k)
23-
print("DATABASE deleted successfully!!!")
26+
def database_deletion():
27+
28+
"""
29+
Deleting database.
30+
"""
31+
print(" ")
32+
print("Press 1 for to delete entire database.")
33+
print("Press 2 to delete tables in database.")
34+
print(" ")
35+
36+
user_choice=int(input("Enter your choice:"))
37+
if user_choice==1:
38+
drop_database='DROP DATABASE ROOM_MANAGEMENT_SYSTEM'
39+
cursor_var.execute(drop_database)
40+
print("DATABASE deleted successfully!!!")
41+
42+
elif user_choice == 2:
43+
print(" ")
44+
print("Press 1 to delete both tables.")
45+
print("Press 2 to delete CHECK_IN table only.")
46+
print("Press 3 to delete CHECK_OUT table only.")
47+
print(" ")
48+
user_choice_table = int(input("Enter your choice:"))
49+
50+
if user_choice_table == 1:
51+
cursor_var.execute("DROP TABLE IF EXISTS CHECK_IN")
52+
cursor_var.execute("DROP TABLE IF EXISTS CHECK_OUT")
53+
print("Both tables deleted successfully")
54+
elif user_choice_table == 2:
55+
cursor_var.execute("DROP TABLE IF EXISTS CHECK_IN")
56+
print("CHECK_IN table deleted successfully")
57+
elif user_choice_table == 3:
58+
cursor_var.execute("DROP TABLE IF EXISTS CHECK_OUT")
59+
print("CHECK_OUT table deleted successfully")
60+
2461
con.commit()
2562
main()
2663

2764
def main():
2865
print("Enter 1 to create database 'ROOM_MANAGEMENT_SYSTEM'")
29-
print("Enter 2 to drop database 'ROOM_MANAGEMENT_SYSTEM'")
30-
a=int(input("Enter your choice:"))
31-
if a==1:
32-
creation()
33-
elif a==2:
34-
deletion()
66+
print("Enter 2 to drop database/table from 'ROOM_MANAGEMENT_SYSTEM'")
67+
user_choice=int(input("Enter your choice:"))
68+
if user_choice==1:
69+
database_creation()
70+
elif user_choice==2:
71+
database_deletion()
3572
else:
3673
print("Wrong input...")
3774
main()

0 commit comments

Comments
 (0)