MySQL data type + simple operation

Source: Internet
Author: User

Data type

Numeric type
Integer
Int (m) four bytes (-2.1 billion ~21 billion)---java:int
BigInt (M) eight bytes (18 square)---java:long
Floating point number
Float (m,d) single-precision floating-point number 8-bit precision four bytes m total number of D decimal---java:float
Double (m,d) dual precision floating point number 16-bit precision eight bytes m total number of D decimal---java:float
Fixed-point number
Floating-point type is always the approximate value in the database, and the fixed-point type holds the exact value
Decimal (m,d) m<65 d<30 and D<m m is the total number D is the number of decimal digits---java:double
Character type
CHAR (n): fixed length of up to 255 characters
Char cannot have spaces at the end of storage
Fixed length, so no matter how many characters are deposited, Occupy N position two bytes also occupy n position
Varcahr (n): fixed length of up to 65,535 characters
VarChar is based on a fixed length with a few +1 of the length of the deposit three actually occupy four
Text: variable length of up to 65,535 characters
In general development use varchar It must be specified length if the string stored is very large, it is recommended to use the text without specifying the length
Time Date Type
Data Date---java:java.sql.Date
Time---java:java.sql.Date
Datatime Date and Time---java:java.sql.Timesatmp
Timestamp Automatic Storage modification time
MySQL operation

Create a table

CREATE TABLE STUDENT (
SID INT PRIMARY KEY,
SNAME Varcahr (), not NULL,
Seex CHAR (3) CHECK (SEX in (' Male ', ' female ')),
)
Modify Table

Modify
ALTER TABLE STUDENT change Seex sex CHAR (4) is not a NULL CHECK (SEX in (' Male ', ' female '));
Renaming a table
ALTER TABLE STUDENT RENAME STUDENTS;
Delete Column
Alter TABLE STUDENT drop sex;--Row-level data deletion using alter
Delete a table
DROP TABLE STUDENT; --table level above data delete using drop
Deleting a database
DROP DATABASE * * *;
MySQL's crud

Add to
INSERT into STUDENT (sname,sex) VALUES (' XXX ', ' Male ');
Modify
Updata STUDENT SET sname= ' YYY ', sex= ' female ' WHERE sid=1;
Delete
DELETE from STUDENT WHERE sid=1;
Inquire
SELECT * from STUDENT

MySQL data type + simple operation

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.