Imagine that you've written an order entry application that is highly dependent on a backend database server. All of your code gains access to the data through stored procedures that you have written. The application is deployed, and a couple hundred users enter customer and order information all day long.
Now imagine that you need to add a new field that contains the customer's credit limit. You must add this field to the customer screen in the application and add business logic to ensure that new orders cannot be entered if the customer's credit limit has been exceeded. Of course, you must add this field to the customer table in the database and modify the stored procedures for retrieving and modifying the customer table to deal with the new field. Oh, yeah: you also have to modify your data access code that calls these stored procedures.
In addition to all of the work that you have to do to accomplish this task, some important questions will arise: How can you be sure that the database is in sync with the code? What should you do if a user is running an older version of the application? Do the database changes need to be deployed at exactly the same time as the application changes?
The answers to these questions might be different for every application, but if your code can get information from the database that describes its tables and stored procedures, you can programmatically decide to abort the application if it's not in sync with the database or to adapt it to the database.
As data stores add new features and schemas change, it becomes increasingly important to have a means of finding out about the data store's capabilities. Exposing metadata data that describes data is important in applications that need the ability to identify and possibly adjust to changes in the backend data store.
You can use metadata in an application to enable users to create new tables or fields on the fly. Developers also create tools that generate data access layer code based on the metadata that the database provides. Microsoft Visual Studio and other development tools make heavy use of metadata when running data access wizards.
Although most data access technologies allow you to query for database schema information, the query method depends on the data provider. This chapter examines the schema API and its metadata capabilities.