MySQL creates data tables and deletes data tables

Source: Internet
Author: User
Tags mysql create mysql create table

Create a datasheet use

Command: CREATE table < table name > (< Field name 1> < type 1> [,.. < Field name N> < type n>];

Syntax: CREATE [temporary] TABLE [IF not EXISTS] tbl_name [(create_definition,...)] [Table_options] [Select_statement]

Cases

The code is as follows Copy Code

Mysql> CREATE TABLE MyClass (
> ID int (4) NOT null primary key auto_increment,
> name char (NOT NULL),
> Sex int (4) NOT null default ' 0 ',
> Degree double (16,2));

Detailed parameters

Temporary: This keyword indicates that the newly created table with MySQL CREATE TABLE is a temporary table that will automatically disappear after the current session ends. Temporary tables are mainly used in stored procedures, and for MySQL, which does not currently support stored procedures, this keyword is generally not available.

IF not EXISTS: In fact, add a judgment before the table is being built to perform the CREATE TABLE operation only if the table does not currently exist. Use this option to avoid errors where the table already exists and cannot be created again.

Tbl_name: The table name of the table you want to create. The table name must conform to the rules for identifiers. The usual practice is to use only letters, numbers, and underscores in the table name. For example, titles, Our_sales, My_user1 and so on should be regarded as the table name of the comparison specification.

Create_definition: This is the key part of the MySQL CREATE TABLE statement. The properties of each column in the table are specifically defined in this section.

Delete Table command : Drop table < table name >

mysql> drop table MyClass;

DROP table is used to cancel one or more tables. You must have drop permissions for each table. All table data and table definitions will be canceled, so be careful with this statement!

And then share some of the table-related commands.

Get table structure

Command: DESC table name, or Show columns from table name

The code is as follows Copy Code

mysql> desc MyClass;
Mysql> show columns from MyClass;


Insert Record

Command: INSERT into < table name > [< field name 1>[,.. < field name n >]] VALUES (value 1) [, (value N)]

For example: Insert two records into table MyClass, two records indicate that: Tom with a number 1 is 96.45, and the number 2 for Joan is 82.99, and the number 3 for Wang is 96.5.

mysql> INSERT INTO MyClass values (1, ' Tom ', 96.45), (2, ' Joan ', 82.99), (2, ' Wang ', 96.59);

Note: INSERT into only one record in the table at a time.

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.