-++++++++++++++++++++++++++++++++++++++++++++++++++++++++
----------------------transaction------------------------
-- Create a table
CREATE TABLE Employee (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
department VARCHAR(50),
salary DECIMAL(10, 2)
);
-- Insert some values
INSERT INTO Employee (name, department, salary)
VALUES
('John', 'IT', 50000.00),
('Alice', 'HR', 60000.00),
('Bob', 'Finance', 55000.00);
_____________________________________________________________________
select * from employee;
-- Start a transaction
START TRANSACTION;
-- Insert a new employee
INSERT INTO Employee (name, department, salary) VALUES ('Emily', 'Marketing',
48000.00);
-- Update the salary of an employee
UPDATE Employee SET salary = 52000.00 WHERE name = 'John';
-- Delete an employee
DELETE FROM Employee WHERE name = 'Bob';
select * from employee;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ROLLBACK ;
select * from employee;
COMMIT;
select * from employee;
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Let's grant and revoke privileges on the Employees table for a hypothetical user
named employee_manager.
Assuming you want to grant SELECT, INSERT, UPDATE, and DELETE privileges to
employee_manager on the Employees table:
-- Grant privileges
GRANT SELECT, INSERT, UPDATE, DELETE ON Employees TO employee_manager;
_________________________________________________________
Now, the employee_manager user has the necessary privileges to perform these
operations on the Employees table.
If you later decide to revoke these privileges from the employee_manager user:
-- Revoke privileges
REVOKE SELECT, INSERT, UPDATE, DELETE ON Employees FROM employee_manager;
--------------------------------------------------------------------
After revoking the privileges, the employee_manager user will no longer have
permission to perform these operations on the Employees table.
Granting and revoking privileges allows you to control access to database objects,
ensuring that only authorized users can perform specific actions on those objects.
It's an essential aspect of database security and access control.