Database
  Home arrow Database arrow Page 15 - Extracting Metadata
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Extracting Metadata
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2004-09-08

    Table of Contents:
  • Extracting Metadata
  • Introducing the Process
  • Using Schema Definitions Such As XSD
  • Extracting Metadata from Databases Such As SQL Server
  • Retrieving Metadata from External Sources
  • Extracting Metadata from Design Tools Such As UML
  • Extracting Metadata from Existing Applications and Source Code
  • Why Extract Metadata?
  • Establishing Your Own XML Design Guidelines
  • Introducing the Tools for Metadata Extraction
  • Understanding XSD’s Role in Code Generation
  • Exploring the Structure of an XSD
  • Working with SQL-92 Databases (SQL Server)
  • Understanding the Tool Architecture
  • Working with Information Schema Views
  • Using Constraints
  • Modifying Mappings
  • Retrieving Stored Procedure Recordsets
  • Retrieving Identity Columns
  • Creating Freeform Metadata
  • Using Skip Attributes
  • Merging Metadata

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Extracting Metadata - Working with Information Schema Views


    (Page 15 of 22 )

    SQL-92 databases, such as SQL Server and Oracle, provide information schema views as a standard way to provide information about database schemas. These views are normalized, meaning that there are many of them. Information schema views are the best way to access structural information about your database. Accessing system tables directly isn’t a good idea because Microsoft might change the layout. The system stored procedure sp_help provides most of the information, but it’s more difficult to work with and it’s specific to SQL Server. So, the best approach is to use the SQL-92 information schema views.

    Understanding SQL-92 Terminology

    You’ll find several features in information schemas named in ways quite different from common SQL Server terminology. Table 2-3 shows the information schema and the corresponding SQL Server terms.

    Table 2-3. Translating Terminology Between Information Schema and SQL Server Terminology

    INFORMATION_SCHEMA

    SQL SERVER

    Catalog

    Database

    Schema

    Owner

    Routine

    Stored procedure or function

    Domain

    User-defined type

    RowVersion

    Timestamp

    Timestamp

    DateTime data type

    I’ll stick with SQL Server terminology because it sounds more familiar. The tool that extracts metadata from SQL-92 databases uses the underlying SQL-92 based table and column names to access the data, so you’ll need to be able to translate between the naming if you work with the internals of this tool.

    Object names for tables, views, user-defined types, stored procedures, and so on are all defined via a three-part name in information schema views. This name consists of the catalog or database name, schema or owner name, and the object name itself. Most of you are likely to target one database and the dbo in your applications, so I’ll stick with simple object names. If you’re targeting multiple databases or multiple owners, you may need to make changes to the metadata extraction classes to avoid potentially ambiguous naming across different scopes.

    Introducing the Specific Schemas

    Information schemas are views, not stored procedures. This means you select from them rather than call them. Also, unlike most things you encounter in SQL Server, the information schema views have to be fully qualified, such as this:

    SELECT * FROM INFORMATION_SCHEMA.SCHEMATA

    SCHEMATA is one of the 20 or so information schema views provided in the SQL-92 standard. The SCHEMATA view returns the databases available to the user within the server instance. Table 2-4 summarizes what information each view provides. For the full information on these views and what each returns, refer to the “INFORMATION_SCHEMA” section in the TSQL help you can access though Query Analyzer (or MSDN).

    Table 2-4. Individual Information Schema View Contents

    VIEWDESCRIPTIONCOMMENTS
    SCHEMATAContains a row for each database in which the user has permissions
    TABLESContains a row for each table
    TABLE_PRIVELEGESContains a row for each table privilege
    TABLE_CONSTRAINTSContains a rom for each table constraintSee the section "Using Constraints" for a discussion of how constraints work.

    CONSTRAINT_TABLE_USAGE

    Similar to TABLE_CONSTRAINTS with less informationNot used in tool.
    COLUMNSContains a row for each column

    COLUMN_PRIVILEGES

    Contains a row for each column privilege
    CONSTRAINT_COLUMN_USAGEContains a row for each column constraint

    COLUMN_DOMAIN_USAGE

    Contains a row for each column that’s defined as a user-defined type. This information is also contained in COLUMNSNot used in this metadata extraction.
    ROUTINESContains a row for each stored procedure or function
    PARAMETERS

    Contains a row for each stored procedure or function parameter

    ROUTINE_COLUMNSContains a row for each column returned from a table value functionDon’t get excited—this just applies to table value functions. I’ll show you later how to retrieve stored procedure recordset structures.
    CHECK_CONSTRAINTSContains a row for each accessible check constraint

    REFERENTIAL_CONSTRAINTS

    Contains a row for each accessible referential constraint
    KEY_COLUMN_USAGE

    Contains a row for each column used in an accessible key

    VIEWS

    One row for each accessible view

    VIEW_TABLE_USAGE

    Contains a row for each accessible table used in a view

    Not used in tool.
    VIEW_COLUMN_USAGEContains a row for each column used in each viewNot used in tool.
    DOMAINS

    Contains a row for each accessible user defined type

    DOMAIN_CONSTRAINTSContains a row for each constraint on an accessible user-defined type

    In the SQL-92 data extraction tool, I include features you’re likely to use and don’t attempt to incorporate everything from the schema views. For example, I ignore aspects such as character set, collations, and so on. If you’re using these features, you’ll want to extend the tool with a derived class or change the source code.   

    This is from Code Generation in Microsoft .NET, by Kathleen Dollard (Apress, ISBN 1590591372). Check it out at your favorite bookstore today. Buy this book now.

    More Database Articles
    More By Apress Publishing


     

    DATABASE ARTICLES

    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT