O'Reilly logo

Visual Basic® .NET Database Programming by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data Validation

Ensuring that changes are saved is only half the data safety problem. A program should also ensure that the saved data values make as much sense as possible. For instance, if the user accidentally types 80201 in a phone number field, the program should not save the data to the database.

At the lowest level, you can use the database itself to validate data. For example, you can use the NOT NULL statement to require a value in a field. You can use CHECK clauses to provide more elaborate validation. For instance, the following SQL statement creates a ZipCodes table. Each record’s Zip field must have the format 12345 or 12345-6789.

 CREATE TABLE Zips ( Zip VARCHAR(10) UNIQUE NOT NULL CHECK ((Zip LIKE '[0-9][0-9][0-9][0-9][0-9]') ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required