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() 

MySQL online editor

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.

About MySQL

MySQL is a open-source, free and very popular relational database management system which is developed, distributed and supported by Oracle corporation.

Key Features:

  • Open-source relational database management systems.
  • Reliable, very fast and easy to use database server.
  • Works on client-server model.
  • Highly Secure and Scalable
  • High Performance
  • High productivity as it uses stored procedures, triggers, views to write a highly productive code.
  • Supports large databases efficiently.
  • Supports many operating systems like Linux*,CentOS*, Solaris*,Ubuntu*,Windows*, MacOS*,FreeBSD* and others.

Syntax help

Commands

1. CREATE

CREATE TABLE table_name (
                column1 datatype,
                column2 datatype,
                ....);

Example

CREATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL
);

2. ALTER

ALTER TABLE Table_name ADD column_name datatype;

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');

3. TRUNCATE

TRUNCATE table table_name;

4. DROP

DROP TABLE table_name;

5. RENAME

RENAME TABLE table_name1 to new_table_name1; 

6. COMMENT

Single-Line Comments:

 --Line1;

Multi-Line comments:

   /* Line1,
   Line2 */

DML Commands

1. INSERT

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

Note: Column names are optional.

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');

2. SELECT

SELECT column1, column2, ...
FROM table_name
[where condition]; 

Example

SELECT * FROM EMPLOYEE where dept ='sales';

3. UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; 

Example

UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001'; 

4. DELETE

DELETE FROM table_name where condition;

Example

DELETE from EMPLOYEE where empId='0001'; 

Indexes

1. CREATE INDEX

  CREATE INDEX index_name on table_name(column_name);
  • To Create Unique index:
  CREATE UNIQUE INDEX index_name on table_name(column_name);

2. DROP INDEX

DROP INDEX index_name ON table_name;

Views

1. Create a View

Creating a View:
CREATE VIEW View_name AS 
Query;

2. How to call view

SELECT * FROM View_name;

3. Altering a View

ALTER View View_name AS 
Query;

4. Deleting a View

DROP VIEW View_name;

Triggers

1. Create a Trigger

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 } */

2. Drop a Trigger

DROP TRIGGER [IF EXISTS] trigger_name;

Stored Procedures

1. Create a Stored Procedure

CREATE PROCEDURE sp_name(p1 datatype)
BEGIN
/*Stored procedure code*/
END;

2. How to call Stored procedure

CALL sp_name;

3. How to delete stored procedure

DROP PROCEDURE sp_name;

Joins

1. INNER JOIN

SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;

2. LEFT JOIN

SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;

3. RIGHT JOIN

SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;

4. CROSS JOIN

SELECT select_list from TABLE1 CROSS JOIN TABLE2;