Basic knowledge of MySQL database operation (1/4)

Source: Internet
Author: User
Tags table name create database

1. Create a database.

The CREATE DATABASE statement is created in MySQL. The format is as follows:

Create DATABASE db_name; Db_name is a database name and must be a valid name. The following provisions are provided:

A. Cannot have duplicate names with other databases.

B. Names can be arbitrary letters, Arabic numerals, underscores or "$". You can start with any of these characters, but you can't use a separate number, which can be confusing with numbers.

C. The longest name can consist of 64 characters (including tables, columns, and indexes), while aliases can be up to 256 characters long.

D. You cannot use the MySQL keyword as the database name and table name.

PS: Execution process: When creating a database, first connect MySQL server, username is root, password is root, and then write "CREATE DATABASE db_name" SQL statement, the database was created successfully.

2. Select the database.

Use statement to select a database to make it the current default database. The format is as follows:

Use db_name;

3. Delete the database.

Deleting a database uses the Drop DB statement. The format is as follows:

Drop DATABASE db_name PS. You should use caution for deleting databases. Once all the structures and data in the database are deleted, there is no possibility of recovery unless there is a backup in the database.

<mysql Database Tables >

The above will finish the operation of the database, the following about the database, the operation of the table. MySQL database table operations include creating, viewing, modifying, renaming, and deleting.

1. Create a table.

The CREATE table is created with the creation Table statement. The format is as follows:

Create [temporary] table [if not EXISTS] data table name [(Create_definition,...)] [Table_options] [Select_statement] A. Temporary, which means that if you use this keyword, you create a temporary table.

B. If not exists, which is used to avoid MySQL-reported errors when tables are created.

C. create_definition, which is the list Properties section of the table. MySQL requires that a table contain at least one column when creating a table.

The create_deifnition format is as follows:

           

The code is as follows Copy Code

Col_name type [NOT NULL] [default Default_value] [auto_increment] [primary key] [reference_definition]

Col_name: Field name. Type: field type. Not null|null: Indicates whether the column allows null values. Not NULL indicates that null values are not allowed. Default Default_value: Represents the defaults.

Auto_increament: Represents the default value. Primary key: Indicates whether the primary key, a table can have only one primary key. If there is no primary key, and some applications require primary key,

The server returns the first unique key with no null column as the primary key.

D. table_option, some characteristic parameters of the table.

E. Select_statement,select Statement Description section, which allows you to quickly create a table.

2. View the table.

For a successfully created table, use the show Columns statement or describe statement to view the table structure of the specified datasheet. The format is as follows:

Show Columns statement:

Show [all] columns from data table name [from database name];
Or
Show [Full] columns the From data table name. database name; Describe statement, describe can be abbreviated as DESC.

Describe data table name; or describe data list name;

Home 1 2 3 4 last page
Related Article

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.