Unit 3 Note 2 for lab activity
Unit 3 Note 2 for lab activity
To create the database tables in Microsoft Access based on the relational database model on page
64 of your textbook, you can use the following SQL code. This code will create the five tables:
Students, Subject, MarkList, SubjectAssigned, and Teachers.
1. VARCHAR(n)
This data type is used for variable-length strings. The n specifies the maximum number
of characters that can be stored.
Example: VARCHAR(10) can store up to 10 characters.
Use Case: Suitable for text fields like names, codes, or identifiers where the length can
vary.
2. INT
This data type is used for integer values. It stores whole numbers without decimals.
Use Case: Ideal for storing numerical data such as marks, counts, or quantities.
3. PRIMARY KEY
This is not a data type but a constraint that uniquely identifies each record in the table.
Each table can have only one primary key, which can consist of one or more columns.
Use Case: Ensures that each entry in the table is unique and helps maintain data integrity.
4. FOREIGN KEY
Again, this is a constraint rather than a data type. It establishes a relationship between
two tables by linking a column (or a group of columns) in one table to the primary key of
another table.
Use Case: Used to enforce referential integrity, ensuring that the value in one table
corresponds to a valid entry in another.
These data types help define the structure of the database, ensuring that data is stored in a
consistent and efficient manner.
So far we used the DDL to create the database schema or structure. The next task is data
insertion which is DML usage. Learn the following codes and insert the data into the
tables,
INSERT INTO Students (SCode, SName, FName) VALUES
('S001', 'Chaltu', 'Gemeda'),
('S002', 'Alemene', 'Setegen'),
('S003', 'Muna', 'Haftom'),
('S004', 'Haftom', 'Kiros');
Students Table: Adding four students with their respective codes and names.
Subject Table: Adding four subjects with their IDs, names, grades, and credit hours.
MarkList Table: Inserting the marks for specific students in given subjects.
SubjectAssigned Table: Assigning subjects to students.
Teachers Table: Adding teacher records with their IDs, names, and specializations.
Make sure to run each INSERT INTO statement sequentially in your Microsoft Access
SQL view to populate your database with the sample data.
Insert Exercises
INSERT INTO Students (SCode, SName, FName) VALUES ('S005', 'Liya', 'Tesfaye');
Adds a new student with the code 'S005', name 'Liya', and father’s name
'Tesfaye'.
Update Exercises