ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions
3 marks · Creating and dropping tables
Developers are creating a database to store details of treatments provided at a hospital. The Doctor table of the database contains four required attributes: doctorID, firstName, lastName and contractType. All doctors at the hospital are issued contracts that can be Consultant, Junior or Locum. The developers use the SQL CREATE statement below to create the Doctor table. Line 1 CREATE TABLE Doctor ( Line 2 doctorID int NOT NULL AUTO-INCREMENT, Line 3 firstName varchar NOT NULL, Line 4 lastName varchar, Line 5 contractType Line 6 ); The SQL statement above is not fit for purpose. Re‑write the SQL statement to implement the Doctor table correctly.
Corrections required to Lines 3, 4 and 5. For example: Line 3: firstName VARCHAR (25) Line 4: lastName VARCHAR (40) Line 5: contractType VARCHAR(10) Missing Lines: PRIMARY KEY (doctorID) CHECK contractType IN ('Consultant', 'Junior', 'Locum') 1 mark each of the following: • Stating a valid size of VARCHAR in Lines 3, 4 and 5 • Stating primary key of the table • Restricting values stored in contractType Notes: Accept any reasonable size for VARCHAR in Lines 3, 4 and 5 Don’t penalise for use of NULL