mysql a basic summary

Create a database: create database <database name>;

Create a table: create tabke <table name> (<column name> <data type> <constraint (not null and the like)>, primary key (primary key));


integer: integer data type column of the memory, can not store decimal
char: storing the specified string, often a long string stored in the specified column as a char type, fixed-length string is stored in the column when!


Less than the length of the longest length of the string will be filled using the half-size space, e.g. char (. 8) Enter 'abc' time, will be 'abc'
which forms behind saved five half-size space;
Var- char: char and the same type, but in a variable-length string to save, not padded with a half-width space!


PRIMARY KEY (id) to the ID column set the primary key constraint, the so-called key, refers to combination of columns used in the particular data, the primary key is the ability
of a particular row of data columns, that is to say the one column as the primary key, you can pass the column the removal of specific data.


Table deleted: DROP TABLE <table name>; only to re-create the deleted table is not recoverable, then reinsert!
Add a column: ALTER TABLE <table name> ADD COLUMN <Column name> <field type>;
change the column name: ALTER TABLE <table name> CHANGE <column name> <new column name> <field type>;
remove columns: ALTER TABLE <table name> DROP cOLUMN <column name>;
can be added to the end of a determination command statement into COMMTI row!
To insert the data INSERT INTO <table name> VALUES ( '', '' ), ( '', '');
Change table name: RENAME TABLE <table name> to <table name>;

 

Query: SELETE <column name> FROM <table name>;
query with multiple columns ',' spaced numbers, in the same order and the query result column SELETE clause order.
Query all columns can use the '*' No. SELETE * FROM <table name>;
the display order if you use an asterisk, then you can not set the column, the column will be sorted by the CREATE TABLE statement definition.
Set an alias for the column:


SQL statement can use the AS keyword for a column alias settings
SELETE <column name> as <alias> FROM <table name>; a plurality of columns set an alias name separated by a comma! Chinese alias in double quotes, this is the result of the query is displayed above the column name alias you set!
Queries exclude duplicate rows Use the DISTINCT keyword: SELETE DISTINCT <column name> FROM <table name>; the use of multi-column name ',' separated number!
DISTINCT keyword can only be used before the first column name!

SELETE condition query
SELETE <column name> FROM <table> WHERE <condition expression>; multi-column names separated by a comma, can also display all columns with an asterisk!

Note NULL !! All calculations contain NULL, the result is NULL!

= Comparison operator <> (not equal) seems to be written! = (Equal to or greater than the use of less time to make a certain number range in the left and right of the equal sign on the right:> =, <=)

If you want to retrieve records NULL, the operator must use the IS NULL, IS NOT NULL is contrary operator!

 

NOT operator: We want to specify "No ~" negative criteria need to use <> operator or! =, And a NOT operator!

But he can not be used in combination of other conditions such as individual: SELETE <column name> FROM <table name> WHERE <column name>> = condition;

Together with the NOT condition calculation: SELETE <column name> FROM <table> WHERE NOT <column name>> = condition; less than equivalent to the condition data;

AND operator: the whole query when it was set up on both sides of the query conditions are true, the equivalent of "and"!

OR operator: in which both sides have the entire query only established when a query established, equivalent to "or"!

AND operator precedence OR operator! When you want to use complex queries, you can use parentheses intensive treatment!

Guess you like

Origin www.cnblogs.com/yeapy/p/11574142.html