use OrdersDB;
# 1
select *
from Orders into outfile '/var/lib/mysql-files/Orders123.csv' fields terminated by ','
enclosed by '"' lines terminated by '\n';

CREATE TABLE NewOrder (
    ONUM int NOT NULL,
    AMT DECIMAL(8, 2) NOT NULL,
    ODATE DATE,
    SNUM int,
    CNUM int,
    PRIMARY KEY (ONUM),
    FOREIGN KEY (SNUM) REFERENCES Salespeople (SNUM),
    FOREIGN KEY (CNUM) REFERENCES Customers (CNUM)
);

LOAD DATA INFILE '/var/lib/mysql-files/Orders.csv' INTO
TABLE NewOrder FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (
    ONUM,
    AMT,
    ODATE,
    SNUM,
    CNUM,
    @dummy
);

CREATE TABLE NewSalespeople AS SELECT * FROM Salespeople;

CREATE TABLE NewCustomers LIKE Customers;

INSERT INTO NewCustomers SELECT * FROM Customers;

# 2

use Team;

ALTER TABLE member ADD birthday DATE DEFAULT NULL;

ALTER TABLE member ADD salary DECIMAL(7, 2) NOT NULL DEFAULT 7999.99;

load data infile '/var/lib/mysql-files/new_members.csv' into
table member fields terminated by ',' enclosed by '"' lines terminated by '\n' ignore 1 lines (
    m_id,
    mname,
    birthday,
    mcity,
    mmail,
    salary
);

# 3

select * from member into outfile '/var/lib/mysql-files/AllMembers.csv' 
fields terminated by ',' enclosed by '"' lines terminated by '\n';

# 4

CREATE TABLE backup_member AS SELECT * FROM member;

show create table backup_member;

DESCRIBE backup_member;

SELECT * FROM backup_member;

# 5

create database Orders_backup;

CREATE TABLE IF NOT EXISTS Orders_backup.member LIKE member;

INSERT INTO
    Orders_backup.member
SELECT *
FROM member
WHERE
    birthday IS NULL;

DESCRIBE Orders_backup.member;

SELECT * FROM Orders_backup.member;