Database schemas, domains and constraints
| | There is more to a database than just a collection of tables. In addition to tables, there are structural aspects that maintain the integrity of data stored in databases. This tutorial will cover the structural aspect of any relational database. These include schemas, domains and constraints.
Schemas
A schema is basically the structure of an entire database structure. Some also calls it the conceptual or logical view of the entire database. Basically a schema is made up of tables, relationships and data describing the structure of a database. In computer science jargon, this is called metadata (which in layman terms means "Data about Data").
Domains
Every attribute or column of a database can only assume a finite number of values. The set of such values is what is called a domain of that attribute or table column. For example; assuming that you sell television sets, and have a database that keeps track of the number of television sets you have in stock and those sold. This table has a column called tv_color where you would store the exterior color of the television such as "black", "grey" and "white". The domain of such a field is the set of these three colors.
Constraints
These are perhaps one of the most overlooked aspects of a good database. Constraints are very important in making sure that the data stored in the database keeps its integrity. You can do stuff such as preventing people from entering invalid data into a field. For example, if you had the field called tv_color and you only want it to have one of the three colors (Black, Grey and White) as valid data, you could use what is called a check constraint to make sure that the data you are about to enter into the table is one of those colors. The general syntax to do that is as follows:
create table tv(
...
tv_color varchar(20) CONSTRAINT chk_color CHECK (tv_color = 'White' OR tv_color = 'Grey', tv_color = 'Black')
...
);
If somebody attempts to insert the value "Blue" into tv_color, the database system will raise an error, reminding you that the value you entered is not valid.
Other constraints
There are several database constraints that will be discussed in other postings. These include the
- Not-NULL constraints
- Primary key constraints
- Foreign key constraints
- Unique constraints
- Check constraints
|
RELATED ARTICLES: Creating database tables with SQL To create a table in SQL, you use a command that requires the name of the table as well as names and data types of the fields of that table. In general, the syntax for creating a table is as follows:
CREATE table_name ( column_name data_type);
The table nam
Database Design After gathering and analyzing your requirements, and depending on whether or not your application needs a database to store information; database design is the next big thing. This comes even before you start coding the application program. The reason for this is that, the application program
The state of Periodic table elements - In addition to the group 8 or O elements, the following elements also naturally occur in gas state:
H, N, O, F, Cl and Br
-Among metals and non-metals, the following occurs in liquid state:
Na, K, Rb, Cs, Fr, Hg a
breaking code periodic table
Understanding Databases In any relational database system, data is stored in what is called a table. Each table is made up of rows and columns. The idea with creating tables is based on the notion that each table should contain data about one and only
Joining a table with itself (SQL self-join) Joining a table with itself is sometimes the only way to make sense of information. Consider a scenario where everybody's information in a company including managers and ordinary employees. That same table contains information on who reports to who?
Copying data from one table to the other here are several ways to copy or move data from one table to another. Some methods are applicable when copying data from one table to another on the same database and other methods are applicable for copying data from one database to another and even or a different server. Bellow are several methods
| |
|