September 26, 2005 at 7:23 am
I'm using SQL-DMO with C# and have no problem scripting out portions of our databases however when I try to script out indexes on views, I get nothing in return even though my views do have indexes on them. The Microsoft SQL Server documentation states that you can script out indexes for both tables and views, however I've had no luck. My code looks like:
foreach(SQLDMO.View2 view in database.Views){
if (!view.SystemObject){
string objectScriptText = view.Script(SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_NonClusteredIndexes,
"",
SQLDMO.SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_UnicodeFile);
if (objectScriptText != null){
objectScriptText = objectScriptText.Trim();
if (objectScriptText.Length > 0){
string filePath = CreateFilePath(subDirectoryName, view.Name, scriptType);
WriteFile(filePath, objectScriptText, view.Name, appendFile);
appendFile = true;
}
}
}
}//foreach
September 27, 2005 at 12:18 am
try iterating the index objects (using index2) - foreach(SQLDMO.Index2 in View2.indexes){//your code}
regards,
Mark Baekdal
+44 (0)141 416 1490
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change management for SQL Server
September 27, 2005 at 6:08 am
I can get the indexes to script if I also script the view itself using SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_Default. I was attempting to script out the indexes to a separate file from the script that creates the view. I'll give your solution a try. Thanks
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply