In: Computer Science
Use MySQL
server.
First step: create and use
database called EDU.
Syntax:
CREATE SCHEMA
edu;
USE edu;
Create a
script which will create the tables listed below:
STUDENT(STUDENT_ID,
STUDENT_NAME, MAJOR_ID, DOB, PHONE_NUMBER)
MAJOR(MAJOR_ID,
MAJOR_NAME)
ENROLLMENT(STUDENT_ID,
COURSE_ID, GRADE)
COURSE(COURSE_ID,
COURSE_NAME)
RESPONSIBILITY(FACULTY_ID,
COURSE_ID)
TEACHER(FACULTY_ID,
DEPT_ID, TEACHER_NAME)
DEPARTMENT(DEPT_ID,
DEPARTMENT_NAME)
Start the script with a series of DROP statements so that as you correct mistakes you will start fresh each time. To avoid referential integrity errors, the table drops should be in the opposite order of the create table statements.
Put script
name and your name in the script heading –see example:
Example of a
script:
/*script1.sql
Student Name:
------*/
USE sh;
DROP TABLE IF EXISTS
part;
DROP TABLE IF EXISTS
salesrep;
CREATE TABLE
part
(Partno
CHAR(4) PRIMARY KEY,
Partdesc
VARCHAR(20),
Onhand
INTEGER,
Partclass CHAR(2) check
(Partclass IN ('AP','HW','KI','SP')),
Unitprice
DECIMAL(6,2)
);
CREATE TABLE
salesrep
(Srepno
CHAR(3),
Srepname
VARCHAR(25),
Srepstreet
VARCHAR(30),
Srepcity
VARCHAR(15) NOT NULL,
Srepprov
VARCHAR(3) NOT NULL,
Sreppcode VARCHAR(6) NOT
NULL,
Totcomm
DECIMAL(8,2),
Commrate
DECIMAL(3,2),
CONSTRAINT pkslsrep
PRIMARY KEY (Srepno)
);
/*myscript.sql
Student Name:_______________*/
/* For creating the database use any of these command
CREATE SCHEMA edu; (or) CREATE DATABASE edu;
*/
USE edu;
DROP TABLE IF EXISTS RESPONSIBILITY;
DROP TABLE IF EXISTS TEACHER;
DROP TABLE IF EXISTS DEPARTMENT;
DROP TABLE IF EXISTS ENROLLMENTS;
DROP TABLE IF EXISTS COURSE;
DROP TABLE IF EXISTS STUDENT;
DROP TABLE IF EXISTS MAJOR;
CREATE TABLE MAJOR
(
MAJORID VARCHAR(10),
MAJORNAME VARCHAR(25),
PRIMARY KEY (MAJORID)
);
CREATE TABLE STUDENT
(
STUDENTID VARCHAR(10),
STUDENTNAME VARCAHR(25),
MAJORID vARCHAR(10),
DOB DATE,
PHONENUMBER INTEGER,
PRIMARY KEY (STUDENTID),
FOREIGN KEY (MAJORID) REFERENCES MAJOR(MAJORID)
);
CREATE TABLE COURSE
(
COURSEID VARCHAR(10),
COURSENAME VARCHAR(25),
PRIMARY KEY (COURSEID)
);
CREATE TABLE ENROLLMENTS
(
STUDENTID VARCHAR(10),
COURSEID VARCHAR(10),
GRADE CHAR(1),
FOREIGN KEY (STUDENTID) REFERENCES STUDENT(STUDENTID),
FOREIGN KEY (COURSEID) REFERENCES COURSE(COURSEID)
);
CREATE DEPARTMENT
(
DEPTID VARCHAR(10),
DEPARTMENTNAME VARCHAR(25),
PRIMARY KEY(DEPTID)
);
CREATE TEACHER
(
FACULTYID VARCHAR(10),
DEPTID VARCHAR(10),
TEACHERNAME VARCHAR(25),
PRIMARY KEY (FACULTYID),
FOREIGN KEY (DEPTID) REFERENCES DEPARTMENT(DEPTID)
);
CREATE RESPONSIBILITY
(
FACULTYID VARCHAR(10),
COURSEID VARCHAR(10),
FOREIGN KEY (FACULTYID) REFERENCES TEACHER(FACULTYID),
FOREIGN KEY (COURSEID) REFERENCES COURSE(COURSEID)
);
---------------------------------------------------------------------------------------------------------------------------------------------------------
Note:Here i am taking all id's as a combination of the letters and
alphabets so i took that data type as varchar.