Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
modul:m290:learningunits:lu05:loesungen:l03 [2024/09/27 14:53] – angelegt vdemirmodul:m290:learningunits:lu05:loesungen:l03 [2024/10/17 12:41] (aktuell) vdemir
Zeile 1: Zeile 1:
-====== LU06.S03 - SQL-DDL: Constraint Management ======+====== LU07.S03 - SQL-DDL: Constraint Management ======
  
 ===== Assignments & Solutions ===== ===== Assignments & Solutions =====
Zeile 12: Zeile 12:
   );   );
  
-==== B: FOREIGN KEY ==== +==== B: AUTO INCREMENT ==== 
-Create two tables: one called departments and the other called employees. Each department has department_id as its primary key. In the employees table, include a column called department_id as a foreign key that references the departments tableEnsure that every employee is linked to a department.+Create a table products where each product has an automatically generatedunique product_id using the AUTO_INCREMENT featureInclude columns for product_name and price.
  
-  CREATE TABLE departments +  CREATE TABLE products 
-    department_id INT PRIMARY KEY, +    product_id INT AUTO_INCREMENT PRIMARY KEY, 
-    department_name VARCHAR(50)+    product_name VARCHAR(100)
 +    price DECIMAL(10,2)  
   );   );
- 
-  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,2)   +
-  ); +
- +
- +
-==== 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 applyanwenden|
-| ... | ... |+
  
  
 ---- ----
 [[https://creativecommons.org/licenses/by-nc-sa/4.0/|{{https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png}}]] Volkan Demir [[https://creativecommons.org/licenses/by-nc-sa/4.0/|{{https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png}}]] Volkan Demir
  • modul/m290/learningunits/lu05/loesungen/l03.1727441605.txt.gz
  • Zuletzt geändert: 2024/09/27 14:53
  • von vdemir