-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path31_01_2025.sql
45 lines (35 loc) · 1.23 KB
/
31_01_2025.sql
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
-- Create database with consistent naming
CREATE DATABASE StudentPractice;
USE StudentPractice;
-- Create table with proper constraints
CREATE TABLE MechanicalStudents (
student_id INT PRIMARY KEY,
student_name VARCHAR(25) NOT NULL,
enrollment_date DATE DEFAULT CURRENT_DATE
);
-- Start transaction with clear comments
START TRANSACTION;
-- Initial insert
INSERT INTO MechanicalStudents VALUES (101, 'Jayanth Kumar', DEFAULT);
SELECT * FROM MechanicalStudents; -- Verify insert
-- First savepoint
SAVEPOINT initial_insert;
-- Update operation
UPDATE MechanicalStudents
SET student_id = 102
WHERE student_id = 101;
SELECT * FROM MechanicalStudents; -- Verify update
-- Second savepoint
SAVEPOINT after_update;
-- Additional insert
INSERT INTO MechanicalStudents VALUES (103, 'Karthick Raj', DEFAULT);
SELECT * FROM MechanicalStudents; -- Verify second insert
-- Third savepoint
SAVEPOINT second_insert;
-- Rollback to after_update state
ROLLBACK TO SAVEPOINT after_update;
SELECT * FROM MechanicalStudents; -- Show state after rollback
-- Commit the transaction
COMMIT;
-- Final verification
SELECT * FROM MechanicalStudents;