spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
What are the titles and studios of films that have been produced by a studio whose name contains "Universal"?
SELECT title , Studio FROM film WHERE Studio LIKE "%Universal%"
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
Show the studios that have not produced films with director "Walter Hill".
SELECT Studio FROM film EXCEPT SELECT Studio FROM film WHERE Director = "Walter Hill"
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
Which studios have never worked with the director Walter Hill?
SELECT Studio FROM film EXCEPT SELECT Studio FROM film WHERE Director = "Walter Hill"
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
List the studios which average gross is above 4500000.
SELECT Studio FROM film GROUP BY Studio HAVING avg(Gross_in_dollar) >= 4500000
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
Which studios have an average gross of over 4500000?
SELECT Studio FROM film GROUP BY Studio HAVING avg(Gross_in_dollar) >= 4500000
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
What is the title of the film that has the highest high market estimation.
SELECT t1.title FROM film AS T1 JOIN film_market_estimation AS T2 ON T1.Film_ID = T2.Film_ID ORDER BY high_estimate DESC LIMIT 1
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
Return the title of the film with the highest high estimate?
SELECT t1.title FROM film AS T1 JOIN film_market_estimation AS T2 ON T1.Film_ID = T2.Film_ID ORDER BY high_estimate DESC LIMIT 1
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
What are the titles and directors of the films were never presented in China?
SELECT title , director FROM film WHERE film_id NOT IN (SELECT film_id FROM film_market_estimation AS T1 JOIN market AS T2 ON T1.market_id = T2.Market_ID WHERE country = 'China')
1
film_rank
CREATE TABLE "film" ( "Film_ID" int, "Title" text, "Studio" text, "Director" text, "Gross_in_dollar" int, PRIMARY KEY ("Film_ID") ); CREATE TABLE "market" ( "Market_ID" int, "Country" text, "Number_cities" int, PRIMARY KEY ("Market_ID") ); CREATE TABLE "film_market_estimation" ( "Estimation_ID" int, "Low_Estimate" real, "High_Estimate" real, "Film_ID" int, "Type" text, "Market_ID" int, "Year" int, PRIMARY KEY ("Estimation_ID"), FOREIGN KEY ("Film_ID") REFERENCES film("Film_ID"), FOREIGN KEY ("Market_ID") REFERENCES market("Market_ID") )
Return the titles and directors of films that were never in the market of China.
SELECT title , director FROM film WHERE film_id NOT IN (SELECT film_id FROM film_market_estimation AS T1 JOIN market AS T2 ON T1.market_id = T2.Market_ID WHERE country = 'China')
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
How many calendar items do we have?
SELECT count(*) FROM Ref_calendar
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Count the number of all the calendar items.
SELECT count(*) FROM Ref_calendar
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show all calendar dates and day Numbers.
SELECT calendar_date , day_Number FROM Ref_calendar
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are all the calendar dates and day Numbers?
SELECT calendar_date , day_Number FROM Ref_calendar
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the number of document types.
SELECT count(*) FROM Ref_document_types
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
How many document types are there?
SELECT count(*) FROM Ref_document_types
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
List all document type codes and document type names.
SELECT document_type_code , document_type_name FROM Ref_document_types
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are all the document type codes and document type names?
SELECT document_type_code , document_type_name FROM Ref_document_types
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the name and description for document type code RV?
SELECT document_type_name , document_type_description FROM Ref_document_types WHERE document_type_code = "RV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Give me the name and description of the document type code RV.
SELECT document_type_name , document_type_description FROM Ref_document_types WHERE document_type_code = "RV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the document type code for document type "Paper"?
SELECT document_type_code FROM Ref_document_types WHERE document_type_name = "Paper"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the code of the document type "Paper".
SELECT document_type_code FROM Ref_document_types WHERE document_type_name = "Paper"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the number of documents with document type code CV or BK.
SELECT count(*) FROM All_documents WHERE document_type_code = "CV" OR document_type_code = "BK"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
How many documents have document type code CV or BK?
SELECT count(*) FROM All_documents WHERE document_type_code = "CV" OR document_type_code = "BK"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the date when the document "Marry CV" was stored?
SELECT date_stored FROM All_documents WHERE Document_name = "Marry CV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
When was the document named "Marry CV" stored? Give me the date.
SELECT date_stored FROM All_documents WHERE Document_name = "Marry CV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the day Number and date of all the documents?
SELECT T2.day_Number , T1.Date_Stored FROM All_documents AS T1 JOIN Ref_calendar AS T2 ON T1.date_stored = T2.calendar_date
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Return the day Number and stored date for all the documents.
SELECT T2.day_Number , T1.Date_Stored FROM All_documents AS T1 JOIN Ref_calendar AS T2 ON T1.date_stored = T2.calendar_date
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the document type name for the document with name "How to read a book"?
SELECT T2.document_type_name FROM All_documents AS T1 JOIN Ref_document_types AS T2 ON T1.document_type_code = T2.document_type_code WHERE T1.document_name = "How to read a book"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the document type name of the document named "How to read a book".
SELECT T2.document_type_name FROM All_documents AS T1 JOIN Ref_document_types AS T2 ON T1.document_type_code = T2.document_type_code WHERE T1.document_name = "How to read a book"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the number of locations.
SELECT count(*) FROM Ref_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
How many locations are listed in the database?
SELECT count(*) FROM Ref_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
List all location codes and location names.
SELECT location_code , location_name FROM Ref_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are all the location codes and location names?
SELECT location_code , location_name FROM Ref_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the name and description for location code x?
SELECT location_name , location_description FROM Ref_locations WHERE location_code = "x"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Give me the name and description of the location with code x.
SELECT location_name , location_description FROM Ref_locations WHERE location_code = "x"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the location code for the country "Canada"?
SELECT location_code FROM Ref_locations WHERE location_name = "Canada"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the location code of the country "Canada".
SELECT location_code FROM Ref_locations WHERE location_name = "Canada"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
How many roles are there?
SELECT count(*) FROM ROLES
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Count the total number of roles listed.
SELECT count(*) FROM ROLES
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
List all role codes, role names, and role descriptions.
SELECT role_code , role_name , role_description FROM ROLES
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are all the role codes, role names, and role descriptions?
SELECT role_code , role_name , role_description FROM ROLES
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the name and description for role code "MG"?
SELECT role_name , role_description FROM ROLES WHERE role_code = "MG"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the name and description of the role with code "MG".
SELECT role_name , role_description FROM ROLES WHERE role_code = "MG"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the description for role name "Proof Reader".
SELECT role_description FROM ROLES WHERE role_name = "Proof Reader"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the description of the role named "Proof Reader"?
SELECT role_description FROM ROLES WHERE role_name = "Proof Reader"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
How many employees do we have?
SELECT count(*) FROM Employees
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the number of employees we have.
SELECT count(*) FROM Employees
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the name, role code, and date of birth for the employee with name 'Armani'.
SELECT employee_name , role_code , date_of_birth FROM Employees WHERE employee_Name = 'Armani'
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the name, role code, and date of birth of the employee named 'Armani'?
SELECT employee_name , role_code , date_of_birth FROM Employees WHERE employee_Name = 'Armani'
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the id for the employee called Ebba?
SELECT employee_ID FROM Employees WHERE employee_name = "Ebba"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the id of the employee named Ebba.
SELECT employee_ID FROM Employees WHERE employee_name = "Ebba"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the names of all the employees with role "HR".
SELECT employee_name FROM Employees WHERE role_code = "HR"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Which employees have the role with code "HR"? Find their names.
SELECT employee_name FROM Employees WHERE role_code = "HR"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show all role codes and the number of employees in each role.
SELECT role_code , count(*) FROM Employees GROUP BY role_code
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the code of each role and the number of employees in each role?
SELECT role_code , count(*) FROM Employees GROUP BY role_code
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the role code with the largest number of employees?
SELECT role_code FROM Employees GROUP BY role_code ORDER BY count(*) DESC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the code of the role that have the most employees.
SELECT role_code FROM Employees GROUP BY role_code ORDER BY count(*) DESC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show all role codes with at least 3 employees.
SELECT role_code FROM Employees GROUP BY role_code HAVING count(*) >= 3
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the roles with three or more employees? Give me the role codes.
SELECT role_code FROM Employees GROUP BY role_code HAVING count(*) >= 3
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the role code with the least employees.
SELECT role_code FROM Employees GROUP BY role_code ORDER BY count(*) ASC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the role with the smallest number of employees? Find the role codes.
SELECT role_code FROM Employees GROUP BY role_code ORDER BY count(*) ASC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the role name and role description for employee called Ebba?
SELECT T2.role_name , T2.role_description FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T1.employee_name = "Ebba"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the name and description of the role played by the employee named Ebba.
SELECT T2.role_name , T2.role_description FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T1.employee_name = "Ebba"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the names of employees with role name Editor.
SELECT T1.employee_name FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T2.role_name = "Editor"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the names of all the employees whose the role name is "Editor".
SELECT T1.employee_name FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T2.role_name = "Editor"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the employee ids for all employees with role name "Human Resource" or "Manager".
SELECT T1.employee_id FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T2.role_name = "Human Resource" OR T2.role_name = "Manager"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the employee ids of the employees whose role name is "Human Resource" or "Manager"?
SELECT T1.employee_id FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T2.role_name = "Human Resource" OR T2.role_name = "Manager"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the different location codes for documents?
SELECT DISTINCT location_code FROM Document_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Give me all the distinct location codes for documents.
SELECT DISTINCT location_code FROM Document_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the location name for document "Robin CV".
SELECT T3.location_name FROM All_documents AS T1 JOIN Document_locations AS T2 ON T1.document_id = T2.document_id JOIN Ref_locations AS T3 ON T2.location_code = T3.location_code WHERE T1.document_name = "Robin CV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the location name of the document "Robin CV"?
SELECT T3.location_name FROM All_documents AS T1 JOIN Document_locations AS T2 ON T1.document_id = T2.document_id JOIN Ref_locations AS T3 ON T2.location_code = T3.location_code WHERE T1.document_name = "Robin CV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the location code, the starting date and ending data in that location for all the documents.
SELECT location_code , date_in_location_from , date_in_locaton_to FROM Document_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are each document's location code, and starting date and ending data in that location?
SELECT location_code , date_in_location_from , date_in_locaton_to FROM Document_locations
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is "the date in location from" and "the date in location to" for the document with name "Robin CV"?
SELECT T1.date_in_location_from , T1.date_in_locaton_to FROM Document_locations AS T1 JOIN All_documents AS T2 ON T1.document_id = T2.document_id WHERE T2.document_name = "Robin CV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the starting date and ending data in location for the document named "Robin CV".
SELECT T1.date_in_location_from , T1.date_in_locaton_to FROM Document_locations AS T1 JOIN All_documents AS T2 ON T1.document_id = T2.document_id WHERE T2.document_name = "Robin CV"
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the location codes and the number of documents in each location.
SELECT location_code , count(*) FROM Document_locations GROUP BY location_code
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the code of each location and the number of documents in that location?
SELECT location_code , count(*) FROM Document_locations GROUP BY location_code
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What is the location code with the most documents?
SELECT location_code FROM Document_locations GROUP BY location_code ORDER BY count(*) DESC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Find the code of the location with the largest number of documents.
SELECT location_code FROM Document_locations GROUP BY location_code ORDER BY count(*) DESC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the location codes with at least 3 documents.
SELECT location_code FROM Document_locations GROUP BY location_code HAVING count(*) >= 3
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the codes of the locations with at least three documents?
SELECT location_code FROM Document_locations GROUP BY location_code HAVING count(*) >= 3
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the location name and code with the least documents.
SELECT T2.location_name , T1.location_code FROM Document_locations AS T1 JOIN Ref_locations AS T2 ON T1.location_code = T2.location_code GROUP BY T1.location_code ORDER BY count(*) ASC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the name and code of the location with the smallest number of documents?
SELECT T2.location_name , T1.location_code FROM Document_locations AS T1 JOIN Ref_locations AS T2 ON T1.location_code = T2.location_code GROUP BY T1.location_code ORDER BY count(*) ASC LIMIT 1
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the names of the employees who authorised the destruction and the employees who destroyed the corresponding documents?
SELECT T2.employee_name , T3.employee_name FROM Documents_to_be_destroyed AS T1 JOIN Employees AS T2 ON T1.Destruction_Authorised_by_Employee_ID = T2.employee_id JOIN Employees AS T3 ON T1.Destroyed_by_Employee_ID = T3.employee_id;
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
List the names of the employees who authorized the destruction of documents and the employees who destroyed the corresponding documents.
SELECT T2.employee_name , T3.employee_name FROM Documents_to_be_destroyed AS T1 JOIN Employees AS T2 ON T1.Destruction_Authorised_by_Employee_ID = T2.employee_id JOIN Employees AS T3 ON T1.Destroyed_by_Employee_ID = T3.employee_id;
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the id of each employee and the number of document destruction authorised by that employee.
SELECT Destruction_Authorised_by_Employee_ID , count(*) FROM Documents_to_be_destroyed GROUP BY Destruction_Authorised_by_Employee_ID
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the id of each employee and the number of document destruction authorised by that employee?
SELECT Destruction_Authorised_by_Employee_ID , count(*) FROM Documents_to_be_destroyed GROUP BY Destruction_Authorised_by_Employee_ID
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the employee ids and the number of documents destroyed by each employee.
SELECT Destroyed_by_Employee_ID , count(*) FROM Documents_to_be_destroyed GROUP BY Destroyed_by_Employee_ID
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the id of each employee and the number of document destroyed by that employee?
SELECT Destroyed_by_Employee_ID , count(*) FROM Documents_to_be_destroyed GROUP BY Destroyed_by_Employee_ID
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the ids of the employees who don't authorize destruction for any document.
SELECT employee_id FROM Employees EXCEPT SELECT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Which employees do not authorize destruction for any document? Give me their employee ids.
SELECT employee_id FROM Employees EXCEPT SELECT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the ids of all employees who have authorized destruction.
SELECT DISTINCT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the ids of all the employees who authorize document destruction?
SELECT DISTINCT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the ids of all employees who have destroyed a document.
SELECT DISTINCT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
What are the ids of all the employees who have destroyed documents?
SELECT DISTINCT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the ids of all employees who don't destroy any document.
SELECT employee_id FROM Employees EXCEPT SELECT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Which employees do not destroy any document? Find their employee ids.
SELECT employee_id FROM Employees EXCEPT SELECT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Show the ids of all employees who have either destroyed a document or made an authorization to do this.
SELECT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed UNION SELECT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed
1
cre_Doc_Tracking_DB
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Calendar ( Calendar_Date DATETIME NOT NULL, Day_Number INTEGER, PRIMARY KEY (Calendar_Date) ); CREATE TABLE Ref_Locations ( Location_Code CHAR(15) NOT NULL, Location_Name VARCHAR(255) NOT NULL, Location_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Location_Code) ); CREATE TABLE ROLES ( Role_Code CHAR(15) NOT NULL, Role_Name VARCHAR(255), Role_Description VARCHAR(255), PRIMARY KEY (Role_Code) ); CREATE TABLE All_Documents ( Document_ID INTEGER NOT NULL, Date_Stored DATETIME, Document_Type_Code CHAR(15) NOT NULL, Document_Name CHAR(255), Document_Description CHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Date_Stored) REFERENCES Ref_Calendar (Calendar_Date) ); CREATE TABLE Employees ( Employee_ID INTEGER NOT NULL, Role_Code CHAR(15) NOT NULL, Employee_Name VARCHAR(255), Gender_MFU CHAR(1) NOT NULL, Date_of_Birth DATETIME NOT NULL, Other_Details VARCHAR(255), PRIMARY KEY (Employee_ID), FOREIGN KEY (Role_Code) REFERENCES ROLES (Role_Code) ); CREATE TABLE Document_Locations ( Document_ID INTEGER NOT NULL, Location_Code CHAR(15) NOT NULL, Date_in_Location_From DATETIME NOT NULL, Date_in_Locaton_To DATETIME, PRIMARY KEY (Document_ID, Location_Code, Date_in_Location_From), FOREIGN KEY (Location_Code) REFERENCES Ref_Locations (Location_Code), FOREIGN KEY (Date_in_Location_From) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Date_in_Locaton_To) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) ); CREATE TABLE Documents_to_be_Destroyed ( Document_ID INTEGER NOT NULL, Destruction_Authorised_by_Employee_ID INTEGER, Destroyed_by_Employee_ID INTEGER, Planned_Destruction_Date DATETIME, Actual_Destruction_Date DATETIME, Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Destroyed_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Destruction_Authorised_by_Employee_ID) REFERENCES Employees (Employee_ID), FOREIGN KEY (Planned_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Actual_Destruction_Date) REFERENCES Ref_Calendar (Calendar_Date), FOREIGN KEY (Document_ID) REFERENCES All_Documents (Document_ID) )
Which employees have either destroyed a document or made an authorization to do so? Return their employee ids.
SELECT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed UNION SELECT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed
1
club_1
How many clubs are there?
SELECT count(*) FROM club