You are on page 1of 2

/* Autor: Luan Moreno M.

Maciel Data de Criao: 22/03/2012 Data ltima Atualizao: //2012 Responsvel ltima Atualizao: */ USE AdventureWorksDW2012 go

--************************************************************* --dbo.vw_DadosSequence --************************************************************* IF OBJECT_ID('dbo.vw_DadosSequence') IS NOT NULL DROP VIEW dbo.vw_DadosSequence GO CREATE VIEW dbo.vw_DadosSequence AS WITH DadosSequence AS ( SELECT S.object_id, SE.name + '.' + S.name AS name, S.type, S.type_desc, S.create_date, S.modify_date, S.start_value, S.increment, S.current_value, S.minimum_value, S.maximum_value, S.is_cycling, S.is_cached, S.cache_size, ST.name AS TypeData, S.precision, S.scale, S.is_exhausted FROM sys.sequences AS S INNER JOIN sys.schemas AS SE ON SE.schema_id = S.schema_id INNER JOIN sys.types AS ST ON ST.system_type_id = S.system_type_id AND ST.user_type_id = S.user_type_id ) , DadosConstraint AS ( SELECT REPLACE(REPLACE(REPLACE(REPLACE(SUBSTRING(SDC.definition,17,LEN(SD C.definition)),'[',''),']',''),')',''),'dbo.','') AS SequenceName, T.name AS TableName, SDC.name AS ConstraintName, SDC.type, SDC.type_desc, SDC.definition FROM sys.tables AS T INNER JOIN sys.default_constraints AS SDC ON T.object_id = SDC.parent_object_id

WHERE LEFT(SDC.definition,15) = '(NEXT VALUE FOR' ) SELECT DS.object_id, DS.name AS SequenceName, DC.TableName, DC.ConstraintName, DS.type, DS.type_desc, DS.create_date, DS.modify_date, DS.start_value, DS.increment, DS.minimum_value, DS.maximum_value, DS.current_value, DS.is_cycling, DS.is_cached, DS.cache_size, DS.TypeData, DC.type AS TypeConstraint, DC.type_desc AS TypeDescConstraint, DC.definition FROM DadosSequence AS DS LEFT OUTER JOIN DadosConstraint AS DC ON REPLACE(DS.name,'dbo.','') = DC.SequenceName -SELECT * FROM AdventureWorksDW2012.dbo.vw_DadosSequence ORDER BY SequenceName

You might also like