Mysql summary _ MySQL

Source: Internet
Author: User
Create database creattabletest (inttest_idint is used for integers, decimaltest_pricedecimal is used for decimals, and decimaltest_pricedecimal is used for common text, and Default is used to specify 20540; test_namevarchar (255) defaultXxx
Creat table test (
# An integer usually uses an int.
Test_id int,
# Decimal is usually used for decimals.
Test_price decimal,
# Common text is usually used and Default is used to specify the Default value
Test_name varchar (255) default "Xxx ",
# Use test for large text types
Test_desc text,
# Use blob for images
Test_img blob,
# Use DateTime for date type
Test_date datetime,
);
-----------------------------------------------------------------
Column types supported by mysql
1. tinyint, smallint, mediumint, int, bigint
2. float, double
3. decimal (dec)
4. date
5. time
6. datetime
7. timestamp
8. year
9. char
10. varchar
11. binary (fixed-length binary string type, saved in binary format


Store strings)
12. varbinary
13. tinyblob, blob, mediumblob, longblob
14. tinytext, text, mediumtext, longtext
15. enum ('value1', 'value2'...) // enumeration type (only


One)
16. set ('value1', 'value2'...) // set type (which can be


)
--------------------------------------------------------------------
# Create a data table, which is exactly the same as user_info.


Also identical
Create table hehe
As
Select * from user_info;
---------------------------------------------------------------------
# Modify the table structure syntax
Alert table name
Add (
# Multiple column definitions can be defined.
Colum_name datatype [default expr],
...
);
---------------------------------------------------------------------
# Add a hehe_id field to the hehe data table. The field type is


Int


Alter table hehe
Add hehe_id int;
# Add aaa and bbb fields for hehe data packets. both fields are of the same type.


Varchar (25)
Alter table hehe
Add aaa varchar (25), bbb varchar (25 );
----------------------------------------------------------------------
# Change the hehe_id column of The hehe table to varchar (255) type.
Alter table hehe
Modify hehe_id varchar (255 );
# Modify the bbb column of The hehe table to the int type.
Alter table hehe
Modify bbb int;
----------------------------------------------------------------------
# Deleting a specified column
Alter table hehe
Drop column_name
# Rename a data table
Alter table hehe
Rename to wawa;
----------------------------------------------------------------------
# Rename the bbb field of the wawa table to ddd
Alter table wawa
Change bbb ddd int;
# Deleting a table
Drop table name
----------------------------------------------------------------------
Database constraints
Not null
Unique
Primary key
Foreign key
Check
# Not null constraint

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.