0% found this document useful (0 votes)
11 views8 pages

Tinooooooo

The document outlines an SQL script for setting up a LabWork database with two tables, each containing four rows, and three users with varying access privileges. It details the creation of the database structure, user management, and access control following the principle of least privilege. Additionally, it includes examples of SQL operations such as JOIN and REVOKE to demonstrate user capabilities and restrictions.

Uploaded by

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

Tinooooooo

The document outlines an SQL script for setting up a LabWork database with two tables, each containing four rows, and three users with varying access privileges. It details the creation of the database structure, user management, and access control following the principle of least privilege. Additionally, it includes examples of SQL operations such as JOIN and REVOKE to demonstrate user capabilities and restrictions.

Uploaded by

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

INSTITUTE OF ACCOUNTANCY ARUSHA

FACULTY OF INFORMATICS

INDIVIDUAL ASSIGNMENT

NAME: THOMAS ROBERT MIHAYO


REGISTRATION NO: BCSe-01-0224-2022
MODULE NAME: NETWORK MANAGEMENT AND ADMINISTRATION
MODULE CODE: CYU 08105
FACILITATOR: DR.NICODEMUS
SEMESTER: ONE
ACADEMIC YEAR: 2024/2025
DATE OF SUBMISSION: 24/01/2025
# SQL Database Setup for LabWork

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)
);

-- Insert 4 rows into table1


INSERT INTO table1 VALUES (1, 'Item A', 100, 'First item');
INSERT INTO table1 VALUES (2, 'Item B', 200, 'Second item');
INSERT INTO table1 VALUES (3, 'Item C', 300, 'Third item');
INSERT INTO table1 VALUES (4, 'Item D', 400, 'Fourth item');

-- Insert 4 rows into table2


INSERT INTO table2 VALUES (1, 1, 'Info for Item A');
INSERT INTO table2 VALUES (2, 2, 'Info for Item B');
INSERT INTO table2 VALUES (3, 3, 'Info for Item C');
INSERT INTO table2 VALUES (4, 4, 'Info for Item D');

-- Create users
CREATE USER 'users1'@'localhost' IDENTIFIED BY 'password1';
CREATE USER 'users2'@'localhost' IDENTIFIED BY 'password2';
CREATE USER 'users3'@'localhost' IDENTIFIED BY 'password3';

-- Grant privileges following principle of least privilege


-- users1 can only SELECT from table1
GRANT SELECT ON LabWork.table1 TO 'users1'@'localhost';

-- users2 can SELECT from both tables and JOIN them


GRANT SELECT ON LabWork.table1 TO 'users2'@'localhost';
GRANT SELECT ON LabWork.table2 TO 'users2'@'localhost';

-- users3 can SELECT, INSERT, UPDATE on both tables


GRANT SELECT, INSERT, UPDATE ON LabWork.table1 TO
'users3'@'localhost';
GRANT SELECT, INSERT, UPDATE ON LabWork.table2 TO
'users3'@'localhost';

-- Example of JOIN operation (can be used by users2 and users3)


SELECT table1.id, table1.name, table2.additional_info
FROM table1
INNER JOIN table2 ON table1.id = table2.table1_id;

-- Example of REVOKE (DAC mechanism)


-- Revoke UPDATE privilege from users3 on table2
REVOKE UPDATE ON LabWork.table2 FROM 'users3'@'localhost';
```
## Explanation:

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

This implementation satisfies all your requirements including database


creation, table structure, user management, privilege assignment, and DAC
mechanisms.
LabWork screenshoot

You might also like