138k views
0 votes
CREATE TABLE statements: -- Employees table CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName CHAR(20), LastName CHAR(20), Department CHAR(20), Salary INT CHECK (Salary >= 5000 AND Salary <= 20000) ); -- Departments table CREATE TABLE Departments ( DepartmentID INT PRIMARY KEY, DepartmentName CHAR(20) ); -- Assignments table (assuming a many-to-many relationship between Employees and Departments) CREATE TABLE Assignments ( AssignmentID INT PRIMARY KEY, EmployeeID INT, DepartmentID INT, FOREIGN KEY (EmployeeID) REFERENCES Employees(EmployeeID), FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID) );

User Desc
by
7.9k points

1 Answer

4 votes

Final Answer:

The provided SQL script defines three tables: Employees, Departments, and Assignments. It establishes relationships between Employees and Departments through the Assignments table, which assumes a many-to-many relationship.

Step-by-step explanation:

The Employees table is created with fields for EmployeeID, FirstName, LastName, Department, and Salary. The EmployeeID is set as the primary key, ensuring unique identification for each employee. Salary has a CHECK constraint to ensure it falls within the specified range of $5000 to $20000.

The Departments table includes DepartmentID (primary key) and DepartmentName. This structure allows for the storage of department-related information.

The Assignments table signifies a many-to-many relationship between Employees and Departments. It has its own primary key (AssignmentID) and foreign keys (EmployeeID and DepartmentID) that reference the respective primary keys in the Employees and Departments tables. This design facilitates the linking of employees to multiple departments and vice versa.

In summary, the script models a relational database where employees are associated with specific departments through the Assignments table. The primary and foreign key constraints maintain data integrity by ensuring unique identifiers and referential integrity. This structure supports the representation of complex relationships between employees and departments in an organized manner.

Therefore, The provided SQL script defines three tables: Employees, Departments, and Assignments. It establishes relationships between Employees and Departments through the Assignments table, which assumes a many-to-many relationship.

User William Reed
by
7.3k points