SQL data type

Definition:

An important element to every fields.

(Remark:Although some of below keywords do not exist in HKDSE ICT candidates’ reference sheet,it is better to remember those keywords.)


Example:

Integer

CREATE TABLE table_name(
field_name INT/INTEGER [constraint(s)],
);

Floating point number

CREATE TABLE table_name(
field_name FLOAT/DOUBLE [constraint(s)],
);

Fixed point number

CREATE TABLE table_name(
field_name DECIMAL [constraint(s)],
);

Character-Fixed length string

CREATE TABLE table_name(
field_name CHAR(length_of_data) [constraint(s)],
);

Character-Variable length string

CREATE TABLE table_name(
field_name VARCHAR(length_of_data) [constraint(s)],
);

Boolean

CREATE TABLE table_name(
field_name BOOL/BOOLEAN [constraint(s)],
);

(Data Format:0(FALSE)/1(TRUE))

Date

CREATE TABLE table_name(
field_name DATE [constraint(s)],
);

(Data Format:YYYY-MM-DD)

Time

CREATE TABLE table_name(
field_name TIME [constraint(s)],
);

(Data Format:HH:MI:SS)

Datetime

CREATE TABLE table_name(
field_name DATETIME [constraint(s)],
);

(Data Format:YYYY-MM-DD HH:MI:SS)


'Data type saves your marks.'By secondary 6 student

Comments