0% found this document useful (0 votes)
4 views

israr dbms assigment

The document outlines the design of two database schemas: one for student enrollment and course book adoption, and another for a company named 'company_Israr'. It details the structure of tables, their relationships through foreign keys, and includes SQL commands for creating and populating the tables. The schemas are designed to effectively manage and query data related to students, courses, employees, departments, projects, and dependents.

Uploaded by

dheerajkum838
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

israr dbms assigment

The document outlines the design of two database schemas: one for student enrollment and course book adoption, and another for a company named 'company_Israr'. It details the structure of tables, their relationships through foreign keys, and includes SQL commands for creating and populating the tables. The schemas are designed to effectively manage and query data related to students, courses, employees, departments, projects, and dependents.

Uploaded by

dheerajkum838
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Question No.

1
(Taken from Exercise 5.15)
Consider the following relations for a database that keeps track of student enrollment in courses and the books adopted
for each course:

• STUDENT(SSN, Name, Major, Bdate)


• COURSE(Course#, Cname, Dept)
• ENROLL(SSN, Course#, Quarter, Grade)
• BOOK_ADOPTION(Course#, Quarter, Book_ISBN)
• TEXT(Book_ISBN, Book_Title, Publisher, Author)

Task:
1. Draw a relational schema diagram specifying the foreign keys for this schema.

Solution:
Step 1: Creating the Database
CREATE DATABASE enroll;

Step 2: Creating the STUDENT Table

CREATE TABLE STUDENT (

SSN CHAR(9) NOT NULL,


Name VARCHAR(20) NOT NULL,
Major VARCHAR(30),
Bdate DATE,
PRIMARY KEY (SSN)
);
Inserting Data into STUDENT Table
INSERT INTO STUDENT (SSN, Name, Major, Bdate)
VALUES
('669696969', 'Israr', 'Computer Science', '2005-02-27'),
('669696970', 'Dheerah 'Computer Science', '2004-03-25'),
('669696971', 'Aman’, 'History', '2002-06-09'),
('669696972', ‘Pawan', 'Computer Science', '2004-10-25');

Step 3: Creating the COURSE Table


CREATE TABLE COURSE (
COURSENO INT NOT NULL,
CNAME VARCHAR(20) NOT NULL,
DEP VARCHAR(20),
PRIMARY KEY (COURSENO)
);
Inserting Data into COURSE Table
INSERT INTO COURSE (COURSENO, CNAME, DEP) VALUES
(101, 'Calculus', 'Mathematics'),
(102, 'Chemistry', 'Science'),
(103, 'Physics', 'Science'),
(104, 'Programming', 'Computer Science'),
(105, 'Economics', 'Business'),
(106, 'Psychology', 'Social Sciences'),
(107, 'Statistics', 'Mathematics'),
(108, 'Marketing', 'Business'),
(109, 'Biology', 'Science'),
(110, 'Algebra', 'Mathematics');

Step 4: Creating the ENROLL Table


CREATE TABLE ENROLL (
SSN CHAR(9) NOT NULL,
COURSENO INT NOT NULL,
Quarter VARCHAR(10) NOT NULL,
Grade CHAR(2),
PRIMARY KEY (SSN, COURSENO, Quarter),
FOREIGN KEY (SSN) REFERENCES STUDENT(SSN),
FOREIGN KEY (COURSENO) REFERENCES COURSE(COURSENO)
);
Inserting Data into ENROLL Table
INSERT INTO ENROLL (SSN, COURSENO, Quarter, Grade) VALUES
('669696969', 101, 'F-24', 'A-'),
('669696969', 102, 'S-24', 'B+'),
('669696970', 103, 'F-24', 'C'),
('669696970', 104, 'S-24', 'A+'),
('669696971', 105, 'F-24', 'B'),
('669696971', 106, 'S-24', 'A+'),
('669696972', 107, 'F-24', 'A+'),
('669696972', 108, 'S-24', 'B'),
('669696969', 109, 'S-24', 'A-');

Step 5: Creating the TEXT Table


CREATE TABLE TEXT (
Book_ISBN CHAR(13) NOT NULL,
Book_Title VARCHAR(100) NOT NULL,
Publisher VARCHAR(50),
Author VARCHAR(50),
PRIMARY KEY (Book_ISBN)
);
Inserting Data into TEXT Table
INSERT INTO TEXT (Book_ISBN, Book_Title, Publisher, Author) VALUES
('9783161484100', 'Introduction to Algorithms', 'MIT Press', 'Thomas H. Cormen'),
('9780201835955', 'The Art of Computer Programming', 'Addison-Wesley', 'Donald E. Knuth'),
('9780321562348', 'Clean Code', 'Prentice Hall', 'Robert C. Martin'),
('9780262033848', 'Design Patterns', 'Addison-Wesley', 'Gamma, Helm, Johnson, Vlissides'),
('9781491946008', 'Python Crash Course', 'No Starch Press', 'Eric Matthes'),
('9780134623184', 'Computer Networking', 'Pearson', 'Andrew S. Tanenbaum'),
('9780321356680', 'Artificial Intelligence', 'Pearson', 'Russell, Norvig'),
('9780471486950', 'Database System Concepts', 'McGraw-Hill', 'Silberschatz, Korth, Sudarshan');

Step 6: Creating the BOOK_ADOPTION Table


CREATE TABLE BOOK_ADOPTION (
COURSENO INT NOT NULL,
Quarter VARCHAR(10) NOT NULL,
Book_ISBN CHAR(13) NOT NULL,
PRIMARY KEY (COURSENO, Quarter),
FOREIGN KEY (COURSENO) REFERENCES COURSE(COURSENO),
FOREIGN KEY (Book_ISBN) REFERENCES TEXT(Book_ISBN)
);
Inserting Data into BOOK_ADOPTION Table
INSERT INTO BOOK_ADOPTION (COURSENO, Quarter,
Book_ISBN) VALUES
(101, 'F-24', '9783161484100'),
(102, 'S-24', '9780201835955'),
(103, 'F-24', '9780321562348'),
(104, 'S-24', '9780262033848'),
(105, 'S-24', '9781491946008'),
(106, 'F-24', '9780134623184'),
(107, 'F-24', '9780321356680'),
(108, 'S-24', '9780471486950');

Relational Schema Diagram


The schema diagram should include the tables STUDENT, COURSE,
ENROLL, TEXT, and BOOK_ADOPTION with foreign key
relationships indicated as follows:

• ENROLL.SSN references STUDENT.SSN


• ENROLL.COURSENO references COURSE.COURSENO
• BOOK_ADOPTION.COURSENO references COURSE.COURSENO
• BOOK_ADOPTION.Book_ISBN references TEXT.Book_ISBN

The STUDENT table links to ENROLL through SSN, COURSE links to ENROLL through COURSENO, TEXT links to
BOOK_ADOPTION through Book_ISBN, and BOOK_ADOPTION links back to COURSE through COURSENO.

Question No. 2
In this task, I designed and populated a database schema for a company named `company_Israr`, covering essential
aspects of company operations. The schema includes six key tables: **EMPLOYEE**, **DEPARTMENT**,
**DEPT_LOCATIONS**, **PROJECT**, **WORKS_ON**, and **DEPENDENT**. Each table models different
elements, such as employee information, departmental data, project assignments, and employee dependents. Here’s a
breakdown of each table and its function:

1. **Creating the Database (`company_Israr`):**


- Using `CREATE DATABASE company_Israr;` initiates a new database to store tables that define the company's
structure and operations.

2. **EMPLOYEE Table:**
- This table holds each employee's details, including personal information (first and last names, social security
number, birthdate, address, gender, and salary).
- `Super_ssn` links to an employee’s supervisor, and `Dno` is a foreign key that associates the employee with a
specific department in the `DEPARTMENT` table.
- `FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE(Ssn)` allows for a recursive relationship, where an
employee can have another employee as their supervisor.

3. **DEPARTMENT Table:**
- Contains information on company departments, such as department name (`Dname`), department number
(`Dnumber`), manager’s SSN (`Mgr_ssn`), and the manager's start date.
- `FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn)` links each department to its manager in the
`EMPLOYEE` table.

4. **DEPT_LOCATIONS Table:**
- Tracks department locations, with `Dnumber` as a foreign key linking it to the `DEPARTMENT` table.
- The combination of `Dnumber` and `Dlocation` forms a composite primary key, allowing departments to have
multiple locations.

5. **PROJECT Table:**
- Records details about company projects, including project name (`Pname`), project number (`Pnumber`), location
(`Plocation`), and the department in charge (`Dnum`).
- `Dnum` is a foreign key that links each project to a department in the `DEPARTMENT` table.

6. **WORKS_ON Table:**
- Captures the allocation of employees to projects, with fields for employee SSN (`Essn`), project number (`Pno`), and
hours worked on each project.
- `Essn` references the `EMPLOYEE` table, and `Pno` references the `PROJECT` table. Both `Essn` and `Pno` form a
composite primary key since employees can work on multiple projects.

7. **DEPENDENT Table:**
- Stores details about employees’ dependents, including the employee’s SSN (`Essn`), dependent’s name
(`Dependent_name`), gender, birth date (`Bdate`), and relationship to the employee.
- `Essn` serves as a foreign key referencing the `EMPLOYEE` table, associating each dependent with an employee.

Sample data for each table illustrates how records would appear within the schema, with relationships defined through
primary and foreign keys to simulate real-world connections, such as employees belonging to departments, working on
projects, and having dependents. This schema supports effective data management and querying for organizational
functions.

You might also like