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
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
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images
Knowledge Booster
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.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education