Database MySQL common command review

Source: Internet
Author: User

--View Database

show databases;

--Create a database
Create database ' name ';

--Delete Database
drop database name ';

--Select Library
Use ' Library name ';

--View your current library
Select Database ();

--View All tables
Show tables;

--Delete Table
drop table name;

--View table structure
DESC table name;

--View the Build table statement
Show create table ' name ';

--Clear Table data
TRUNCATE table ' name ';

--PRIMARY key
PRIMARY KEY

--Cannot be empty
Not NULL

--Can be empty
Null

-The only
UNIQUE

--Self-increment
Auto_increment

--Default value
DEFAULT

--Unsigned
UNSIGNED

--0 padding
Zerofill

--Modify Table name
ALTER table Old table name RENAME [to] new table name

--Modify the data type of the field
ALTER Table name MODIFY property name data type [integrity constraint]

--Modify field names
ALTER table name change old table name new property name new data type

--Add Field
ALTER Table name ADD property 1 data type [integrity data constraint][first | After property name 2]

--delete Field
ALTER Table Table name DROP property name

--Modify the position of the field
ALTER Table name MODIFY property name 1 data type First | After property name 2

--Modify the table's storage engine
ALTER table name engine= storage Engine

--PRIMARY Key index
PRIMARY KEY

--Unique index
UNIQUE

--General Index
INDEX

--Create an index format
Primary KEY (' ID ')--set ID as primary key

Unique Uni_name (' name ')--set name to unique index Uni_name alias

Index Index_tel (' Tel ')--General index Index_tel alias

--Create the index after the table is built
ALTER table name ADD PRIMARY KEY (' field name ');

ALTER table name ADD UNIQUE (' Field name ')

ALTER table name ADD INDEX index_name (' Field name ')

--View Index
SHOW INDEXES from table name

--Delete primary key index
--Delete the self-increment first
ALTER table name MODIFY self-increment field INT UNSIGNED not NULL
--then delete the primary key
ALTER table name DROP PRIMARY KEY

--delete unique index and normal index
DROP index index name on table name


--Add data to the database
INSERT into table name (field name 1, field Name 2, field 3) VALUES (value 1, value 2, value 3);

--Modify data
UPDATE table name SET field name WHERE [condition]

--Delete data
DELETE from table name WHERE [condition]

--Link Database
Mysqli_connect (' hostname ', ' username ', ' password ', ' library name ');

--Set character sets
Musqli_set_charset ();

--Judging the error message
Mysqli_error ();

--Judging the error number
Mysqli_errno ();

--Launch SQL statement
Mysqli_equry ();

--Parse the variable into an associative array
Mysqli_fetch_assoc ();

--Returns the number of result sets
Mysqli_num_rows ();

--Affected rows
Mysqli_affected_rows ();

--Gets the ID of the last insertion
Mysql_free_result ();

Database MySQL common command review

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.