First time MySQL

Source: Internet
Author: User

mtsql: Common codeCreate TableCeShi1 (Uidvarchar( -)Primary Key, PWDvarchar( -), Namevarchar( -) Nationvarchar( -),     Foreign Key(Nation)ReferencesNation (Code)//Add foreign key relationship//Referencesreferences) Write query statements that require attention:1. When creating a table, do not write a comma after the last column. 2if more than one statement is executed together, be careful to separate the statements with semicolons. 3. Write code all symbols are half-width. Relational database: There are several key words to create a table between tables and tables;1. PRIMARY key:Primary Key2. Non-null: not NULL3Self-growth column: Auto_increment4. Foreign key relationships:Foreign Key(column name)Referencestable name (column name) CRUD operations: Adding and deleting changes1. Add Data:Insert  intoTable nameValues(', ', ', ', ') requires that the values in the parentheses are the same as the number of columns in the tableInsert  intoInfo (Code,name)Values(', ') adds the value of the specified column2. Modify the data:UpdateInfoSetName=' Zhang San 'whereCode=' P001 '3. Delete data:Delete  fromInfowhereCode=' P001 '4. Querying data:1. General Enquiry: Check all theSelect * fromInfo #查所有数据SelectCode,name fromInfo #查指定列2. Conditional QuerySelect * fromInfowhereCode=' p001 ' #一个条件Select * fromInfowhereName=' Zhang San ' andNation=' n001 ' #两个条件并的关系Select * fromInfowhereName=' Zhang San 'orNation=' n001 ' #两个条件或的关系3. Sort QueriesSelect * fromInfoOrder  byBirthday #默认升序排列asc If you want to sort in descending orderdescSelect * fromCarOrder  byBrand,oildesc#多列排序4. Aggregate functionsSelect Count(*) fromInfo #取个数Select sum(Price) fromCar #查询price列的和Select avg(Price) fromCar #查询price列的平均值Select Max(Price) fromcar #查询 The maximum value of the price columnSelect min(Price) fromcar #查询 The minimum value of the price column5. Paged QuerySelect * fromcar limit n,m #跳过n条数据取m条数据6. Group QueriesSelectBrand fromCarGroup  byBrand #简单分组查询SelectBrand fromCarGroup  byBrand having Count(*)>2#查询系列里面车的数量大于2的系列7. Go to re-querySelect distinctBrand fromCar8. modifying column namesSelectBrand asSeries fromCar9. Fuzzy QuerySelect * fromCarwhereName like' Audi%’ #%represents any number of charactersSelect * fromCarwhereName like' _ Dee%' # _ represents a characterTen. Discrete queriesSelect * fromCarwhereCodeinch(' c001 ', ' c002 ', ' c003 ', ' c004 ')Select * fromCarwhereCode not inch(' c001 ', ' c002 ', ' c003 ', ' c004 ')

First time MySQL

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.