MySQL database basic syntax

1. Database operations

There is no case sensitivity in the database! ! !

1.1 Display database

show databases ;

As shown in the picture:

1.2 Create database

create database [if not exists] database name;

As shown in the picture:

 1.3 Using database

use database name;

 As shown in the picture:

 This operation is used to operate tables in the library. We will not talk about it now. It will be used in the next article when we talk about adding, deleting, checking, and modifying tables . Whenever you operate a table, you must add this sentence before using the table.

1.4 Delete library

drop database [ if exists ] database name;

As shown in the picture:

2. Common data types

2.1 Integer and floating point types

type of data size illustrate Corresponding JAVA type
bit[(M)] M represents the specified number of digits, the default is 1, you can not add it

Binary number, M ∈[1,64]

Storage value range [0,2^M-1]

boolean
tinyint 1 byte Byte
smallint 2 bytes Short
int 4 bytes Integer
bigint 8 bytes Long
float(M,D) 4 bytes

Single precision, M specifies the length, D specifies the number of decimal places,

A loss of precision will occur

Float
double(M,D) 8 bytes

Double
 decimal(M,D) M/D maximum value +2

Double precision, M specifies the length, D specifies the number of decimal places,

Exact value

DigDecimal
numeric(M,D) M/D maximum value +2

Double precision, M specifies the length, D specifies the number of decimal places,

Exact value

BigDecimal

Note: There is an unsigned type in mysql, but its use is not recommended and may cause data errors.

2.2 String type

type of data size illustrate Corresponding JAVA type
varchar(size) 0-65535 bytes size indicates how many characters there are (a Chinese character is also a character) String
test 0-65535 bytes long text data String
mediumtext 0-16777215 bytes Medium and long text data String
blob 0-65535 bytes binary text data byte[]

2.3 Date type

type of data size illustrate Corresponding JAVA type
datetime 8 bytes The range is from 1000 to 9999. Time zone retrieval and conversion will not be performed.

java.util.Date

java.sql.Timestamp

timestamp 4 bytes Ranges from 1970 to 2023, automatically retrieves current time zone and converts

java.util.Date

java.sql.Timestamp

3. Table operations

3.1 View table structure

desc table name;

3.2 Create table 

create table table name(field name type, field name type, ...);

 Note: Before using the table, be sure to write use database name;

3.3 Delete table

drop table [ if exists ] 表名 ;

Guess you like

Origin blog.csdn.net/m0_74859835/article/details/132198880