Upcoming SlideShare
×

Like this presentation? Why not share!

# L4 domain integrity

## on Sep 27, 2013

• 206 views

### Views

Total Views
206
Views on SlideShare
206
Embed Views
0

Likes
0
2
0

No embeds

### Report content

• Comment goes here.
Are you sure you want to

## L4 domain integrityPresentation Transcript

• Domains Understanding Domain Integrity Version 1.0 (c) Rushdi Shams, CSE@KUET 1
• What are Domains  Domains are pools of values from where values appear in the column of a table  Domain of a column is KIND of value it can represent  Column: domain- it defines the kind of values the column represents  Data type and domain are two different things  Data type is a physical thing while domain is a logical thing (c) Rushdi Shams, CSE@KUET 2
• What are domains (continued)  I said, domain is a all possible collection of values that a column can contain, in this example, you have one perspective why I said so!  Say, Staffno column has 4 values in it- 01K28, 01B23, 03X98 and 09Y12 (well, I can’t say what they really mean)! The domain of Staffno is {01K28, 01B23, 03X98 and 09Y12}. 3(c) Rushdi Shams, CSE@KUET
• What are domains (continued)  I also said that domain represents the kind of data it represents. The following example will simplify the statement  Say, Streetname and Studentname are two columns of a table. They can both have the same data type like TEXT or CHAR or VARCHAR or whatever…can’t they? But they are different. Aren’t they? (c) Rushdi Shams, CSE@KUET 4
• What are domains (continued)  Again, say, there are two columns in a table named rollnumber and salary having the same data type INTEGER, NUMBER or whatever…but they are different, no?  So, studentname and streetname have different domains and rollnumber and salary have different domains  In these two example, you can see the difference between data type and domain as well. Can’t you? (c) Rushdi Shams, CSE@KUET 5
• What are domains (continued)  Doamins are thus narrower concept than data types. What is a narrower concept? Well it means, it is descriptive! Degreeawarded column can be represented by simply datatype TEXT (3). But in domains, it is represented by {BA, BS, MA, MS, PhD, LLD, MD}  But remember one thing- you don’t manipulate domains in database engine, you work with data type (as data type is physical and domain is logical thing) (c) Rushdi Shams, CSE@KUET 6
• What are domains (continued)  Sometimes domains are large in numbers so that they become difficult to implement. Say, AGE! What if you are representing the domain AGE? You can then use the concept of range. The domain of AGE can be between 1 to 120. (c) Rushdi Shams, CSE@KUET 7
• Deep into domains  Now, we will dig into deep of the domain and data type concept  Sometimes, you will need to compare between columns of two tables. Then, you will need the concept of domain. (c) Rushdi Shams, CSE@KUET 8
• Deep into domains (continued)  SALES table has Salesperson ID which is eventually the Employee ID of EMPLOYEE table.  So, Mr. Michael Suyama was dealing with Order ID 10643.  You may have to compare them to find out this information.  If the domain of Salesperson ID and Employee ID is not same, you could not compare them! 9(c) Rushdi Shams, CSE@KUET
• Deep into domains (continued)  So, Salesperson ID and Employee ID, as they are comparable, are called type- compatible  Trying to combine the relations on Employee ID and Order ID, however, would probably not result in a meaningful answer, even if the two domains were defined on the same data type. (c) Rushdi Shams, CSE@KUET 10
• Domain Integrity  In a database the domain integrity is defined by 1. Data type and length 2. NULL value acceptance 3. Allowable values through rules 4. Default value Back 1 Back 2 (c) Rushdi Shams, CSE@KUET 11
• Domain Constraints  Domain constraints are rules that define legal values for columns  Sometimes more than one rule is needed for a column to completely define the legal values  Unfortunately, SQL and other database engine generally don’t facilitate with powerful tools to recognize violations on domains.  If employee ID and Salary are both NUMBERs then, if you make a query by relating them, they will certainly give you an answer! Aweful, huh?  But some tools can still be easily manipulated to avoid the violations. (c) Rushdi Shams, CSE@KUET 12
• Domain Constraints (continued) DEFAULT  You can use DEFAULT to set a column value to some specific value. In this example, the data type and length, NULL value acceptance and default value is covered (see Domain Integrity) CREATE TABLE Course( Course_ID NUMBER(10) NOT NULL, Course_Name VARCHAR(20), Pass_Mark INTEGER(3) DEFAULT 40, PRIMARY KEY (Course_ID) ); (c) Rushdi Shams, CSE@KUET 13
• Domain Constraints (continued) CHECK  This is a good tool to check if violation in putting data have occurred or not. In this example NULL value acceptance, data types and length and the allowable value by rules are covered (see Domain Integrity) CREATE TABLE Subject( Subject_ID VARCHAR(10) NOT NULL, Subject_Name VARCHAR(20), Credit NUMBER(10) CHECK(Credit>0 AND Credit<=10), PRIMARY KEY (Subject_ID) ); (c) Rushdi Shams, CSE@KUET 14
• Domain Constraints (continued)  If you use CHECK on more than one column in a table, that constraint is also called table constraint. CREATE TABLE Lecturer( ID VARCHAR(10) NOT NULL, Name VARCHAR(20), Grade CHAR(1), Salary INTEGER(5), CHECK (Salary<50000 OR Grade<=‘B’), PRIMARY KEY (ID) ); (c) Rushdi Shams, CSE@KUET 15
• References  Designing Effective Database Systems by Rebecca M. Riordan, Addison Wesley Professional, 2005  Structured Query Language: A Practical Introduction by Akil I Din  Database Systems by Paul Beynon- Devies, Palgrave Macmillan, 2004  www.databasedev.co.uk (c) Rushdi Shams, CSE@KUET 16