MySQL Create data table

Source: Internet
Author: User
Tags mysql create

The following information is required to create a MySQL data table:

    • Table name
    • table field Name
    • Define each table field
Grammar

The following is the general SQL syntax for creating MySQL data tables:

CREATE TABLE table_name (column_name column_type);

In the following example we will create a data table Runoob_tbl in the Runoob database:

CREATE TABLE IF not EXISTS ' runoob_tbl ' (   ' runoob_id ' INT UNSIGNED auto_increment,   ' Runoob_title ' VARCHAR ( c1>100) Not null,   ' Runoob_author ' VARCHAR (+) not null,   ' submission_date ' date,   PRIMARY KEY ( ' runoob_id ') ENGINE=innodb DEFAULT Charset=utf8;

Instance parsing:

If you do not want the fields to be null, you can set the field's property to NOT NULL, and you will get an error if the data entered in the field is null when you manipulate the database.

Auto_increment defines a property that is self-increasing, typically used for a primary key, and the value is automatically added to 1.

The PRIMARY key keyword is used to define the column as the primary key. You can use multiple columns to define a primary key, and the columns are separated by commas.

The engine sets the storage engines and CHARSET sets the encoding.

To create a table from the command prompt

The mysql> Command window makes it easy to create MySQL data tables. You can create a table by using the SQL statement.

Instance

The following is a runoob_tbl instance of creating a data table:

[Email protected] # mysql-u root-p Enter password:*******mysql> Use runoob;database changedmysql> CREATE TABLE runoob_tbl (    - runoob_id INT NOT null auto_increment,   runoob_title VARCHAR (+) not NULL,   /c8>-> runoob_author VARCHAR (+) not NULL,      submission_date date,  PRIMARY KEY (runoob_id)   , engine=innodb DEFAULT charset=UTF8; Query OK, 0 rows affected (0.16 sec) MySQL>

Note: The MySQL command Terminator is a semicolon (;).

When you create a table for MYSQL, the symbol outside the table name and field name is not a single quotation mark, but an inverted single quote in the state of the English IME, which is the button below the ESC key in the upper left corner of the keyboard, and the pit is miserable.
Anti-quotes are symbols that are introduced in order to differentiate between MYSQL keywords and ordinary characters, in general, table names and field names using anti-quotes.

MySQL Create data table

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.