students(student_id, name, year, GPA, programs_code) instructors(instructor_id, name, title, salary, programs_code) programs(code, name, division, instructor_id) course(course_name, credit, domain, course_number) enroll(student_id, instructor_id, course_name) 1. Create tables according to the schema. 2. Use check or assertion to make sure instructors salary > 5000.
时间: 2024-02-27 17:54:57 浏览: 45
spsnip_gui.zip_As You Like It_matlab gui.m
Sure, here are the SQL statements to create the tables based on the given schema, and add a check constraint to ensure that an instructor's salary is greater than 5000:
```
CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(50),
year INT,
GPA DECIMAL(3,2),
programs_code VARCHAR(10)
);
CREATE TABLE instructors (
instructor_id INT PRIMARY KEY,
name VARCHAR(50),
title VARCHAR(50),
salary DECIMAL(10,2),
programs_code VARCHAR(10),
CONSTRAINT salary_check CHECK (salary > 5000)
);
CREATE TABLE programs (
code VARCHAR(10) PRIMARY KEY,
name VARCHAR(50),
division VARCHAR(50),
instructor_id INT,
FOREIGN KEY (instructor_id) REFERENCES instructors(instructor_id)
);
CREATE TABLE course (
course_name VARCHAR(50) PRIMARY KEY,
credit INT,
domain VARCHAR(50),
course_number INT
);
CREATE TABLE enroll (
student_id INT,
instructor_id INT,
course_name VARCHAR(50),
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (instructor_id) REFERENCES instructors(instructor_id),
FOREIGN KEY (course_name) REFERENCES course(course_name)
);
```
The `CONSTRAINT salary_check CHECK (salary > 5000)` statement adds a check constraint to the `instructors` table to ensure that the `salary` column is always greater than 5000.
阅读全文