Friday, January 18, 2013

SQL Server: Some Useful Schema Scripts

Here are some helpful scripts that help me to find out more about the table's I'm working on.

Getting more information about a table.  This stored procedure returns the table's columns, primary key, foregin keys, contrstraints, which tables reference this one, and more.


Getting the SQL for a view (or a trigger or stored procedure). Here is another stored procedure that fetches the create statement for various objects.

Getting the triggers on a table. If you ever need to know what triggers are executing on a table this one is very helpful, especially when also used with the query to get the SQL for a trigger above.

Getting the triggers on a table II. Here is another way to get the triggers which seems to work better.

Getting a table's columns. While this does basically repeat the functionality of the first query, it does introduce INFORMATION_SCHEMA, which contains lots of information about your schema in general.
Getting a table's indexes

And also while I'm listing some useful things for SQL Server, here are a couple links for some useful sql formatters.

And here some more more useful SQL Server tools from SO.

No comments:

Post a Comment