Scripts sql (maintenance)
De Wiki1000
Version du 27 novembre 2023 à 09:41 par Syfre (discuter | contributions)
RootOID
Retourne le max des racines d'OID d'une base de données avec OID caractères.
DECLARE @SQL nvarchar(max)
DECLARE @TableName sysname
DECLARE @TableUID int
DECLARE @RootOID int
DECLARE @MaxUID int
DECLARE @MaxTableName sysname
SELECT @MaxUID = 0
SELECT @RootOID = cValue from sysCounter where cName='RootOID'
DECLARE tables_cursor CURSOR FAST_FORWARD
FOR
select t.name from sys.all_columns c
join sys.tables t on t.object_id = c.object_id
where c.name='oid'
OPEN tables_cursor
FETCH NEXT FROM tables_cursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @SQL = 'select @TableUID = MAX(convert(INT, CONVERT(VARBINARY,''0x''+SUBSTRING(oid,21,8),1) )) from '+ @TableName
EXEC sp_executesql @SQL, N'@TableUID int OUTPUT, @TableName varchar', @TableUID OUTPUT, @TableName = @TableName
IF (@TableUID > @MaxUID )
BEGIN
SELECT @MaxUID=@TableUID
SELECT @MaxTableName = @TableName
END
FETCH NEXT FROM tables_cursor INTO @TableName
END
SELECT @MaxTableName, @MaxUID, @RootOID
CLOSE tables_cursor
DEALLOCATE tables_cursor
| Whos here now: Members 0 Guests 0 Bots & Crawlers 1 |