Database Reference
In-Depth Information
Data Types SQL supports a variety of data types for the table columns repre-
senting the attributes. In the database, legal values may be entered for each column
based on the declared data type. The standard versions of SQL allow for accepted
data types; in addition, specific vendor implementation may have additional data
types or some variations of a standard data type.
The following is a list of the common SQL data types:
Character data
CHAR( n )
Alphanumeric character data of fixed length n
VARCHAR ( n )
Alphanumeric character data of variable length up to a
maximum length of n
Numeric data
DECIMAL ( m , n )
Signed number, where m is the total number of digits
including the sign and n is the number of digits to the right
of the decimal point
INTEGER
Large positive or negative whole numbers up to 11 digits
SMALLINT
Small positive or negative whole numbers up to 5 or 6 digits
FLOAT ( m )
Floating point number represented in scientific notation
with specified precision of at least m digits
Date/time data
DATE
Calendar date showing year, month, and day in a prescribed
format (year/month/day, month/day/year, or day/month/
year)
TIME
Hour, minute, second with time zone
Interval data
INTERVAL
Representation of periods of time
Bit data
BIT ( n )
Bit string of fixed length n
Logical data
LOGICAL
“True” or “False” values
SQL Data Definition Example You have now gone through the various SQL
statements available for defining database objects. You have also noted the provi-
sions to indicate the different data types for values to be stored in the database. Let
us put what we have covered so far in a practical example. In Figure 11-5, you
studied an entity-relationship diagram for a florist business. Also, Figure 11-10 pre-
sents the relational schema for that business. We will refer to those figures and create
data definitions with SQL statements. While doing so, we will provide examples of
most of the data definition statements listed above.
Carefully observe all the statements now shown in Figure 13-9. This figure pre-
sents the definition of the schema with the tables, columns, indexes, and so on for
Search WWH ::




Custom Search