LU07.S02 - SQL-DDL: Table Management

Create a table called employees with the following columns:

  • employee_id (INT) as the primary key
  • first_name (VARCHAR 50)
  • last_name (VARCHAR 50)
  • hire_date (DATE)
  • salary (DECIMAL)
CREATE TABLE employees (
  employee_id INT PRIMARY KEY,
  first_name VARCHAR(50),
  last_name VARCHAR(50),
  hire_date DATE,
  salary DECIMAL(10,2)
);

Create a table called products to store inventory information. The table should have:

  • product_id (INT) as an auto-incrementing primary key
  • product_name (VARCHAR 100)
  • category (VARCHAR 50)
  • price (DECIMAL)
  • stock_quantity (INT)
CREATE TABLE products (
  product_id INT AUTO_INCREMENT PRIMARY KEY,
  product_name VARCHAR(100),
  category VARCHAR(50),
  price DECIMAL(10,2),
  stock_quantity INT
);

Add a new column email (VARCHAR 100) to the employees table.

ALTER TABLE employees
ADD COLUMN email VARCHAR(100);

Change the salary column's data type to FLOAT in the employees table.

ALTER TABLE employees
MODIFY COLUMN salary FLOAT;

Remove the stock_quantity column from the products table.

ALTER TABLE products
DROP COLUMN stock_quantity;

Completely remove the products table from the database.

DROP TABLE products;
English German

Volkan Demir

  • modul/m290/learningunits/lu05/loesungen/l02.txt
  • Zuletzt geändert: 2024/10/17 12:42
  • von vdemir