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

Oracle 12c: SQL
3rd Edition
ISBN:9781305251038
Author:Joan Casteel
Publisher:Joan Casteel
Chapter13: Views
Section: Chapter Questions
Problem 3MC
icon
Related questions
Question
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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
SQL Query
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781285196145
Author:
Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:
Cengage Learning
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781305627482
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning