0% found this document useful (0 votes)
34 views

DB Lab - A1

The document elaborates on SQL data types with examples of data type commands and sample values. It discusses character, numeric, date, time, and large object data types. Examples are provided for each data type to illustrate how values of different formats can be stored according to the data type specifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

DB Lab - A1

The document elaborates on SQL data types with examples of data type commands and sample values. It discusses character, numeric, date, time, and large object data types. Examples are provided for each data type to illustrate how values of different formats can be stored according to the data type specifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Assignment #01

DB Lab

5-C

BY: Syed Mohammad Ali – 70066816.


To: Sir Shahid Iqbal.
Due date: 14 November, 2020.
Q1: Elaborate SQL data types with number of examples and SQL
commands?

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.

SQL Data types: -

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:

'Race car', '24865'

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:

12345678, 1.2, -12345678

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:

DATE '1999-01-01', DATE '2000-2-2'

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:

TIME '00:00:00', TIME '1:30:00', TIME '23:59:59'

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:

TIMESTAMP `1999-12-31 23:59:59.99'

CLOB [(length)] or CHARACTER LARGE OBJECT [(length)] or CHAR LARGE


OBJECT [(length)]
The Character Large Object (CLOB) data type accepts character strings longer than those that
are allowed in the CHARACTER [(length)] or VARCHAR (length) data types. The CLOB
declaration uses the following syntax to specify the length of the CLOB 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 CLOB data types is 2 gigabytes. If a length is not specified, then
a default length of one byte is used.

BLOB [(length)] or BINARY LARGE OBJECT [(length)]:

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.

You might also like