sql Easy Tutorial

Speak dry, not long-winded, this tutorial is mainly based Mysql database, explain the basic use of the sql.

 

Database including add, delete, change, and other basic operations, the following is common to design sql statement:

 

First, check

1.select query syntax

SELECT column_name,column_name FROM table_name

Which is a database table column column_name Name field, table_name table name

Such as: select * from people representing a query all the columns in the table people to return all the records, * indicates all columns

Such as: select name, age from people represent people within a query table name for the column name and age

2.select distinct grammar, non-duplicate query

SELECT DISTINCT column_name,column_name FROM table_name

Add the DISTINCT keyword query results to be heavy, returns a unique value Note: when query multiple columns, multiple columns only the value of all the same, was considered to be the same result, they will not go heavy

3.where grammar

SELECT column_name,column_name FROM table_name WHERE column_name operator value

Such as: select * from people where name = 'Bob' represents the query people table, called records "Bob" in

4.and or operator and

and a plurality of connection or operator and query, where the syntax used with

Such as: select * from people where age> 20 and country = 'CN' age field indicates a value greater than the table 20 and Query ipeople country field is "CN" recording

 

Second, increase

1.insert into statement

INSERT INTO table_name VALUES (value1, value2, value3, ...), this syntax need to write the whole value of all the columns, otherwise unsuccessful

INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...)

Such as: insert into people (name, age) values ​​( 'John Doe', 30), represents a record is inserted into the people table, name is "Joe Smith", Age 30

 

Third, reform

1.update statement

UPDATE table_name SET column1=value1,column2=value2, ... WHERE some_column=some_value

Such as: update people set name = 'John Doe', age = '31 'where name =' John Doe ', represents the name is equal to "John Doe" is recorded within people table, to name "John Doe", to Age 31

 

Fourth, delete

1.delete statement

DELETE FROM table_name WHERE some_column=some_value

Such as: delete from people where name = 'John Doe', represents the table name is deleted people "San" recording

 

 

The above is the most simple sql grammar, be future updates!

 

 

 

Guess you like

Origin www.cnblogs.com/wwlstc/p/11302584.html