CREATE PROC dbo.gp_TableScript
@table VARCHAR(100) = NULL
AS
BEGIN
DECLARE @cmd VARCHAR(4000)
DECLARE @ord_pos INT
SET @ord_pos = 1

PRINT  'IF OBJECT_ID(''dbo.' + RTRIM(@table) + ''') IS NOT NULL'
PRINT  '	DROP TABLE dbo.' + @table
PRINT  'go'
PRINT  'CREATE TABLE dbo.' + @table + '(' 
	
WHILE @ord_pos < (SELECT MAX(ordinal_position) FROM INFORMATION_SCHEMA.COLUMNS
			WHERE table_name = @table)+1
BEGIN
	SET @cmd = 
	-- Alternative to scripting, shows defaults inline
	(SELECT CHAR(9) + SUBSTRING(t1.column_name,1,60) + CHAR(9) 
		+ RTRIM(t1.data_type) 
		+ CASE WHEN COLUMNPROPERTY(OBJECT_ID(t1.table_name), t1.column_name, 		'isidentity') = 1 THEN ' identity' ELSE '' END
		+ CASE WHEN t1.data_type IN('char', 'varchar', 'nchar', 'nvarchar') THEN 	'(' + RTRIM(character_maximum_length) + ')'
			WHEN t1.data_type IN('decimal', 'numeric') THEN '(' + 		RTRIM(numeric_precision) + ',' + RTRIM(numeric_scale) + ')'
			ELSE '' END
		+ CHAR(9) 
		+ CASE WHEN Is_Nullable = 1 THEN 'NULL' ELSE 'NOT NULL' END
		+ CHAR(9) 
		+ CASE WHEN DATALENGTH(t1.column_default) > 0 THEN 'DEFAULT ' + t1.column_default ELSE '' END
		+ CASE WHEN @ord_pos+1 < (SELECT MAX(ordinal_position) FROM INFORMATION_SCHEMA.COLUMNS
			WHERE table_name = @table) + 1 THEN ',' ELSE '' END
		FROM information_schema.columns t1
		WHERE t1.table_name = @table
		AND t1.ordinal_position = @ord_pos)
	PRINT @cmd
	SET @ord_pos = @ord_pos + 1
END
PRINT ')'
END
