About User-Defined Types
This page is part of the book SQL-99 Complete, Really, by Peter Gulutzan & Trudy Pelzer. The authors have graciously allowed us to reproduce the contents of the book here. Because the book is about the SQL-99 standard, the contents of this and other pages in the book may not directly apply to MariaDB. Use the navigation bar to navigate the book.
SQL began life as a procedurally oriented language, or — properly speaking — as a language with procedures that worked on sets. Nowadays the rage is for object oriented languages — like C++ and Java. The popularity of object orientation ("OO" for short) has been so great, that some have attempted to supersede SQL with pure "OO DBMSs" (POET is an example). On the other hand, a great deal of time and trouble has been invested getting SQL to where it is today, so most users and experts have looked to a more moderate solution. Namely: extending SQL so that it can handle databases the OO way, but without abandoning the current language. We'll call this hybrid object/relational, or O/R for short.
The inspirations have come from languages like C++ and Object Pascal, which are extensions of C and Pascal. Those extended languages have been successful. It appears that there will be an equivalent success for the Object Oriented SQL extensions, once DBMS vendors implement them and users get acquainted with them.
We're not at that stage yet. What you're going to read about in this chapter is
the very latest stuff, just accepted as part of the SQL Standard, and still
quite wet around the edges. Since that's so, we will depart from the usual
chapter organization. The first parts of this chapter are merely a tutorial
which (we hope) you'll find is fairly light reading, peppered with liberating
slogans like "a type is a class" or "a row is an object". The middle parts of
this chapter are more of a syntactical slog as we get into the details of
CREATE TYPE and the various SQL statements associated with it; however, we
have omitted some details which we think will not be part of real DBMS
implementations for some years.
If you've ever used an object oriented language, you'll find the concepts are familiar (which they're supposed to be — that's the point). However, you must start with a good recollection of the earlier chapters on <data type>s, procedures and SQL syntax.