Data types and creation in MySQL

Source: Internet
Author: User

Tag: LOB ext Lin Time font text drop timestamp length

MySQL Create:

1. Create a database
Create Database test2;
2. Deleting a database
Drop database test2;

3. Create a table
CREATE TABLE Ceshi
(
IDS int Auto_increment primary KEY,
UID varchar (20),
Name varchar (20),
Class varchar (20),
Foreign key (Class) references Class (code)
);
CREATE TABLE Class
(
Code varchar (primary key),
Name varchar (NOT NULL)
);

* * Self-growth auto_increment
* * PRIMARY KEY PRIMARY key
* * FOREIGN key FOREIGN key (column name) references Main Table name (column name)
* * non-null NOT NULL

4. Delete a table
drop table Ceshi;

Attention:
1. The type contains the length of the parentheses after the type, and the parentheses write the length
2. Complete the previous column with a comma
3. The last column do not write a comma
4. Add a semicolon after each SQL statement is finished
5. If there is a foreign key relationship, first create the primary table

Data types in MySQL

MySQL has three major classes of data types, number, date \ Time, string, and more detailed sub-types in the three categories:

    • Number Type
      • integers: tinyint, smallint, mediumint, int, bigint
      • Floating-point numbers: float, double, real, decimal
    • dates and times : Date, Time, DateTime, timestamp, year
    • String type
      • String: char, varchar
      • Text: Tinytext, text, Mediumtext, Longtext
      • Binary (used to store pictures, music, etc.): Tinyblob, Blob, Mediumblob, Longblob

Data types and creation in 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.