-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassesment 1.sql
More file actions
48 lines (42 loc) · 1.1 KB
/
Copy pathassesment 1.sql
File metadata and controls
48 lines (42 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#Q-1
CREATE DATABASE sampal ;
#Q-2
USE sampal ;
#Q-3
CREATE TABLE employee (
emp_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
emp_name VARCHAR(50),
position VARCHAR(50),
hire_date DATE,
salary DECIMAL(10, 2),
bonus DECIMAL(10, 2),
total_salary DECIMAL(10, 2),
emp_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
#Q-4
INSERT INTO employee (emp_name, position, salary, hire_date, bonus)
VALUES
('varun', 'Manager', 50000.00, '2022-01-15', 5000.00),
('tirth', 'Developer', 40000.00, '2022-03-10', 3000.00),
('jay', 'Designer', 45000.00, '2022-05-20', 4000.00);
#Q-5
CREATE TABLE employee_audit (
audit_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
emp_id INT,
emp_name VARCHAR(50),
position VARCHAR(50),
inserted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
#Q-6
DELIMITER $$
CREATE TRIGGER after_employee_insert
AFTER INSERT ON employee
FOR EACH ROW
BEGIN
INSERT INTO employee_audit (emp_id, emp_name, position)
VALUES (NEW.emp_id, NEW.emp_name, NEW.position);
END$$
DELIMITER ;
SHOW TRIGGERS ;
select * from employee;
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS;