Getting started with MySQL-quick reference (1) _ MySQL

Source: Internet
Author: User
Tags mysql manual
MySQL Getting Started Guide-quick reference (1) I. SQL quick start


The following is an important quick reference for SQL. for SQL syntax and features added to standard SQL, Please query the MySQL manual.

1. create a table

A table is one of the most basic elements of a database. tables and tables can be independent or associated with each other. The basic syntax for creating a table is as follows:

Create table table_name

(Column_name datatype {identity | null | not null },

...)

The table_name and column_name parameters must meet the requirements of identifier in the user database. the parameter Ype YPE is a standard SQL type or a type provided by the user database. You must use the non-null clause to input data for each field.

Create table also has some other options, such as creating a temporary table and reading some fields from other tables using the select clause to form a new table. In addition, when creating a table, you can use the primary key, KEY, INDEX, and other identifiers to set certain fields as PRIMARY keys or indexes.

Note the following when writing:

List the complete fields in a pair of parentheses.

Field names are separated by commas.

Enter a space after the comma (,) between field names.

The last field name is not followed by a comma.

All SQL statements end with a semicolon.

Example:

Mysql> create table test (blob_col BLOB, index (blob_col (10 )));

2. create an index

Indexes are used to query databases. Generally, a database has a variety of index solutions, each of which is precise to a specific query class. Indexes can accelerate the database query process. The basic syntax for creating an index is as follows:

Create index index_name

On table_name (col_name [(length)],...)

Example:

Mysql> create index part_of_name ON customer (name (10 ));

3. change the table structure

When using a database, you sometimes need to change its table structure, including changing the field name or even changing the relationship between different database fields. The alter command can be implemented. its basic syntax is as follows:

Alter table table_name alter_spec [, alter_spec...]

Example:

Mysql> alter table t1 CHANGE a B INTEGER;

4. delete data objects

Many databases are dynamically used, and sometimes a table or index needs to be deleted. Most database objects can be deleted using the following command:

Drop object_name

Mysql> drop table tb1;

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.