Table command

First, let's look at database creation, deletion, and selection statements.

Database creation statement

CREATAE DATABASE database name;

Drop database statement

DROP DATABASE database name;

Database selection statement

use database name;

Now let's look at the table command
As mentioned earlier, a table is divided into rows and columns as shown in the table.
For example, let's say that the information of students
Fill in the fields with name, major, student number, address, mobile number, etc.
The record will be filled with Hong Gil-dong Electronics 0883433 010-111-111.
To create a table, create a database before creating the table, select the database and create it with CREATE TABLE.
As mentioned earlier, you should also set the type such as int.
If you set the type to char when you set the type to char (10)
If you enter 5 bytes of char in the char value, the remaining 5 bytes are blanked out. If you enter a character that is longer than 10 bytes, it will be truncated from 10 bytes.
varchar is a variable-width string. Both char and varchar can be up to 255 characters long.
If you set varchar (10) and enter 5 characters, characters are padded from the left and no spaces are created. It is different from char.
It can use memory efficiently. It has the advantage of being slow, but it is expected that it will not make any difference.
Use varchar more than char.

The length of the string data type.

Data type MAX Length Storage size
char 255 byte entered
varchar 255 (Number entered + 1) byte
tinylob, tinytext 255 (Number entered + 1) byte
blob, text 65535 (Enter number + 2) byte
mediumblob, mediumtext 16777215 (Enter number + 3) byte
longblob, longtext 4294967295 (Enter number + 4) byte
enum(string1, string2) 1 or 2byte

Numeric

When using numeric data, use int or integer for integers and double for real numbers. For integers with large numbers, use unsignet int or bigint.

Data Type

MAX Length

Storage size

TINYINT

-128 ~ 127
(unsigned : 0 ~ 255)

1byte

smallint

-32768 ~ 32767
(unsigned : 0 ~65535)

2byte

mediumint

-8388608 ~ 5388607
(unsigned : 0~16777215)

3byte

int

-2147493648 ~ 2147483647
(unsigned : 0 4294967295)

4byte

integer

-2147493648 ~ 2147483647
(unsigned : 0 4294967295) 위와 동일하네요

4byte

bigint

-9223372036854775858 ~ 9223372036854775807

4byte

float

-3.402823466E+38 ~ -1.175494351E-38, 0 ,

1.175494351E-38 ~ 3.402823466E+38

8byte

double

-1.7976931348623157E+308 ~ -2.2250738585072014E-308,0,

2.2250738585072014E-308 ~ -1.7976931348623157E+308

8byte


Don't memorize this and just pass it like this for mental health or time savings.
If you're studying programming for the first time, I'm sure you'll memorize everything perfectly.
When I study programming for the first time, it takes me a few days to memorize each one of them.
Absolute light.


Data type

Display range

form

Storage size

date

1000-01-01 ~ 9999-12-31

YYYY-MM-DD

3byte

datetime

1000-01-01 00:00:00 ~

9999-12-31 23:59:59

YYYY-MM-DD HH:MM:SS

8byte

timestamp

1970-01-01 00:00:00 ~

2037-12-31 23:59:59

YYYYMMDD HHMMSS

4byte

time

-838:59:59 ~ 838:59:59

HH:MM:SS

3byte

year

1901~2155

1byte