|
Java Oracle Database Development Authors: Gallardo D. Published year: 2002 Pages: 16-17/71 |
Chapter 2. Database Design EssentialsA relational database is essentially just a set of tables of data that are related to each other. These tables are useful because we can use a high-level language, such as SQL, to add, change, or delete the tables or the data in the tables. We can query the database and obtain the results of selecting data based on simple or complex relations. We can perform set operations, such as joins, on the data. These capabilities let us store, manage, and make use of even very large amounts of data. Tables can hold data of different types, allowing us to store, primarily, numbers , dates, and text. We can perform calculations, sort , or change these types of data. (There are also types used to store arbitrary data—which could be images or sounds, for example—but they are just "stuff" to the database and we cannot perform operations on these types apart from storing it and retrieving it. These cannot be manipulated using SQL and won't be considered until Chapter 9, "Advance JDBC Features.") The Oracle SQL datatypes correspond only roughly to Java types and mapping from one to the other requires some care. Designing a database is largely a matter of determining the types of data in each table and determining the relationships between each of the tables in the database. Exploring a little of the theory behind relational database design will prevent problems such as redundant data or a database that is difficult to use. |
Tables, Columns , and RowsThe table is the fundamental organizing unit in a database. There are several terminologies used, but generally we describe a table as having columns and rows. Let's take as an example a table designed to hold information about the CDs in our collection. There are a number of different pieces of information we would like to keep about each CD, such as artist, title, and release date. We call each of these a column , and we define them when we create the table. As we start to enter data into our table, each item that we enter—in our example, the information for each CD—is called a row in the table. Sometimes the columns in a table are called fields , and sometimes the rows are called records . In other words, for each CD, we will have a record in the table, and each record will have fields identifying the artist, the album title, etc. In general, we'll stick to the row and column terminology. One of the requirements of a relational database is that it must have a high-level relational language. In practice, this language is SQL (Structured Query Language). The main purpose of SQL is to define and manipulate data through statements that apply to tables, rows, and sets of rows. Each SQL statement is independent of all others, and each one is executed, effectively, all at once. There is no provision in standard SQL (at least, as it is now most commonly implemented) for step-by-step, conditional processing. If we need to do that, we need to use a host procedural language, such as Java, that allows us to execute SQL statements sequentially, making decisions as we go, based on conditional expressions in constructs such as if statements and while loops . Because SQL was intended to be hosted by another language, it has datatypes that are intended to be mapped to the datatypes of typical procedural languages. Perhaps because of this intention to be so generally useful, these mappings are not particularly ideal for any language. To complicate things further, different database vendors support the SQL standard types in different ways. Oracle, specifically , has a small set of native types that map to a larger set of standard SQL types. As a matter of principle, we should try to do things in as standard a way as possible, but in this case, we'll use the Oracle datatypes, rather than add an additional layer of complexity by struggling to maintain the illusion that we are using the standard SQL types. |
|
Java Oracle Database Development Authors: Gallardo D. Published year: 2002 Pages: 16-17/71 |