Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| modul:m290:learningunits:lu05:loesungen:l03 [2024/09/27 14:53] – angelegt vdemir | modul:m290:learningunits:lu05:loesungen:l03 [2024/10/17 12:41] (aktuell) – vdemir | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== | + | ====== |
| ===== Assignments & Solutions ===== | ===== Assignments & Solutions ===== | ||
| Zeile 12: | Zeile 12: | ||
| ); | ); | ||
| - | ==== B: FOREIGN KEY ==== | + | ==== B: AUTO INCREMENT |
| - | Create | + | Create a table products where each product has an automatically generated, unique product_id using the AUTO_INCREMENT feature. Include columns for product_name and price. |
| - | CREATE TABLE departments | + | CREATE TABLE products |
| - | | + | |
| - | | + | |
| + | price DECIMAL(10, | ||
| ); | ); | ||
| - | |||
| - | CREATE TABLE employees ( | ||
| - | employee_id INT PRIMARY KEY, | ||
| - | employee_name VARCHAR(100), | ||
| - | department_id INT, | ||
| - | FOREIGN KEY (department_id) REFERENCES departments(department_id) | ||
| - | ); | ||
| - | |||
| ==== C: NOT NULL ==== | ==== C: NOT NULL ==== | ||
| Zeile 36: | Zeile 29: | ||
| ); | ); | ||
| - | ==== D: AUTO INCREMENT ==== | + | ==== D: UNIQUE ==== |
| - | Create a table products where each product has an automatically generated, unique product_id using the AUTO_INCREMENT feature. Include columns for product_name and price. | + | |
| - | + | ||
| - | CREATE TABLE products ( | + | |
| - | product_id INT AUTO_INCREMENT PRIMARY KEY, | + | |
| - | product_name VARCHAR(100), | + | |
| - | price DECIMAL(10, | + | |
| - | ); | + | |
| - | + | ||
| - | + | ||
| - | ==== E: UNIQUE ==== | + | |
| Create a table users that has a user_id (INT) and email (VARCHAR). Ensure that no two users can have the same email address by applying the UNIQUE constraint to the email column. | Create a table users that has a user_id (INT) and email (VARCHAR). Ensure that no two users can have the same email address by applying the UNIQUE constraint to the email column. | ||
| Zeile 53: | Zeile 36: | ||
| email VARCHAR(100) UNIQUE | email VARCHAR(100) UNIQUE | ||
| ); | ); | ||
| - | |||
| | | ||
| + | ==== E: FOREIGN KEY ==== | ||
| + | Create two tables: one called departments and the other called employees. Each department has a department_id as its primary key. In the employees table, include a column called department_id as a foreign key that references the departments table. Ensure that every employee is linked to a department. | ||
| + | CREATE TABLE departments ( | ||
| + | department_id INT PRIMARY KEY, | ||
| + | department_name VARCHAR(50) | ||
| + | ); | ||
| + | |||
| + | CREATE TABLE employees ( | ||
| + | employee_id INT PRIMARY KEY, | ||
| + | employee_name VARCHAR(100), | ||
| + | department_id INT, | ||
| + | FOREIGN KEY (department_id) REFERENCES departments(department_id) | ||
| + | ); | ||
| ===== Vocabulary ===== | ===== Vocabulary ===== | ||
| ^ English ^ German ^ | ^ English ^ German ^ | ||
| - | | ... | ... | | + | | to apply| anwenden| |
| - | | ... | ... | | + | |
| ---- | ---- | ||
| [[https:// | [[https:// | ||