Complete the SQL code to create a table for an entity named 'Student' with an ID as primary key.
CREATE TABLE Student (StudentID [1] PRIMARY KEY, Name VARCHAR(100));
The primary key should be an integer type for IDs in this case.
Complete the SQL code to create a table for a weak entity 'Dependent' with a foreign key referencing 'Employee'.
CREATE TABLE Dependent (DependentID INT, EmployeeID [1], PRIMARY KEY (DependentID, EmployeeID), FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID));The foreign key EmployeeID should have the same data type as the referenced primary key, which is INT.
Fix the error in the SQL code to correctly create a table for a many-to-many relationship 'Enrollment' between 'Student' and 'Course'.
CREATE TABLE Enrollment (StudentID INT, CourseID [1], PRIMARY KEY (StudentID, CourseID), FOREIGN KEY (StudentID) REFERENCES Student(StudentID), FOREIGN KEY (CourseID) REFERENCES Course(CourseID));Both foreign keys should have the same data type as their referenced primary keys, which are INT.
Fill both blanks to create a table for an entity 'Book' with a composite primary key and a foreign key referencing 'Publisher'.
CREATE TABLE Book (ISBN [1], Edition [2], PRIMARY KEY (ISBN, Edition), PublisherID INT, FOREIGN KEY (PublisherID) REFERENCES Publisher(PublisherID));
ISBN is a string of 13 characters, so VARCHAR(13) is used. Edition is a number, so INT is appropriate.
Fill all three blanks to create a table for an entity 'Employee' with an auto-increment primary key, a name, and a hire date.
CREATE TABLE Employee (EmployeeID [1] [2] PRIMARY KEY, Name [3] NOT NULL, HireDate DATE);
EmployeeID is an INT with AUTO_INCREMENT for automatic numbering. Name is a VARCHAR(100) to store text.