How can I made this SQL code work on Maria_DB?
--creating the data base
create database databaseproject
use databaseproject;
--DROPING the data bases if its not existed
DROP TABLE Doctor CASCADE CONSTRAINTS PURGE;
DROP TABLE patient CASCADE CONSTRAINTS PURGE;
DROP TABLE tests CASCADE CONSTRAINTS PURGE;
DROP TABLE appointments CASCADE CONSTRAINTS PURGE;
DROP TABLE labortory CASCADE CONSTRAINTS PURGE;
DROP TABLE medicines CASCADE CONSTRAINTS PURGE;
DROP TABLE bill CASCADE CONSTRAINTS PURGE;
DROP view disp
DROP view display2
-- creating the doctor table with the doctor _id as a primary key
create table doctor(
doctor_id int primary key IDENTITY(1,1) not null,
name varchar(15),
specilization varchar(15),
phone varchar(10),
gender varchar(10)
);
-- creating the patient table with the patient_id as a primary key
create table patient(
patient_id int primary key IDENTITY(1,1) not null,
name varchar(15),
age int,
gender varchar(10),
weight int,
cinic varchar(10)
);
-- creating the apointment table with the id int as a primary key
create table appointments(
id int primary key IDENTITY(1,1) not null,
patient_id int foreign key references patient(patient_id),
doctor_id int foreign key references doctor(doctor_id)
);
-- creating the tests table with the test_id as a primary key
create table tests(
test_id int primary key IDENTITY(1,1) not null,
name varchar(10),
duration varchar(10),
patient_id int foreign key references patient(patient_id),
doctor_id int foreign key references doctor(doctor_id)
);
-- creating the labortory table with the id int as a primary key
create table labortory(
id int primary key IDENTITY(1,1) not null,
name varchar(10),
timing varchar(15)
);
-- creating the mediciones table with the medicines_id as a primary key
create table medicines(
medicine_id int primary key IDENTITY(1,1) not null,
medicine_name varchar(10),
prescription varchar(10),
patient_id int foreign key references patient(patient_id),
doctor_id int foreign key references doctor(doctor_id)
);
-- creating the bill table with the bill_id as a primary key
create table bill(
bill_id int primary key IDENTITY(1,1) not null,
patient_id int foreign key references patient(patient_id),
doctor_id int foreign key references doctor(doctor_id),
bill_date datetime
);
--ADDING total in bill using alter
alter table bill
add total int
--Inserting a value In doctor,patient,medicines,bill
insert into doctor values('ibn alhajam','cardiologist','+931122','MALE')
insert into patient values('ali',20,'M',50,'34501699')
insert into medicines values('leflox','2 a day',3,2)
insert into bill values(3,3,'6-12-2020',5000)
--Displaying values from doctor,patient,medicines,bill
select * from doctor
select * from patient
select * from medicines
select * from bill
--Displaying values from doctor where name is ALI
select * from patient where name='ali'
--counting total number of patients
select count(patient_id) from patient
--Displaying values from doctor where name ends in a
select * from doctor where name like '%a'
--Displaying values of patient along with their medicines
select m.medicine_name,m.prescription from patient p
join medicines m on m.patient_id=p.patient_id
where p.name='ali'
--Displaying values of patient along with their medicines and total bill
select m.medicine_name,m.prescription,b.total,p.name from patient p
join medicines m on m.patient_id=p.patient_id
join bill b on b.patient_id=p.patient_id
where p.name='ali'
--CreatING Views
CREATE VIEW disp AS
select m.medicine_name,m.prescription from patient p
join medicines m on m.patient_id=p.patient_id
where p.name='ali'
create view display2 as
select m.medicine_name,m.prescription,b.total,p.name from patient p
join medicines m on m.patient_id=p.patient_id
join bill b on b.patient_id=p.patient_id
where p.name='ali'
--CREATNG ROLES FOR THE VIEWS
CREATE ROLE admin1;
GRANT create table, create view
TO admin1;
create role admin2
grant alter
to admin2