SQL statement-add data-modify statement-delete statement-connect query

One. Add statement

Basic format: insert into table name ...

Method 1 : Specify the field and value, as long as the field and value correspond. Independent of order

insert into heroes (field, field, ...) values ​​(value, value, ...) 
insert into heroes (nickname, age, name) values ​​('Fear of the Void', 98, 'Cogas')

Method 2: It is related to the order, because no field is specified, the value must be all values, and the order must be consistent with the order of the fields in the table

insert into heroes values ​​(null, 'Laxe', 'Glory Girl', null, 'Dynamic Lightwave', 28, 'Female')

== Method three ==: Use the set to set the new data value, there is no order relationship

insert into heroes set field = value, field = value, .... 
insert into heroes set name = '李青', nickname = 'blind monk', skill = '一 库'

two. Modify statement

format:

`update table name set field 1 = value 1, field 2 = value 2, ... where modify condition`

Modify which (several) data fields in the table have field 1 = value 1 ...


-Add conditions to modify update heroes set age = 28, skill = 'Roll on the ground' where id = 19 
-If no conditions are specified, all rows will be modified 
update heroes set sex = 'Demon'

Third, delete the data

Format: delete from table name where == delete condition ==

Note: All data will be deleted without specifying conditions ==

-delete from heroes where id = 19 
-without conditions, all data will be deleted, dangerous operation 
-delete from heroes

Four, connect query

Join query means to join two or more tables together to query. The results of the query will generally contain all the results of the two tables

-select * from table 1 join table 2 on relationship [join table 3 on relationship] 
-inner join 

, the result of the query is the intersection of two tables select * from boy join girl on boy.flower = girl.flower 
-left Connect 
-select * from boy left join girl on boy.flower = girl.flower 
-Connect right 
-select * from boy right join girl on boy.flower = girl.flower

 You can define an alias for the table during the query

-Define the alias for boy as table b through boy b. In the following relationship, you can use b instead of boy 
select * from boy b join girl g on b.flower = g.flower

You can define an alias for a field during the query (not just the connection query, but the query you learned earlier):

-- select id i,name n from heroes limit 2
select 
	b.name bn,
	b.flower bf,
	g.name gn,
	g.flower gf 
from boy b 
join girl g 
on b.flower = g.flower

summary:

  • Inquire

    select * from heroes [where condition] [order by field ordering rule] [limit start position, length]

  • Add to

    insert into heroes set field = value, field = value, ...

  • modify

    update heroes set field = value, field = value, ... [where condition]

  • delete

    delete from heroes where 条件

 

Guess you like

Origin www.cnblogs.com/star-meteor/p/12754875.html