X hits on this document

PDF document

The “SQL Server Management Objects” series - page 4 / 6

18 views

0 shares

0 downloads

0 comments

4 / 6

www.tobuku.com

The “SQL Server Management Objects” series

{

L i s t V i e w I t e m i t e m = t h i s . l v O b j e c t . I t e m s . A d d ( v w . S c h e m a + " . + vw.Name); item.SubItems.Add("View"); "

}

}

}

//enumerate user triggers if (triggerList) //enumerate the tables first, then the triggers afterward { foreach (Microsoft.SqlServer.Management.Smo.Table tbl in database.Tables) { if (!tbl.IsSystemObject) //only user objects { foreach (Microsoft.SqlServer.Management.Smo.Trigger tr in tbl.Triggers) { ListViewItem item = this.lvObject.Items.Add(tbl.Schema + "." + tr.Name); item.SubItems.Add("Trigger"); item.SubItems.Add(tbl.Name);

}

}

}

}

...

The program responsible to generate the SQL script file is displayed as follow. Firstly the program opens a dialog window for you to enter the file name for the SQL script file to be generated. The subsequent lines determine which object that selected from the list, then identifying the object type, schema name and the object name. The SQL script is produced by executing the Script method of the corresponding object where its output is stored in a StringCollection object. Later each string (that represents a line of SQL command) should be extracted from the collection and appended line by line to construct a complete T-SQL program in a text format.

... private void btnGenerateScript_Click(object sender, EventArgs e) {

if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string fileName = saveFileDialog1.FileName;

string dbName =

cboDatabase.Items[cboDatabase.SelectedIndex].ToString(); Microsoft.SqlServer.Management.Smo.Database database =

server.Databases[dbName];

ListViewItem item = this.lvObject.SelectedItems[0]; string itemName = item.SubItems[0].Text;

  • -

    4-

Document info
Document views18
Page views18
Page last viewedSat Dec 03 10:55:04 UTC 2016
Pages6
Paragraphs110
Words1400

Comments