-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcol_def.sql
More file actions
33 lines (33 loc) · 813 Bytes
/
col_def.sql
File metadata and controls
33 lines (33 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
exec dbo.drop_if_exists 'dbo.col_def'
GO
-- Outputs column metadata in valid SQL for creating tables
create view dbo.col_def
as
select
table_catalog,
table_schema,
table_name,
column_name,
ordinal_position,
data_type +
case
when data_type in ('binary', 'char', 'float', 'nchar', 'nvarchar', 'varbinary', 'varchar') then
'(' +
case character_maximum_length
when -1 then
'max'
else cast(character_maximum_length as varchar(5))
end +
')'
when data_type in ('decimal', 'numeric') then
'(' + cast(numeric_precision as varchar(3)) + ',' + cast(numeric_scale as varchar(3)) + ')'
else ''
end as data_type,
case is_nullable
when 'NO' then 'not null'
when 'YES' then 'null'
else null
end as is_nullable,
column_default
from information_schema.columns
GO