import mysql.connector as sql conn=sql.connect(host='localhost',user='root',password='manager',database='medical_store') if conn.is_connected: print('successfully connected') c1=conn.cursor() c1.execute('create table account_details(User_Name varchar(30)primary key,password varchar(30) unique)') c1.execute('create table customers_details(account_number int primary key,patient_name varchar(30),age int,address varchar(50),phone_number bigint(11),balance_amount float)') c1.execute('create table medicines_details(medicine_name varchar(30),medicine_code int,gst float,sgst float,total_cost float)') c1.execute('create table SS_bill(medicine_name varchar(30),medicine_code int ,gst float,sgst float,cost_per_item float,quantity int,discount_on_balance_amount float,total_amount float)') print('table created') import sys import mysql.connector as sql conn=sql.connect(host='localhost',user='root',password='manager',database='medical_store') c1=conn.cursor() from time import gmtime, strftime a=strftime("%a ,%d %b %y %H:%M:%S",gmtime()) if conn.is_connected: print("WELCOME TO SS MEDICAL STORE") print(a) print("1. Login") print("2. Exit") print() option=int(input("Enter your choise : ")) if option==1: print() user=input('User Name : ') user=user.upper() c1.execute("select * from account_details where User_Name like '" + user + "'") datas=c1.fetchall() for i in datas: value_1=i[0] value_2=i[1] if user==value_1: password=input('Password : ') password=password.upper() if password==value_2: print() print('Login successfull') print() print("11.Customers Account") print("12.Medicine Cost") print("3.Bill") print() option=int(input("enter a option:")) if option==11: account_number=int(input("enter your acct_number:")) patient_name=input("enter your name:") age=int(input("enter your age:")) address=input("enter your address:") phone_number=int(input("enter your number:")) balance_amount=float(input("enter your amount:")) x="insert into customers_details values("+str(account_number)+",'"+patient_name+"',"+str(age)+",'"+address+"',"+str(phone_number)+","+str(balance_amount)+")" print(x) c1.execute(x) print("Account created congrats") conn.commit() import mysql.connector as sql conn=sql.connect(host='localhost',user='root',password='manager',database='medical_store') c1=conn.cursor() choice=int(input("enter your choice:")) if choice==2: c1.execute("insert into medicines_details values('paracetamal 250mg',325674,1.5,1,5)") c1.execute("insert into medicines_details values('amoxylin',647890,1,1,4)") c1.execute("insert into medicines_details values('zinc sulphide',546783,1.5,0.5,3.5)") c1.execute("insert into medicines_details values('polodb 500mg',568903,3,2.5,10)") c1.execute("insert into medicines_details values('paracetamal 500mg',325679,2,1.5,6)") c1.execute("insert into medicines_details values('vicks action 500',250348,1,0.5,5)") c1.execute("insert into medicines_details values('dolo 500mg',789541,3,2.5,10)") c1.execute("insert into medicines_details values('ferric sulphide',546784,1.5,0.5,3.5)") print("Records Created") conn.commit() if option==3: print(a) patient_name=input("enter the patient_name :") no=int(input('enter the number of medicine:')) print('customer name:',patient_name) for i in range (no): med_name=input('enter medicine name : ') m=c1.execute("select medicine_code,gst,sgst,total_cost from medicines_details where medicine_name like '" + str(med_name) +"'" ) data=c1.fetchall() for row in data: print('medicine_code of',med_name,':',row[0]) print('gst of',med_name,':',row[1]) print('sgst of',med_name,':',row[2]) print('cost_per_item of',med_name,':',row[3]) conn.commit() account_number=input('enter account_number:') c1.execute("select balance_amount from customers_details where account_number like'"+str(account_number)+"'") datas=c1.fetchall() datas=list(datas[0]) datas=datas[0] print(datas) conn.commit() print("rows affected:",c1.rowcount) conn.commit() quantity=int(input("enter the quantity:")) total_amount=row[3]*quantity print("total_amount of",med_name,':',total_amount) v_sql_insert="insert into SS_bill (medicine_name,medicine_code,gst,sgst,cost_per_item,quantity,discount_on_balance_amount,total_amount)values('{}',{},{},{},{},{},{},{})".format(med_name,row[0],row[1],row[2],row[3],quantity,datas,total_amount) print(v_sql_insert) c1.execute(v_sql_insert) conn.commit() print("Records added") else: print('Invalid Password') print('Tryagain') elif option==2: print(" THANK YOU ") sys.exit()
Write, Run & Share MySQL queries online using OneCompiler's MySQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for MySQL. Getting started with the OneCompiler's MySQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'MySQL' and start writing queries to learn and test online without worrying about tedious process of installation.
MySQL is a open-source, free and very popular relational database management system which is developed, distributed and supported by Oracle corporation.
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
....);
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept TEXT NOT NULL
);
ALTER TABLE Table_name ADD column_name datatype;
INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');
TRUNCATE table table_name;
DROP TABLE table_name;
RENAME TABLE table_name1 to new_table_name1;
--Line1;
/* Line1,
Line2 */
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Note: Column names are optional.
INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');
SELECT column1, column2, ...
FROM table_name
[where condition];
SELECT * FROM EMPLOYEE where dept ='sales';
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001';
DELETE FROM table_name where condition;
DELETE from EMPLOYEE where empId='0001';
CREATE INDEX index_name on table_name(column_name);
CREATE UNIQUE INDEX index_name on table_name(column_name);
DROP INDEX index_name ON table_name;
Creating a View:
CREATE VIEW View_name AS
Query;
SELECT * FROM View_name;
ALTER View View_name AS
Query;
DROP VIEW View_name;
CREATE TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW [trigger_order] trigger_body
/* where
trigger_time: { BEFORE | AFTER }
trigger_event: { INSERT | UPDATE | DELETE }
trigger_order: { FOLLOWS | PRECEDES } */
DROP TRIGGER [IF EXISTS] trigger_name;
CREATE PROCEDURE sp_name(p1 datatype)
BEGIN
/*Stored procedure code*/
END;
CALL sp_name;
DROP PROCEDURE sp_name;
SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;
SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;
SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;
SELECT select_list from TABLE1 CROSS JOIN TABLE2;