Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can OBJECTPROPERTY and INDEXPROPERTY be used across databas
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Can OBJECTPROPERTY and INDEXPROPERTY be used across databas
Divers
Thread ID:
01013663
Message ID:
01013663
Vues:
61
I am building a Stored procedure that when ran will reindex all indexes within a given database. Right now it works fine when ran from the database being reindexed, but I want this SP to reside only in a protected DBA database. The Driving query for this (the base of which I found online, then very heavily modified) is as follows:
SELECT 'Northwind' DBName
	, O.Name TableName
	, I.Name IndexName
	, 'DBCC INDEXDEFRAG (Northwind, ' + O.Name + ', ' + I.Name + ')' IndexDFCommand
	, CAST(0 AS BIT) IsDefragged
	FROM Northwind.dbo.SysObjects O
		INNER JOIN Northwind.dbo.SysIndexes I
			ON O.ID = I.ID
	WHERE O.xType = 'U'
		AND OBJECTPROPERTY(I.ID, 'IsMSShipped') = 0
		AND I.IndID NOT IN (0, 255)
		AND INDEXPROPERTY(I.ID, I.Name, 'IsStatistics') = 0
		AND INDEXPROPERTY(I.ID, I.Name, 'IsHypothetical') = 0
		AND INDEXPROPERTY(I.ID, I.Name, 'IsFulltextKey') = 0
This works fine cross-database so long as the OBJECTPROPERTY and INDEXPROPERTY clauses are removed.

To test this out, run it in Northwind, then any other DB.

Any help would be much appreciated!

TIA,
-Justin
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform