Skip to content

Commit 2739a08

Browse files
authored
Merge branch 'Baeldung:main' into main
2 parents 818677a + 4e445b8 commit 2739a08

File tree

50 files changed

+378
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+378
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
INSERT INTO registration_analytics(student_id, number_of_course_enrolled, year)
2+
SELECT student_id, COUNT(course_id) AS number_of_course_enrolled, year
3+
FROM registration
4+
GROUP BY course_id, student_id, year;

sql-queries-5/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SET autocommit=1; --Turns on automatic transaction mode
2+
3+
CREATE TABLE Department
4+
(
5+
id INT PRIMARY KEY NOT Null,
6+
name VARCHAR (50),
7+
code VARCHAR (4),
8+
UNIQUE (id)
9+
); -- Runs in a separate transaction
10+
11+
SELECT SELECT * FROM DEPARTMENT; --Runs in a separate transaction
12+
13+
INSERT INTO Department VALUES(6,'Data Science','DS'); --Runs in a separate transaction
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SET autocommit=1; --Enables autocommit mode
2+
3+
/*These are equivalent*/
4+
SET autocommit = DEFAULT;
5+
6+
SET autocommit='ON';
7+
SET @@autocommit = 'ON';
8+
9+
SET SESSION autocommit = 'ON';
10+
SET @@SESSION.autocommit = 'ON';
11+
12+
SET LOCAL autocommit = 'ON';
13+
SET @@LOCAL.autocommit = 'ON';
14+
15+
SELECT @@autocommit; --Query autocommit mode
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
START TRANSACTION; --Starts a single transaction
2+
3+
/* SQL Statements*/
4+
SELECT SELECT * FROM DEPARTMENT;
5+
INSERT INTO Department VALUES(6,'Data Science','DS');
6+
INSERT INTO Department VALUES(7,'Computer Engineering','CE');
7+
UPDATE Department SET name = 'Math' WHERE id=5;
8+
9+
COMMIT; -- or ROLLBACK ends the single transaction
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Using INSERT IGNORE
2+
INSERT IGNORE INTO table_name (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
3+
VALUES (id_value, name_value, national_id_value, birth_date_value, enrollment_date_value, graduation_date_value, gpa_value);
4+
5+
6+
-- Using INSERT … ON DUPLICATE KEY UPDATE
7+
INSERT INTO table_name (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
8+
VALUES (id_value, name_value, national_id_value, birth_date_value, enrollment_date_value, graduation_date_value, gpa_value)
9+
ON DUPLICATE KEY UPDATE id = id;

0 commit comments

Comments
 (0)