Tinooooooo
Tinooooooo
FACULTY OF INFORMATICS
INDIVIDUAL ASSIGNMENT
Here's a complete SQL script that creates the LabWork database with two
tables (table1 and table2), inserts 4 rows into each, creates three users, and
implements the required access controls:
```sql
-- Create the database
CREATE DATABASE LabWork;
USE LabWork;
-- Create table1
CREATE TABLE table1 (
id INT PRIMARY KEY,
name VARCHAR(50),
value INT,
description VARCHAR(100)
);
-- Create table2
CREATE TABLE table2 (
id INT PRIMARY KEY,
table1_id INT,
additional_info VARCHAR(100),
FOREIGN KEY (table1_id) REFERENCES table1(id)
);
-- Create users
CREATE USER 'users1'@'localhost' IDENTIFIED BY 'password1';
CREATE USER 'users2'@'localhost' IDENTIFIED BY 'password2';
CREATE USER 'users3'@'localhost' IDENTIFIED BY 'password3';
1. **Database Structure**:
- Created LabWork database with two tables (table1 and table2)
- Each table has exactly 4 rows
- Established a relationship between tables with a foreign key
2. **Users**:
- Created three users: users1, users2, users3
- Each has different privilege levels following least privilege principle
3. **Access Control**:
- users1: Only SELECT on table1 (most restricted)
- users2: SELECT on both tables (can perform JOINs)
- users3: SELECT, INSERT, UPDATE on both tables (more privileges)
- Demonstrated REVOKE to remove UPDATE from users3 on table2
4. **JOIN Example**:
- Included an INNER JOIN between the tables that users2 and users3 can
execute