Home > php教程 > PHP开发 > body text

Some simple sql statements compiled

高洛峰
Release: 2016-11-17 09:12:48
Original
1177 people have browsed it

I compiled simple sql statements a few days ago. It’s not quite complete, but I will sort it out slowly.

Please correct me if there is anything wrong, because I am also using these commands.

Thank you!

create database library name; create database

show databases; view database

use library name; go to database

show tables; view table data

drop database library name; delete database

create table epm [table name] (ename [column name] varchar (10), sal [column name] date, aaa [column name] int (2)); create table

desc table name; view the contents of the table

show create table table name G; View the table information (G can arrange the records vertically according to the fields)

drop table table name; delete the table

alter table table name modify column name varchar(20); modify the column field definition in the table

alter table Table name add column column name int(3); add a column in the table

alter table table name drop column column name; delete a column in the table

alter table table name change original column name new column name int(4) ; modify column The name and type

alter table table name add new column name date after original column name; add the new column name after the original column name

alter table table name modify original column name int(3) first; Modify the column and put it at the front

alter table original table name rename new table name; modify the name of the table

insert into table name (column name, column name) values('new record','new record'); to Insert records into the table

insert into table name values('new record','new record'); You can also not specify the field name, but the subsequent record order must be consistent with the field order

insert into table name values(new record, 'New record'), (New record, 'New record'); Insert two records at a time in order

update table name set field = record where field = 'record'; Change table content

select * from table name [ Column name]; View table content [View column content]

select field, field from table name; display the selected records

select distinct field from table name; query unique records

select * from table name where Field = 1; Query all records whose fields are 1

select * from table name where field = 1 and field <3000; Query records where two fields are 1 and greater than 3000

select * from table name order by field ;Display the field records from low to high

select * from table name order by field, field desc;The same first two records are displayed in order of high and low

select * from table name order by field limit 3;According to field The first 3 records sorted by high and low

select * from table name order by field limit 1,3; after sorting by field high and low, starting from the second record, 3 records are displayed

select field from table name; the total in the statistics table Record

select field 1, field 2 from table name group by field 1; display the data of field 1 and the total data. Only display the data of field 2

select field 1, field 2 from table name group by field 1 with rollup; display Data of all fields and total data

select field 1, field 2 from table name group by field 1 having field 2>1; count field records greater than 1

select sum(field),max(field),min(field ) from table name; total, maximum, and minimum records of statistical fields

select field 1, field 2 from table name 1, table name 2 where table name 1. field 3 = table name 2. field 3; display table 1 and The records in table 2 are displayed in field 3.

select * from table 1 where record in (select record from table 2); display all the fields in table 2 records


delete from table name where field =' Content';Delete the record of the content in the field in the table


Related labels:
sql
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!