Data Type
Integer: It can be expressed in decimal or hexadecimal notation.
Point: A floating point number is composed of a number plus a decimal point and a number. The two numeric sequences cannot be empty at the same time.
String: a character or number enclosed by single or double quotation marks. It must be a special character that can only be expressed by escape characters.
Value of date and time: for example, the value of 12:30:25 is based on year-month-day.
NUUL value: it is a non-typed value, indicating "null, nothing ".
________________________________________________________________________________
Mysql-h host name-u user name-p password // mysql login Run Command
DML data operation language
Select query select field name, field name,... (*) from table name where clause
Query the first 3 limit columns of "select field name", "field name",... (*) from table name "where clause unit price" 500
Select * from kehu, yewuyuan where ye_id = ke_id; query the ID of the customer to which the salesman belongs
Insert into badwolf (bad_id, bad_name) values (3, 'badbird '); insert
Update modify update badwolf (Table Name) set bad_name (column name) = 'badwolf ';
Updata badwolf (Table Name) set bad_name column name = 'Alex 'value where bad_name = 'badbird ';
Delete from badwolf (indicated) where bad_id = 2;
DCL Data Control Language
Grant control access permission
Revoke access permission
Ddl Data Definition Language
Create table database name;
Drop table database objects
Alter table defines its columns
When mysql enters the end of a statement, there must be a; sign at the end. -> Indicates that the input is not completed and the input is continued. \ C is used to cancel input.
//////////////////////////////////////// /////////////////////////////////
Value Type
TINYTIN very small integer BIGINT big integer
SMALLINT small integer FLOAT Single-precision floating point number
MEDIUMINT medium-sized integer DOUBLE-precision floating point number
INT standard integer DECIMAL floating point number of a string
CHAR fixed-length string VARCHAR variable-length string
Small BLOB of TINYBLOB
MEDIUMBLOB medium bolb longblob large BLOB
Small TEXT string of TINYTEXT
MEDIUMTEXT mid-text LONGTEXT large text string
ENUM enumeration: A column can be assigned to an enumeration member.
SET: A column can be assigned to multiple SET members.
Auto_increment
Columns that want to use this attribute should be defined as not null and as primary key or unique key.
Unsigned. This attribute disables negative values. The value range starts from zero, that is, the value range is moved forward.
//////////////////////////////////////// //////////////////////////////////////// ///
Create a database
Create database name; create a database with the specified name
For example, create database book. A database named book is created.
Show database list available databases on the server
Show table: displays the Database List
Use the database name, for example, use book;
Not null non-empty primary key auto_increment auto-Increment
Common integrity constraints
Primary key constraint (primary key) The primary key is the primary key, which uniquely identifies the field attribute.
The unique constraint of unique is that the data in a field or a set of fields is unique compared to the data in other rows in the table.
Not null non-null Constraint
Auto_increment integer column auto-increment 1
Default ult_value Constraints
Show structure operations
Database Table Name
Desc table name
Delete a database or table
Drop table name Delete table drop table if exists badbird; add if exists Delete non-existing table name no error
Drop database name delete database with the same name as if exists will not cause errors
//////////////////////////////////////// ////////////////////
Modify Table Structure
Syntax: alter table name action;
Note: action can be the following statement:
Add column name <Table creation Statement> [first | after column name]
Add primary key (column name) to add a primary key to the table. If the primary key already exists, an error occurs.
Alter column name set default value can change the default value of the specified Column
----------------------------------------------------------
Later table name add insert such as column name varchar (attribute) first (Before) | after (after) add column name
Change old column name new column name <Table creation Statement> [first | after column name]
You can change the column type and column name. If the original column name is the same as the new column name, the change and modify functions the same.
-----------------------------------------------------------
Modify column name <Table creation Statement> [first | after column name]
Alter table badbird (table Name) badtitle (column) modif varchar (attribute );
Alter table badbird (table Name) change badtitle (column) bad_sad (changed name) varchar (attribute) not null (no blank );
Drop column name // you can delete a column.
Drop primary key // you can delete a primary key.
Drop index index_name; // you can delete an index.
Delete column: alter table badbird (table Name) drop badtitle;
Rename as new table name // you can change the table name
Alter table badbird (table Name) rename badwolf (table Name );
Insert record operation
Syntax:
Insert into Table Name (field name, field name,...) values (field value, field value ,...);
Example: insert into badwolf (bad_id, bad_name) values (3, 'badbird '); insert
If the field name is not followed by the table name, the value is added to all fields by default. In addition, the string value should be enclosed by 'or '.
Add multiple entries: insert into badwolf values (1, 'badbird '), (2, 'badbird'), (4, 'badbird ');
Change Record operation
Syntax:
Update table name set column name = data value where clause;
For example, update badwolf (Table Name) set bad_name (column name) = 'badwolf ';
------------------------------------------------------------------
The where clause is a judgment statement used to set conditions. Only matching rows are updated. If the where clause is not included, all rows are updated.
Delete record operation Syntax: delete from table name where clause;
For example, delete from badwolf (indicating) where bad_id = 2; the judgment condition for deleting all IDs = 2 can be attached.