6, mysql data manipulation

1, mysql create a data table

Create a mysql table data requires the following information: name of the table, the table field name, define each table field

语法:create table table_name (column_name,column_type);

For example:

create table if not exist `runoob_tb1`(

`runoob_id` int unsigned auto_increment,

`runoob_title` varchar(100) not null,

`sunmission_date` data,

primary key (`runoob_id`)

) engine=InnoDB default charset=utf8;

Resolution:

Non-empty field: nut null

auto_increment attributes defined as increment, typically for the primary key, the value will be automatically increased by 1

keyword is used to define the primary key columns of the primary key may be used to define a multi-column primary keys, columns separated by commas

engine setting storage engine, charset set encoding

2, create a table from the command prompt

mysql -u root -p

user runoob;

 

mysql> CREATE TABLE runoob_tbl(
   -> runoob_id INT NOT NULL AUTO_INCREMENT,
   -> runoob_title VARCHAR(100) NOT NULL,
   -> runoob_author VARCHAR(40) NOT NULL,
   -> submission_date DATE,
   -> PRIMARY KEY ( runoob_id )
   -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.16 sec)

Note: MySQL command terminator is the semicolon ;.

Note: -> is a newline identity, do not copy.

3, mysql delete data table

drop table runoob_tb1;

4, mysql insert data

INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN );

5, mysql query data

select * from table_name;

6, mysql where words

7, mysql update update

update table_name set field1='value1' ,field2='value2' where field3='value3';

8, mysql delete statement

delete from table_name where ;

9, mysql like words

select *from table_name where field1 like 'aa%';

10 、mysql union

UNION statement: display data for the different tables out of the same column of the query; (duplicate data not included)

UNION ALL statement: display data for the different tables out of the same column of the query; (including duplicates)

Use the form below:

SELECT column names FROM table name UNION SELECT column names FROM table name where condition ORDER BY column name;

SELECT column names FROM table name UNION ALL SELECT column names FROM table name for condition Condition WHERE  the ORDER BY column name;

11, mysql sorting

order by

12, mysql grouping

group by

13, mysql connection using

INNER JOIN (the connection, or equivalent connection): Get Records matching fields in the relationship between two tables.

LEFT JOIN (left connection): Get the left table all records, even if no record corresponding to the right table matching.

RIGHT JOIN (Right link): a LEFT JOIN contrast, all records in the table for acquiring the right, the left table even if there is no corresponding matching records.

14, mysql null value processing

IS NULL: When the value of the column is NULL, the operator returns true

IS NOT NULL: column when the value is not NULL, the operator returns true

<=>: comparison operators (= different from the operator), returns true when comparing the two values ​​are equal or are NULL

 

Guess you like

Origin www.cnblogs.com/myheart-new/p/11947486.html