Simple exercise of mysql database (create table, add, delete, modify and query data)

1. Create an employee table
    field attribute
    id integer (int)
    name string (varchar) (length 20)
    gender string (length 2)
    birthday date type (date)
    email string (length 10)
    remark string ( length is 50)

CREATE TABLE workers(
         sid INT,
         sname VARCHAR(20),
         gender VARCHAR(2),
         birthday DATE,
         email  VARCHAR(10),
         remark VARCHAR(50)
         );

 2. Modify the table exercise
    2.1 Add the age column on the basis of the employee table
    2.2 Modify the length of the email column to 50
    2.3 Delete the remark column
    2.4 Change the column name to username

ALTER TABLE workers ADD COLUMN age INT;
 ALTER TABLE workers MODIFY COLUMN email VARCHAR(50);
 ALTER TABLE workers DROP COLUMN remark;
 ALTER TABLE workers CHANGE COLUMN sname username VARCHAR(20);

 3 Practice data addition, deletion and modification operations on the employee table

  /* View all data in the employee table */
 SELECT * FROM workers;
 /* View the sid, username, age data of the employee table */
 SELECT sid,username,age FROM workers;
 /*View the username,age data of the employee table*/
 SELECT username,age FROM workers;
 /* Fill in the form with the following data */
 INSERT INTO workers VALUES(1,'Zhang Sanfeng','male','1367-10-21','[email protected]',102);
 INSERT INTO workers VALUES(2,'Dharma','Male','1227-4-15','[email protected]',54);
 INSERT INTO workers VALUES(3,'Mei Chaofeng','Female','1547-6-1','[email protected]',44);
 INSERT INTO workers VALUES(4,'Trisolaran','Unknown','3012-8-15','[email protected]',2000);
 INSERT INTO workers VALUES(5,'Super Saiyan','Male','1985-2-3','[email protected]',25);
 /* Change the username of the line with sid 4 to "Fliza" */
 UPDATE workers SET username = '弗利萨' WHERE sid = 4;
  /* delete the line with age 2000 */
 DELETE FROM workers WHERE age = 2000;
  /*Set the age of the row whose sid is 4 to 250*/
 UPDATE workers SET age = 250 WHERE sid =4;
  /*Change the username of the line with sid 5 to "Sun Wukong" and the age to 26*/
 UPDATE workers SET username = '孙悟空',age = '26' WHERE  sid  = 5;
 

 

Guess you like

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