"MySQL" MySQL common build Table statement

Source: Internet
Author: User

Reference: http://blog.csdn.net/kakane/article/details/7401111

"1" Create Employee profile form
Requirements field: Employee employee number, employee name, gender, salary, email, entry time, department.


"2" reasonable choice of data type and field modifiers, requires not null,auto_increment, primary key and so on.

[SQL]View PlainCopy
  1. --
  2. --Make by Kakane
  3. --
  4. DROP TABLE IF EXISTS ' workers_info ';
  5. CREATE TABLE ' Workers_info ' (
  6. ' ID ' int (one) not NULL auto_increment,
  7. ' Workername ' varchar (not NULL) ,
  8. ' Sex ' enum (f,m,s),
  9. ' Salary ' int (one) DEFAULT ' 0 ',
  10. ' Email ' varchar (+),
  11. ' Employeddates ' date,
  12. ' Department ' varchar (+),
  13. PRIMARY KEY (' id ')
  14. ) Engine=myisam DEFAULT Charset=utf8;
  15. mysql> alter table workers_info ADD sex enum (' F ',' M ',' S ');
[SQL]View PlainCopy

"3" View the structure of the table

[HTML]View PlainCopy
    1. MySQL> desc workers_info;

"4" added QQ and Tel fields, require tel field before email, require the entry time is the last field

mysql> ALTER TABLE workers_info ADD Tel varchar (all) after salary;

[SQL]View PlainCopy
    1. mysql> ALTER TABLE workers_info ADD qq int;
    2. ALTER TABLE workers_info MODIFY employeddates date after QQ;


"5" Change the email field to mailbox
mysql> ALTER TABLE workers_info Change email mailbox varchar (30);

"6" adds 10 records to the table
Mysql> INSERT into workers_info values (NULL, ' Xing ', 10000, ' 1598232123 ', ' [email protected] ', ' Yanfa ', 736019646,20121221);

[SQL]View PlainCopy
    1. Mysql> INSERT into workers_info (workername,salary,tel,mailbox,department,qq,employeddates) values (  ' Xing ', 10000,' 1598232123 ',' [email protected] ',' Yanfa ', 736019646,20121221);


"7" Modify the Tel and mailbox of two records
Mysql> UPDATE workers_info SET mailbox = ' [email protected] ' WHERE id = 14;

[SQL]View PlainCopy
    1. mysql> UPDATE workers_info SET mailbox = ' [email protected] ', tel=' 1246543423 ' where id = 13;


"8" view added records
Mysql> select * from Workers_info;

"9" View name and entry time record
Mysql> select Workername,employeddates from Workers_info;

"10" inquiry into the employment time before 2003

[SQL]View PlainCopy
    1. Mysql> SELECT * from workers_info where year (Employeddates) < 2003;
[SQL]View PlainCopy

"11" Search for the highest and lowest employee names

[SQL]View PlainCopy
    1. Mysql> SELECT * from workers_info ORDER by salary limit 1;
    2. Mysql> SELECT * from workers_info ORDER by salary desc LIMIT 1;


"12" Query average salary

[SQL]View PlainCopy
    1. mysql> Select avg (Salary) from Workers_info;
[SQL]View PlainCopy

"13" Statistics of male employees, number of female employees

[SQL]View PlainCopy
    1. mysql> Select count (male) from workers_info where sex="M";
    2. mysql> Select count (male) from workers_info where sex="M";


"14" is sorted according to the time of entry and shows the first 5 employees ' names

[SQL]View PlainCopy
      1. Mysql> SELECT * from workers_info ORDER by employeddates limit 5;

"MySQL" MySQL common build Table statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.