/****** Object: View [dbo].[viewMeta_TableColumns] Script Date: 05/09/2010 09:13:14 ******/
IF EXISTS (SELECT * FROM sys.views
WHERE object_id = OBJECT_ID(N'[dbo].[viewMeta_TableColumns]'))
DROP VIEW [dbo].[viewMeta_TableColumns]
GO
/****** Object: View [dbo].[viewMeta_TableColumns]
Script Date: 05/09/2010 09:13:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewMeta_TableColumns]
AS
-- Action !!!
SELECT top 100000
db_name() AS 'DataBaseName'
,isc.TABLE_SCHEMA AS 'SchemaName'
,SysObjects.NAME AS 'TableName'
,SC.NAME AS 'ColumnName'
,isc.ORDINAL_POSITION AS 'OrdinalPosition'
,st.name AS 'DataType'
,sc.is_nullable AS 'IsNullable'
,sc.is_identity AS 'IsPrimaryKey'
,sc.max_length AS 'MaxLength'
,SC.is_computed AS 'IsComputed'
,sm.text AS 'DefaultValue'
FROM dbo.sysobjects
INNER JOIN sys.all_columns SC ON SysObjects.id = SC.object_id
INNER JOIN sys.types st on st.system_type_id = sc.system_type_id
LEFT JOIN syscomments sm on SysObjects.id = sm.id
-- LEFT JOIN sys.tables stb on sc.object_id = SysObjects.parent_obj
LEFT JOIN INFORMATION_SCHEMA.COLUMNS isc on
isc.TABLE_NAME=SysObjects.NAME and SC.NAME = isc.COLUMN_NAME
--LEFT JOIN dbo.syscomments SM ON SC.cdefault = SM.id
--inner join sys.types st
--on sc.xtype = st.system_type_id
WHERE SysObjects.xtype = 'U'
and st.name <> 'sysname' --to a bug with this one occurs if enabled
and sc.is_computed = 0 --todo a bug with this one occurs if enabled
--and SysObjects.name = @TableName --uncomment this line while debugging
ORDER BY DatabaseName , SchemaName , TableName , isc.ORDINAL_POSITION
GO
--select * from sys.schemas
select * from [viewMeta_TableColumns]
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!