Page 46 - DCAP402_DCAO204_DATABASE MANAGEMENT SYSTEM_MANAGING DATABASE
P. 46
Unit 3: Structured Query Language
specifies the name of the table and the names and data types of each column of the table. Its Notes
format is:
create table (relation> (<attribute list>)
where the attribute list is specified as:
<attribute list> :: = <attribute name> (<data type>)[not null] <attribute list>
The data types supported by SQL depend on the particular implementation. However, the
following data types are generally included: integer, decimal, real (i.e., floating point values),
and character strings, both of fixed size and varying length. A number of ranges of values for the
integer data type are generally supported, for example, integer and smallint. The decimal value
declaration requires the specification of the total number of decimal digits for the value and
(optionally), the number of digits to the right of the decimal point. The number of fractional
decimal digits is assumed to be zero if only the total number of digits is specified.
<data type> :: = <integer> | <smallint> | <char(n)> | <float> | <decimal (p[q])>
In addition, some implementations can support additional data types such as bit strings, graphical
strings, logical, data, and time. Some DBMSs support the concept of date. One possible
implementation of date could be as eight unsigned decimal digits representing the data in the
yyyymmdd format. Here yyyy represents the year, mm represents the month and dd represents
the day. Two dates can be compared to find the one that is larger and hence occurring later. The
system ensures that only legal date values are inserted (19860536 for the date would be illegal)
and functions are provided to perform operations such as adding a number of days to a date to
come up with another date or subtracting a date from the current date to find the number of
days, months, or years. Date constants are provided in either the format given above or as a
character string in one of the following formats: mm/dd/yy; mm/dd/yyyy; dd-mm-yy;
dd-mm-yyyy. In this unit, we represent a date constant as eight unsigned decimal digits in the
format yyyymmdd.
3.3 Data Types
In a broad sense, a data type’ defines a set of values, and the allowable operations on those
values. Almost all programming languages explicitly include the notion of data type, though
different languages may use different terminology. Most programming languages also allow
the programmer to define additional data types, usually by combining multiple elements of
other types and defining the valid operations of the new data type.
Example: A programmer might create a new data type named “Person” that specifies
that data interpreted as Person would include a name and a date of birth.
Common data types may include:
1. Integers,
2. Floating-point numbers (decimals), and
3. Alphanumeric strings.
Example: In the Java programming language, the “int” type represents the set of 32-bit
integers ranging in value from -2,147,483,648 to 2,147,483,647, as well as the operations that can
be performed on integers, such as addition, subtraction, and multiplication. Colors, on the other
hand, are represented by three bytes denoting the amounts each of red, green, and blue, and one
LOVELY PROFESSIONAL UNIVERSITY 39