Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

participation activity 15.4.3: create a product table. write the sql to…

Question

participation activity 15.4.3: create a product table. write the sql to create a table named product with the following columns: - id - integer, primary key - name - variable-length string with maximum 40 characters - product_type - fixed-length string with maximum 3 characters - origin_date - year, month, and day - weight - precise decimal number with precision = 5 and scale = 1 place your create table statement before the insert and select statements. run your solution and verify the result table cont the three inserted rows. 1 -- write your create table statement here: 2 3 4 insert into product (id, name, product_type, origin_date, weight) values 5 (100, tricorder, con, 2020-08-11, 2.4), 6 (200, food replicator, fod, 2020-09-21, 54.2), 7 (300, cloaking device, spa, 2019-02-04, 177.0); 8 9 select * 10 from product;

Explanation:

Step1: Define table and primary key

Use CREATE TABLE, set id as INT PRIMARY KEY.

Step2: Add name column

VARCHAR(40) for variable-length string (max 40 chars).

Step3: Add product_type column

CHAR(3) for fixed-length string (max 3 chars).

Step4: Add origin_date column

DATE for year-month-day format.

Step5: Add weight column

DECIMAL(5,1) for precision=5, scale=1.

Answer:

CREATE TABLE product (
    id INT PRIMARY KEY,
    name VARCHAR(40),
    product_type CHAR(3),
    origin_date DATE,
    weight DECIMAL(5,1)
);

INSERT INTO product (id, name, product_type, origin_date, weight) VALUES
(100, 'Tricorder', 'CON', '2020-08-11', 2.4),
(200, 'Food replicator', 'FOD', '2020-09-21', 54.2),
(300, 'Cloaking device', 'SPA', '2019-02-04', 177.0);

SELECT * FROM product;