I have run those SQL in “DB Fiddle” and “Programiz Online SQL Editor” I keep getting ERROR in both GRANT and CREATE ROLE
why?
How to make it work?
CREATE TABLE Patients (
PatientID INT PRIMARY KEY,
Name VARCHAR(100),
ContactDetails VARCHAR(100),
MedicalHistory TEXT
);
CREATE TABLE Appointments (
AppointmentID INT PRIMARY KEY,
PatientID INT,
StaffID INT,
AppointmentDate DATETIME,
Details TEXT,
FOREIGN KEY (PatientID) REFERENCES Patients(PatientID)
);
— Insert statements for Patients
INSERT INTO Patients (PatientID, Name, ContactDetails, MedicalHistory) VALUES
(101, ‘John Doe’, ‘123-456-7890’, ‘None’),
(102, ‘Jane Smith’, ‘987-654-3210’, ‘Diabetes’),
(103, ‘Alice Johnson’, ‘555-123-4567’, ‘Hypertension’),
(104, ‘Bob Brown’, ‘444-555-6666’, ‘Asthma’);
— Insert statements for Appointments
INSERT INTO Appointments (AppointmentID, PatientID, StaffID, AppointmentDate, Details) VALUES
(2001, 101, 501, ‘2024-07-01 09:00:00’, ‘Regular Check-up’),
(2002, 102, 502, ‘2024-07-02 10:00:00’, ‘Follow-up Visit’),
(2003, 103, 501, ‘2024-07-03 11:00:00’, ‘Consultation’),
(2004, 104, 503, ‘2024-07-04 12:00:00’, ‘Vaccination’);
select * from Patients;
select * from Appointments;
— Creating the MedicalStaff role
CREATE ROLE MedicalStaff;
— Granting SELECT permission on the Patients table to the MedicalStaff role
GRANT SELECT ON Patients TO MedicalStaff;
— Creating the AdministrativeStaff role
CREATE ROLE AdministrativeStaff;
— Granting SELECT, INSERT, and UPDATE permissions on the Appointments table to the AdministrativeStaff role
GRANT SELECT, INSERT, UPDATE ON Appointments TO AdministrativeStaff;
select * from Patients;
select * from Appointments;
U_Kno_A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.