MySQL Basic operation

Source: Internet
Author: User

Create a database

1 Create database studentdb charset UTF8;
1 #Create a database2 CREATE Database Studentdb charset UTF8;3 #View the character set of a database4 Show Create database studentdb;5 #Create a data table6 CREATE TABLE students (7ID int auto_increment,#int represents a numeric type, char represents a string type8Name Char (32) notNull#Date represents the time type, and NOT NULL means cannot be null9Age int notNull#auto_increment represents self-incrementTenAddr char (32),#primary KEY (ID) represents ID as primary key OneRegister_date Date notNULL, APrimary key (ID));
 #   insert data into table  INSERT into students (name, Age,register_date) VALUES ( " zhangchen " Span style= "COLOR: #800000" > ", 21,"    2016-11-30   "); #insert into table name (field) VALUES (field corresponding value); 
#查询数据表
Select * from students where ID >3 and >24;
SELECT * from students  limit 7; #查询前7行
Select * FROM students  limit 7 offset 2; #从第3行起往后查7行 offset defaults to 0
SELECT * from students where register_date like "2016-09%"; #模糊查询
#修改表
Update students set Name= "Xuxiaoyu" where age=22; #update table name set [field = value],[field = value] where age = 22;
Delete from students where name = "Liruixin"; #删除数据
SELECT * FROM students order by register_date ASC; The fields behind #order by are sorted in ascending order
SELECT * FROM students order BY register_date Desc; The fields behind #order by are sorted in descending order
Select Name,count (*) from students group by name; #分组统计 Count the number of people with the same name in this table

#字段操作
ALTER TABLE students add sex enum ("M", "F") not null; Add a field
ALTER TABLE students drop addr #删除一个字段
ALTER TABLE students modify sex enum ("F", "M") null; ALTER TABLE students modify age int (a); #修改字段的属性

  

MySQL Basic operation

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.