Understanding SQL & Java Together: A Guide to SQLJ, JDBC, and Related Technologies

7.3: SQL:1999 User-Defined Types

7.3 SQL:1999 User-Defined Types

As we suggested in Section 7.2.2, SQL:1999 provides more than one sort of user-defined type. While it provides a very powerful variation, called "structured types" (which we'll cover a bit more thoroughly in Section 7.4 and the rest of the chapter), it also provides a more limited variant, called "distinct types." Our discussion of distinct types is relatively short, since it has little to do with using SQLJ and Java together; in fact, we're including it only because we felt the need to complete the picture of SQL's user-defined types. We'll spend most of this chapter's space, and energy, on structured types.

7.3.1 Distinct Types

A distinct type is a data type that is based on a single built-in data type, such as INTEGER, but whose values cannot be directly mixed in operations with that built-in type or with other distinct types based on that built-in type. They are first-class types meaning that they can be used to define columns, variables, and so forth, just like any SQL built-in type. They provide strong typing in the SQL language (in which typing is traditionally viewed as moderately strong at best, since you are allowed to mix data types in expressions within fairly generous bounds).

The best way to explain SQL's distinct types is by example. Consider an application that gathers information about people who buy music CDs and videotapes in an effort to learn how to predict based on their demographics what products people will be interested in...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Middleware
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.