Basic use of MySQL

Source: Internet
Author: User

Sql
DDL: Data definition language CREATE DROP ALTER
DML: Data Manipulation language SELECT INSERT UPDATE DELETE
DCL: Data Control Language GRANT REVOKE COMMIT ROLLBACK

The most basic (build a library, build a table)
SHOW DATABASES;
Use database name;
CREATE database name;
DROP database name;
SHOW TABLES; <<<<<<<< need to switch databases first
CREATE TABLE [library name.] Table Name (Field 1 property, Field 2 property,......)
CREATE TABLE [library name.] Table name like [library name.] Table name <<<<<<< Create a new table by a table in a library
Craete TABLE [library name.] Table name as SELECT field 1, Field 2 .... from [library name.]    Table name; >>>>>>>>>>>
DROP TABLE [library name.] Table name
DESC [library name.] Table name


Alter command
Role: Modify the table's field properties
1. Add a new field
Format: ALTER table name ADD field property

2. Delete fields
Format: ALTER table name DROP field

3. Modify field names
Format: ALTER table name change field New Field property

4. Add Index
Set PRIMARY key: ALTER table name ADD PRIMARY key (field)
Set index: ALTER table name ADD index [index name] (field)
Set UNIQUE constraint: ALTER table name ADD unique [index name] (field)

5. Add foreign keys
Format: ALTER table name 1 ADD froeign KEY (field) REFERENCES Table 2 (field)

6. Delete Index
Delete primary key: ALTER table name DROP PRIMARY key
Delete index: ALTER table name DROP index name
Delete foreign key: ALTER table name DROP FOREIGN key


Insert command
Role: Adding records
Format: INSERT into table name (Field 1, Field 2,.....) Values (value 1, value 2 ...), (value 1, value 2 ...),......

Delete one or more records
DELETE from table name condition


Update command
Role: Modifying data in a table
Attention:
UPDATE is typically used in conjunction with where, order by, and limit

Format:
UPDATE table name SET field 1= value, field 2= value ... [Where to judge condition]
UPDATE table name SET field 1= value, field 2= value ... [ORDER BY judging condition]

Ps: Welcome To correct me, thank you.

Basic use of MySQL

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.