|
From: Ramesh Subramaniyan on 2 Jul 2008 06:21 foreach (Table NewTable in TblCollection) { if (NewTable.IsSystemObject == false) { string ObjectName; Scripter NewScripter = new Scripter(); DataRow dr = dbTable.NewRow(); dr["objName"] = NewTable.Name; dbTable.Rows.Add(dr); StringCollection SPscript = NewTable.Script(); string[] scriptArray = new string[SPscript.Count]; SPscript.CopyTo(scriptArray, 0); } } with help of above coding i can take ony table definition , i need all table dependent objects such as Pk ,FK,Defauls ....) can any one post coding for taking full table definition adv thanks
From: Plamen Ratchev on 2 Jul 2008 10:06 The easiest way is to set the scripting options to include all indexes, checks (via setting to true the properties ClusteredIndexes, NonClusteredIndexes, DriAll, Indexes, etc.): http://msdn.microsoft.com/de-de/library/microsoft.sqlserver.management.smo.scriptingoptions_properties.aspx Here is one example: http://www.devx.com/dotnet/Article/35552/0/page/3 Alternatively, inside the innermost IF statement you can add code to script each sub-collection of the Table object: foreach (Index ndx in NewTable.Indexes) { if (ndx.IndexKeyType.ToString() == "DriUniqueKey") { // script ndx here } else if (ndx.IndexKeyType.ToString() == "DriPrimaryKey") { // script ndx here } else // index { // script ndx here } foreach (Check chk in NewTable.Checks) { // script chk here } foreach (Column col in NewTable.Columns) { if (col.DefaultConstraint != null) { // script colDefaultConstraint here } } HTH, Plamen Ratchev http://www.SQLStudio.com
|
Pages: 1 Prev: SQL Wishes , Correct path Next: Linked Server and Stored Procedure |