SQL Server 13 – Domain Integrity
This video will introduce domain integrity. It would be helpful first to know what domain means. In the context of software development, domain defines what kind of data is expected or allowed. This may be tied to what is known as business rules. Business rules are the rules that say what the database is supposed to allow and not allow.
There is a fine line between business rules and domain integrity, so let’s go in a little more detail. A business rule is given in a spoken language, such as English. It is a non-technical way of describing what the data is supposed to be. For example, we could say that the business rule for a certain column is that it is supposed to store a salary. This business rule could then be described technically as a column that is stores only integers. The technical requirement described would be the domain.
Domain integrity means that all of the data in a column with business rules is of the right format and has appropriate content.
We can go a step further and say that row has to have a value (NOT NULL) or has to be UNIQUE.
How do we acquire data integrity? There are a few ways. The first is with a data type. This is the easiest way to restrict certain types of data. What is a data type? Looking at the word it becomes quite clear. The data type is the type of data. You have to select a data type for each column in a database. The important classifications of data types are numeric, string, and date.
In SQL server, an example of a data type is INT. By giving a column this data type, you can force the data to be a number.
The second way is with constraints. Using constraints, we could force every row to have a salary, or we could say all of the salaries have to be unique (which sounds like a dumb idea). We can even get more specific in our domain using what is known as a check constraint. This allows us to do fancy stuff like forcing every salary to be within a certain range.
Support me! http://www.patreon.com/calebcurry
Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter
More content: http://CalebCurry.com
Amazing Web Hosting – http://bit.ly/ccbluehost (The best web hosting for a cheap price!)