DB Lab - A1
DB Lab - A1
DB Lab
5-C
Answer:
Each column in a database table is required to have a name and a data type. An SQL developer
must decide what type of data that will be stored inside each column when creating a table. The
data type is a guideline for SQL to understand what type of data is expected inside of each
column, and it also identifies how SQL will interact with the stored data. Data types define what
type of data a column can contain. An SQL developer must decide what type of data that will be
stored inside each column when creating a table.
CHARACTER or char:
The CHARACTER data type accepts character strings, including Unicode, of a fixed length. The
length of the character string should be specified in the data type declaration; for example,
CHARACTER (n) where n represents the desired length of the character string. If no length is
specified during the declaration, the default length is 1. The minimum length of the
CHARACTER data type is 1 and it can have a maximum length up to the table page size. If you
assign a value to a CHARACTER column containing fewer characters than the defined length,
the remaining space is filled with blanks characters.
SQL Command:
CHARACTER (10)
Examples:
VARCHAR:
The VARCHAR data type accepts character strings, including Unicode, of a variable length is up
to the maximum length specified in the data type declaration.
A VARCHAR declaration must include a positive integer in parentheses to define the maximum
allowable character string length. For example, VARCHAR (n) can accept any length of
character string up to n characters in length.
SQL Command:
VARCHAR (10)
Examples:
'RACECAR', '24865'
BOOLEAN:
The BOOLEAN data type supports the storage of two values: TRUE or FALSE. No parameters
are required when declaring a BOOLEAN data type. 1,0, yes, no are invalid in Boolean data
type.
SQL Command:
BOOLEAN
Examples:
TRUE, False
SMALLINT:
The SMALLINT data type accepts numeric values with an implied scale of zero. It stores any
integer value between the range 2^ -15 and 2^15 -1. Attempting to assign values outside this
range causes an error.
SQL Command:
SMALLINT
Examples:
-32768, 0
INTEGER:
The INTEGER data type stores any integer value between the range 2^ -31 and 2^31 -1.
Attempting to assign values outside this range causes an error.
SQL Command:
INT (5)
Examples:
-2147483648
DECIMAL or DEC:
The DECIMAL data type accepts numeric values, for which you may define a precision and a
scale in the data type declaration. The precision is a positive integer that indicates the number of
digits that the number will contain. The scale is a positive integer that indicates the number of
these digits that will represent decimal places to the right of the decimal point. The scale for a
DECIMAL cannot be larger than the precision.
SQL Command:
DECIMAL (10, 3)
Examples:
DECIMAL (10, 3)
1234567, 1234567.123
NUMERIC:
Point Base treats the NUMERIC data type in exactly the same way as the DECIMAL data type.
FLOAT (p):
The FLOAT data type accepts approximate numeric values, for which you may define a
precision up to a maximum of 64. If no precision is specified during the declaration, the default
precision is 64. Attempting to assign a value lager than the declared precision will cause an error
to be raised.
SQL Command:
FLOAT (8)
Examples:
DATE:
The DATE data type accepts date values. No parameters are required when declaring a DATE
data type. Date values should be specified in the form: YYYY-MM-DD. Month values must be
between 1 and 12, day values should be between 1 and 31 depending on the month and year
values should be between 0 and 9999. Values assigned to the DATE data type should be
enclosed in single quotes, preceded by the case insensitive keyword DATE; for example, DATE
'1999-04-04'.
SQL Command:
DATE
Examples:
TIME:
The TIME data type accepts time values. No parameters are required when declaring a TIME
data type. Date values should be specified in the form: HH:MM: SS. The minutes and seconds
values must be two digits. Hour values should be between zero 0 and 23, minute values should
be between 00 and 59 and second values should be between 00 and 61.999999. Values assigned
to the TIME data type should be enclosed in single quotes, preceded by the case insensitive
keyword TIME; for example, TIME '07:30:00'.
SQL Command:
TIME
Examples:
TIMESTAMP:
The TIMESTAMP data type accepts timestamp values, which are a combination of a DATE
value and a TIME value. No parameters are required when declaring a TIMESTAMP data type.
Timestamp values should be specified in the form: YYYY-MM-DD HH:MM: SS. There is a
space separator between the date and time portions of the timestamp.
SQL Command:
TIMESTAMP
Examples:
N [K | M | G]
In the above syntax, n is an unsigned integer that represents the length. K, M, and G correspond
to Kilobytes, Megabytes or Gigabytes, respectively. If K, M, or G is specified in addition to n,
then the actual length of n is the following:
K = N * 1024
M = N * 1,048,576
G = N * 1,073,741,824
The maximum size allowed for CLOB data types is 2 gigabytes. If a length is not specified, then
a default length of one byte is used.
The Binary Large Object (BLOB) data type accepts binary values. The BLOB declaration uses
the following syntax to specify the length in bytes:
N [K | M | G]
In the above syntax, N is an unsigned integer that represents the length. K, M, and G correspond
to Kilobytes, Megabytes or Gigabytes, respectively. If K, M, or G is specified in addition to n,
then the actual length of n is the following:
K = N * 1024
M = N * 1,048,576
G = N* 1,073,741,824
The maximum size allowed for BLOB data types is 2 gigabytes. If a length is not specified, then
a default length of one byte is used.