How do I introspect on a SQL Server?

Posted by MetaHyperBolic on Stack Overflow See other posts from Stack Overflow or by MetaHyperBolic
Published on 2010-05-14T14:56:26Z Indexed on 2010/05/14 15:04 UTC
Read the original article Hit count: 167

Filed under:
|

I have a server with a vendor application which is heavily database-reliant. I need to make some minor changes to the data in a few tables in the database in an automated fashion. Just INSERTs and UPDATEs, nothing fancy. Vendors being vendors, I can never be quite sure when they change the schema of a database during upgrade.

To that end, how do I ask the SQL server, in some scriptable fashion, "Hey, does this table still exist? Yeah, cool, okay, but does it have this column? What's the data type and size on that? Is it nullable? Could you give me a list of tables? In this table, could you give me a list of columns? Any primary keys there?" I do not need to do this for the whole schema, only part of it, just a quick check of the database before I launch into things.

We have Microsoft SQL Server 2005 on it currently, but it might easily move to Microsoft SQL Server 2008. I am probably not using the correct terminology when searching. I do know that ORM is not only too much overhead for this sort of thing, but also that I have no chance of pitching it to my coworkers.

© Stack Overflow or respective owner

Related posts about sql

Related posts about introspection