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

Database 5

Uploaded by

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

Database 5

Uploaded by

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

You're creating a School Database with two tables:

1. Students – Contains student information.

2. Enrollments – Contains records of courses students are enrolled in.

Goal: Establish a one-to-many relationship between these tables.

Step 1: Create the Database

1. Open Microsoft Access.

2. Click on Blank Database.

3. Enter a name for your database (e.g., SchoolDatabase.accdb).

4. Click Create.

Step 2: Create the Students Table (Primary Table)

1. In the Access window, click on Create > Table Design.

2. You'll see a blank table design grid.

Add Fields:

• Field Name: StudentID

o Data Type: AutoNumber

o Description: Unique ID for each student.

o Right-click StudentID and click Primary Key.

• Field Name: FirstName

o Data Type: Short Text

o Description: Student's first name.

o Field Size: 50 (default).

• Field Name: LastName

o Data Type: Short Text

o Description: Student's last name.

o Field Size: 50 (default).

• Field Name: DateOfBirth

o Data Type: Date/Time

o Description: Student's date of birth.

Save the Table:

1. Click File > Save (or press Ctrl + S).

2. Name the table Students.


Step 3: Create the Enrollments Table (Foreign Table)

1. Go to Create > Table Design.

Add Fields:

• Field Name: EnrollmentID

o Data Type: AutoNumber

o Description: Unique ID for each enrollment.

o Right-click EnrollmentID and click Primary Key.

• Field Name: StudentID

o Data Type: Number

o Description: Links to the StudentID in the Students table.

• Field Name: CourseName

o Data Type: Short Text

o Description: Name of the course.

o Field Size: 100.

• Field Name: EnrollmentDate

o Data Type: Date/Time

o Description: Date of enrollment.

Save the Table:

1. Click File > Save.

2. Name the table Enrollments.

Step 4: Establish the One-to-Many Relationship

1. Go to Database Tools > Relationships.

2. In the Show Table dialog box:

o Select Students and Enrollments tables.

o Click Add, then Close.

3. Drag the StudentID from the Students table and drop it on the StudentID field in the Enrollments table.

4. The Edit Relationships dialog will appear:

o Check Enforce Referential Integrity.

o Make sure the relationship is set to One-to-Many.

o Click Create.

Step 5: Enter Data into the Students Table

1. Double-click the Students table in the Navigation Pane (left side).


2. Enter the following records:

yaml

Copy code

StudentID | FirstName | LastName | DateOfBirth

---------------------------------------------

1 | John | Doe | 2002-05-14

2 | Jane | Smith | 2003-03-22

3 | David | Johnson | 2001-09-30

(Note: The StudentID auto-generates if AutoNumber is set).

Step 6: Enter Data into the Enrollments Table

1. Double-click the Enrollments table to open it.

2. Enter the following records:

yaml

Copy code

EnrollmentID | StudentID | CourseName | EnrollmentDate

------------------------------------------------------

1 | 1 | Math 101 | 2024-01-10

2 | 1 | Science 101| 2024-01-15

3 | 2 | History 101| 2024-02-01

• StudentID must match the StudentID in the Students table.

You might also like