copy database structure from sql server to other -


i want copy database sql server another, want copy structure (views, stored procedures, tables, fields, indexes, etc), no rows. tried generate script sql server management script verbose (task menu > create as)

follow below steps generate script :

c# code generate sql script :

public string generatescript() {       var sb = new stringbuilder();        var srv= new server(@"your database server name");       var db= server.databases["your database name"];        var scrpt = new scripter(srv);       scrpt.options.scriptdrops = false;        var obj= new urn[1];       foreach (table tbl in db.tables)       {           obj[0] = tbl.urn;           if (tbl.issystemobject == false)           {               stringcollection sc = scripter.script(obj);                foreach (var st in sc)               {                   sb.append(st);               }            }        }             return sb.tostring();  } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -