code_junkie

How can I get SQL Server column definition with parentheses and everything?

Nov 12th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. select column_type = data_type +
  2. case
  3. when data_type like '%text' then ''
  4. when data_type like '%char' and character_maximum_length = -1 then '(max)'
  5. when character_maximum_length is not null then '(' + convert(varchar(10), character_maximum_length) + ')'
  6. when data_type = 'numeric' then '(' + convert(varchar(10), isnull(numeric_precision, 18)) + ', ' +
  7. convert(varchar(10), isnull(numeric_scale, 0)) + ')'
  8. else ''
  9. end
  10. ,*
  11. from information_schema.columns
Add Comment
Please, Sign In to add comment