Friday, 8 November 2013

Get all TableName and column name with datatypes in sql server

Share it Please
SELECT SysObjects.[Name] as TableName,
SysColumns.[Name] as ColumnName,
CASE SysTypes.[Name]
WHEN
'sysname'THEN
'nvarchar'
ELSE
SysTypes.[Name]
END
AS [Name]
,CASE SysTypes.[Name]
WHEN
'nvarchar'THEN
SysColumns.[Length] / 2
WHEN
'sysname'
THEN
SysColumns.[Length] / 2
ELSE
SysColumns.[Length]
END
AS [Length]
FROM
SysObjects INNER JOIN SysColumns
ON SysObjects.[Id] = SysColumns.[Id]
INNER JOIN SysTypes
ON SysTypes.[xtype] = SysColumns.[xtype]
WHERE SysObjects.[type] = 
'U'ORDER BY SysObjects.[Name]

No comments:

Post a Comment

Followers

Follow The Author