set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[proc_DataSelect]
@tabelName varchar(100)
as
SELECT
-- TableName=o.name,
FieldId=c.colid,
FieldName=c.name,
FieldDescription=ISNULL(pfd.value,''),
FieldType=QUOTENAME(t.name)
+CASE
WHEN t.name IN (N'decimal',N'numeric')
THEN N'('+CAST(c.prec as varchar)+N','+CAST(c.scale as varchar)+N')'
WHEN t.name=N'float'
OR t.name like N'%char'
OR t.name like N'%binary'
THEN N'('+CAST(c.prec as varchar)+N')'
ELSE N'' END
+CASE WHEN c.isnullable=1 THEN N'' ELSE N' NOT' END+N' NULL',
DefileLength=c.length,
IsIDENTITY=COLUMNPROPERTY(o.id,c.name,N'IsIdentity'),
IsPrimaryKey=CASE WHEN opk.xtype IS NULL THEN 0 ELSE 1 END,
TableDescription=ISNULL(ptb.value,N'')
FROM sysobjects o
JOIN syscolumns c
ON c.id=o.id
AND OBJECTPROPERTY(o.id,N'IsUserTable')=1
JOIN systypes t
ON t.xusertype=c.xusertype
LEFT JOIN syscomments df
ON df.id=c.cdefault
LEFT JOIN sys.extended_properties ptb
ON ptb.major_id =o.id and ptb.minor_id=0
LEFT JOIN sys.extended_properties pfd
ON pfd.major_id =o.id and pfd.minor_id=c.colid
LEFT JOIN sysindexkeys idxk
ON idxk.id=o.id
AND idxk.colid=c.colid
LEFT JOIN sysindexes idx
ON idx.indid=idxk.indid
AND idx.id=idxk.id
AND idx.indid NOT IN(0,255)
LEFT JOIN sysobjects opk
ON opk.parent_obj=o.id
AND opk.name=idx.name
AND OBJECTPROPERTY(opk.id,N'IsPrimaryKey')=1
where o.name=@tabelName
ORDER BY o.name,c.colid