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

2lab2 DB

database lab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

2lab2 DB

database lab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DATABASE LAB MANUAL

LAB-2
Objectives
- Understand CREATE command in SQL.
- Understand DROP Command in SQL.
- Study different data types in SQL.
- Know how to build a database and tables based on a given scenario.

Create a database:

CREATE DATABASE Database_name;

Drop a database:

DROP DATABASE Database_name;

Drop a table:

DROP TABLE table_name;

Create a table:

CREATE TABLE table_name


fieldname1 datatype,
fieldname2 datatype,

);
Data Types

SQL offers a variety of data types to store different kinds of data. Here
are some common SQL data types:

Numeric Data Types


- INT: Integer values.
- FLOAT: Floating-point numbers.

Character and String Data Types


- CHAR(size): Fixed-length character string.
- VARCHAR(size): Variable-length character string.

Date and Time Data Types


- DATE: Date values (YYYY-MM-DD).
- TIME: Time values (HH:MI:SS).
- DATETIME: Combination of date and time.
(YYYY-MM-DD HH:MI:SS)

Other Data Types


- BOOLEAN: True or false values.
LAB WORK

Create the tables based on the following scenario:


1. Departments: The university is organized into departments. Each department has a unique ID and a
name.
2. Courses: Each course has a unique Course ID, a Course name, and a number of Credits. A department
offers several courses, and each course is managed by one teacher. Each course is associated with
only one department.
3. Students: We store each student's name, a unique Student ID, address, and score. A student is
assigned to one department but can enroll in multiple courses. We also keep track of the number of
credits for each course a student enrolls in.
4. Teachers: We store each teacher's name, a unique Employee ID, address, and salary. A teacher is
assigned to one department but can teach multiple courses.
5. Student-Course Enrollment: Each student can enroll in multiple courses, and each course can have
multiple students enrolled. We keep track of the enrollment date and the grade each student receives
for each course.

Steps:
Create Entities:
 Department
 Course
 Student
 Teacher
 Enrollment (for the Student-Course relationship)
Define Attributes:
 Department: DepartmentID (PK), DepartmentName
 Course: CourseID (PK), CourseName, Credits, TeacherID , DepartmentID
 Student: StudentID (PK), Name, Address, Score, DepartmentID
 Teacher: TeacherID (PK), Name, Address, Salary, DepartmentID
 Enrollment: EnrollmentID (PK), EnrollmentDate, Grade, StudentID , CourseID

You might also like