DDL table and library management language

Management of DDL tables and libraries

#1. Create table dept1

NAME   NULL?  TYPE

id     INT(7)

NAME       VARCHAR(25)

 

 

USE test;

 

CREATE TABLE dept1(

    id INT(7),

    NAME VARCHAR(25)

   

 

);

#2. Insert the data in the table departments into the new table dept2

 

CREATE TABLE dept2

SELECT department_id,department_name

FROM myemployees.departments;

 

 

#3. Create table emp5

NAME   NULL?  TYPE

id     INT(7)

First_name VARCHAR (25)

Last_name  VARCHAR(25)

Dept_id       INT(7)

 

CREATE TABLE emp5(

id INT(7),

first_name VARCHAR(25),

last_name VARCHAR(25),

dept_id INT(7)

 

);

 

 

#4. Increase the length of the column Last_name to 50

 

ALTER TABLE emp5 MODIFY COLUMN last_name VARCHAR(50);

#5. Create employees2 from table employees

 

CREATE TABLE employees2 LIKE myemployees.employees;

 

#6. Drop table emp5

DROP TABLE IF EXISTS emp5;

 

#7. Rename table employees2 to emp5

 

ALTER TABLE employees2 RENAME TO emp5;

 

#8. Add new column test_column in table dept and emp5 and check the operation

 

ALTER TABLE emp5 ADD COLUMN test_column INT;

#9. Directly delete the column dept_id in the table emp5

DESC emp5;

ALTER TABLE emp5 DROP COLUMN test_column;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325298821&siteId=291194637