While at work I had an irritation with my SQL Server database. My coworkers give me data to load and without fail I have to create new tables to accept the data that they give me. The data is all headed somewhere and that somewhere always has many tables and in each of those tables many columns. The need I have is for the names of those columns, their data types, how long they are, and what their collations are. I don’t really have any of that information written down and for the longest time I’ve been schlepping to sp_help ‘table name’ to find the answers and it’s been a right mess. The data is there, but it’s annoying as sp_help gives me way too much information and there is no way to trim it back. So, I created a new stored procedure and I named it “tattle”, here it is in T-SQL:
CREATE PROCEDURE [dbo].[tattle]
@MYARG char(255)
AS
SELECT COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=@MYARG
GO
I’m quite proud of what I accomplished and the output is EXACTLY what I need when I need it. To run it I just type in tattle ‘table’ and it spits out just what I am after.
It’s the little victories you have to savor. 🙂