Skip to content

Commit 818677a

Browse files
authored
Merge branch 'Baeldung:main' into main
2 parents 324cea2 + bd6a718 commit 818677a

File tree

166 files changed

+1387
-10
lines changed

Some content is hidden

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

166 files changed

+1387
-10
lines changed

1-setup/manual-setup/postgresql-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Download and install PostgreSQL: https://www.postgresql.org/download/ and the pg
88
(the script is tested with version PostgreSQL v 16.2 and pgAdmin 4 v 8.5)
99

1010
Open the pgAdmin tool and connect to the server with your credentials. Then open a new query and run the script in the university-postgresql.sql file as follows:
11-
- first, run the DROP DATABASE statament by itself (otherwise it will show an error)
11+
- first, run the DROP DATABASE statement by itself (otherwise it will show an error)
1212
- copy and run the CREATE DATABASE statement by itself
1313
- copy and run the rest of the script to create the tables.
1414

mysql-queries/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
1+
### Relevant Articles:
2+
- [How to Find the Engine for a Specific Table in MySQL?](https://www.baeldung.com/sql/mysql-find-table-storage-engine)
3+
- [Changing a Table’s Storage Engine in MySQL](https://www.baeldung.com/sql/mysql-change-table-storage-engine)
4+
- [Pattern Matching in MySQL](https://www.baeldung.com/sql/mysql-pattern-matching)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- specify the database
2+
USE University;
3+
4+
-- find the engine of University.Student
5+
-- using the information_schema.tables
6+
SELECT engine
7+
FROM information_schema.tables
8+
WHERE table_schema = 'University'
9+
AND table_name = 'Student';
10+
11+
-- find the engine of all the tables in University
12+
-- using the information_schema.tables
13+
SELECT table_name, engine
14+
FROM information_schema.tables
15+
WHERE table_schema = 'University'
16+
AND table_type = 'BASE TABLE'
17+
AND table_name = 'Student';
18+
19+
-- find the engine of University.Student
20+
-- using the information_schema.tables
21+
SHOW TABLE STATUS
22+
FROM University
23+
WHERE name = 'Student';

mysql-queries/mysql-images/images.sql

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
-- SQL Script for the article Images in MySQL
2+
3+
-- Change schema to University
4+
USE University;
5+
6+
-- Check max image size you can upload
7+
SHOW VARIABLES LIKE 'max_allowed_packet';
8+
SHOW VARIABLES LIKE 'secure_file_priv';
9+
10+
-- Grant access
11+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
12+
FLUSH PRIVILEGES;
13+
14+
-- DIRECT STORAGE
15+
16+
-- Create Tables
17+
CREATE TABLE DepartmentComplete
18+
(
19+
id INT PRIMARY KEY NOT Null,
20+
name VARCHAR (50),
21+
code VARCHAR (4),
22+
logo BLOB,
23+
UNIQUE (id)
24+
);
25+
26+
CREATE TABLE StudentComplete
27+
(
28+
id INT PRIMARY KEY NOT null,
29+
name VARCHAR (60),
30+
national_id BIGINT NOT Null,
31+
birth_date DATE,
32+
enrollment_date DATE,
33+
graduation_date DATE,
34+
gpa FLOAT,
35+
profile_pic BLOB,
36+
UNIQUE (id)
37+
);
38+
39+
-- Adding data for DepartmentComplete
40+
INSERT INTO DepartmentComplete (id, name, code, logo) VALUES
41+
(1, 'Computer Science', 'CS', LOAD_FILE('/usr/local/mysql/data/cs_logo.png')),
42+
(2, 'Electronics and Communications', 'EC', LOAD_FILE('/usr/local/mysql/data/ece_logo.png')),
43+
(3, 'Social Sciences', 'SS', LOAD_FILE('/usr/local/mysql/data/ss_logo.png')),
44+
(4, 'Computational Biology', 'CB', LOAD_FILE('/usr/local/mysql/data/cb_logo.png')),
45+
(5, 'Mathematics', 'MA', LOAD_FILE('/usr/local/mysql/data/ma_logo.png'));
46+
47+
-- Adding data for StudentComplete
48+
INSERT INTO StudentComplete (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa, profile_pic) VALUES
49+
(1001, 'John Liu', 123345566, '2001-04-05', '2020-01-15', '2024-06-15', 4, LOAD_FILE('/usr/local/mysql/data/john_pp.jpeg')),
50+
(1003, 'Rita Ora', 132345166, '2001-01-14', '2020-01-15', '2024-06-15', 4.2, LOAD_FILE('/usr/local/mysql/data/rita_pp.jpeg')),
51+
(1007, 'Philip Lose', 321345566, '2001-06-15', '2020-01-15', '2024-06-15', 3.8, LOAD_FILE('/usr/local/mysql/data/philip_pp.jpeg')),
52+
(1010, 'Samantha Prabhu', 3217165566, '2001-03-21', '2020-01-15', '2024-06-15', 4.9, LOAD_FILE('/usr/local/mysql/data/cs_logo.png')),
53+
(1011, 'Vikas Jain', 321345662, '2001-7-18', '2020-01-15', NULL, 3.3, LOAD_FILE('/usr/local/mysql/data/vikas_pp.jpeg'));
54+
55+
SELECT * from DepartmentComplete;
56+
57+
SELECT * from StudentComplete;
58+
59+
-- INDIRECT STORAGE
60+
-- Alter Table DepartmentComplete to drop logo
61+
ALTER TABLE DepartmentComplete
62+
DROP COLUMN logo;
63+
64+
-- Alter Table DepartmentComplete to add logo_path
65+
ALTER TABLE DepartmentComplete
66+
ADD logo_path VARCHAR (256);
67+
68+
-- Alter Table StudentComplete to drop profile_pic
69+
ALTER TABLE StudentComplete
70+
DROP COLUMN profile_pic;
71+
72+
-- Alter Table StudentComplete to add profile_pic_path
73+
ALTER TABLE StudentComplete
74+
ADD profile_pic_path VARCHAR (256);
75+
76+
77+
-- Update data
78+
UPDATE DepartmentComplete SET logo_path='/usr/local/mysql/data/cs_logo.png' WHERE code ='CS';
79+
UPDATE DepartmentComplete SET logo_path='/usr/local/mysql/data/ece_logo.png' WHERE code ='EC';
80+
UPDATE DepartmentComplete SET logo_path='/usr/local/mysql/data/ss_logo.png' WHERE code ='SS';
81+
UPDATE DepartmentComplete SET logo_path='/usr/local/mysql/data/cb_logo.png' WHERE code ='CB';
82+
UPDATE DepartmentComplete SET logo_path='/usr/local/mysql/data/ma_logo.png' WHERE code ='MA';
83+
84+
UPDATE StudentComplete SET profile_pic_path='/usr/local/mysql/data/john_pp.jpeg' WHERE name ='John Liu';
85+
UPDATE StudentComplete SET profile_pic_path='/usr/local/mysql/data/rita_pp.jpeg' WHERE name ='Rita Ora';
86+
UPDATE StudentComplete SET profile_pic_path='/usr/local/mysql/data/philip_pp.jpeg' WHERE name ='Philip Lose';
87+
UPDATE StudentComplete SET profile_pic_path='/usr/local/mysql/data/samantha_pp.jpeg' WHERE name ='Samantha Prabhu';
88+
UPDATE StudentComplete SET profile_pic_path='/usr/local/mysql/data/vikas_pp.jpeg' WHERE name ='Vikas Jain';
89+
90+
-- END
1.55 KB
Loading
1.67 KB
Loading
3.16 KB
Loading
2.63 KB
Loading
3.19 KB
Loading
5.02 KB
Loading

0 commit comments

Comments
 (0)