Friday, 5 February 2010

Domain ( Interbase Tutorial # 5 )

What is Domain ?

Let us see our SQL script in the previous tutorial for creating table ‘employee’ :

create table employee(
id integer not null,
name varchar(30) not null,
age integer not null,
phonenumber varchar(12) not null)


We have an integer data type for column ‘id’ and ‘age’. As we know integer has range value between -2,147,483,648 to 2,147,483,647. We can insert a negative value to these columns. But in the real world, id and age can not have a negative value.
We can solve this problem by creating a DOMAIN. DOMAIN is a customized column definition.

The syntax to create a domain is :

CREATE DOMAIN domain_name AS data type
DEFAULT devault_value NOT NULL
CHECK (condition)


DEFAULT clause and CHECK clause are optional.

Type the codes below in the text editor, and save it with file name ‘mydata_domain.txt’.

create database 'c:\mydata\mydata.gdb'
user 'NEW_USER' password 'password';

create domain string30 as varchar(30);
create domain string12 as varchar(12);
create domain domain_id as integer check(value>0);
create domain domain_age as integer
check(value>18 and value<55);


Go to InterBase Interactive SQL window.

You can not run the script above, because database 'c:\mydata\mydata.gdb' is slready exist. You need to drop the old database first.

Connect to the old database, then choose File – Drop Database. So the old database ‘c:\mydata\mydata.gdb' is now deleted. Then you run the script above by choosing File – Run an ISQL Script. And choose your ISQL script file : ‘mydata_domain.txt’. Now you have a better column definition in your table ‘employee’.

Go to Previous Tutorial or NextTutorial

3 comments:

  1. I like this article very much because it is technical and very much useful for me to gather more knowledge. Good to read...
    domain name India

    ReplyDelete
  2. We should thank you for giving such a wonderful blog. Your site happens to be not only informative but also very imaginative too. We find a limited number of experts who can think to write technical articles that creatively. Website Domain Name

    ReplyDelete
  3. s The best and a lot of secret drop-shipping suppliers in the world which will provide your products globally available for you directly to your customers doors. Also get the best drop-shipping manufacturer on your organization.

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.