From 11d76cae66c8fae6778caed8bb253d637494c9be Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 27 Oct 2023 19:06:52 +0200 Subject: [PATCH] added tasks from 27.10.2023 --- .idea/.gitignore | 6 ++++++ tasks/03-set-and-enums.sql | 21 +++++++++++++++++++++ tasks/05-create-table.sql | 21 +++++++++++++++++++++ tasks/task-6-1-1.sql | 29 +++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 tasks/03-set-and-enums.sql create mode 100644 tasks/05-create-table.sql create mode 100644 tasks/task-6-1-1.sql diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..8bf4d45 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/tasks/03-set-and-enums.sql b/tasks/03-set-and-enums.sql new file mode 100644 index 0000000..54d91ec --- /dev/null +++ b/tasks/03-set-and-enums.sql @@ -0,0 +1,21 @@ +CREATE SCHEMA task03; +USE task03; + +CREATE TABLE Colors ( + colorName SET ('red', 'green', 'blue') +); + +/* can have multiple values at once and be empty */ +INSERT INTO Colors VALUES ('red'); +INSERT INTO Colors VALUES ('green'); +INSERT INTO Colors VALUES ('blue,green'); +INSERT INTO Colors VALUES (''); + +CREATE TABLE Animals ( + name ENUM ('Dog', 'Cat', 'Bird') +); + +/* cannot be empty or multiple variants at once */ +INSERT INTO Animals VALUES ('Dog'); +INSERT INTO Animals VALUES ('Cat'); +INSERT INTO Animals VALUES ('Bird'); \ No newline at end of file diff --git a/tasks/05-create-table.sql b/tasks/05-create-table.sql new file mode 100644 index 0000000..ce0daab --- /dev/null +++ b/tasks/05-create-table.sql @@ -0,0 +1,21 @@ +CREATE SCHEMA employees; + +DROP TABLE IF EXISTS employees.Employee; + +CREATE TABLE employees.Employee ( + id BINARY(16) PRIMARY KEY, /* automatically NOT NULL */ + name NVARCHAR(64) NOT NULL, /* this field is mandatory */ + email VARCHAR(32) /* optional field */ +); + +INSERT INTO employees.Employee SET + id = UUID_TO_BIN(UUID()), + name = 'Hans Jürgen Peter'; + +INSERT INTO employees.Employee VALUES ( + id = UUID_TO_BIN(UUID()), + name = 'Guten Tag', + email = 'klaus@doof.de' +); + +SELECT hex(id), name, email FROM employees.Employee; diff --git a/tasks/task-6-1-1.sql b/tasks/task-6-1-1.sql new file mode 100644 index 0000000..9a3dfee --- /dev/null +++ b/tasks/task-6-1-1.sql @@ -0,0 +1,29 @@ +CREATE SCHEMA cities; + +CREATE TABLE cities.Cities ( + id BINARY(16) NOT NULL, /* UUID */ + name NVARCHAR(32) NOT NULL, + countryName CHAR(2) CHARACTER SET ASCII NOT NULL, /* country code such DE, US, CH, ... */ + countryCode NUMERIC(3) NOT NULL, /* numeric country code */ + url VARCHAR(100), + history MEDIUMTEXT, + icon BLOB +); + +INSERT INTO cities.Cities SET + id = UUID_TO_BIN(UUID()), + name = 'Berlin', + countryName = 'DE', + countryCode = 268, + url = 'https://www.berlin.de/en/', + history = 'German Empire, 3rd Reich, split into two, reunited :)'; + +INSERT INTO cities.Cities SET + id = UUID_TO_BIN(UUID()), + name = 'Berlin', + countryName = 'US', + countryCode = 840, + url = 'https://www.berlinnh.gov/', + history = 'some weird country. They like guns'; + +SELECT name, countryName, countryCode, url, history FROM cities.Cities ORDER BY countryName; \ No newline at end of file