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 :
- right click on database
- select task
- select generate script task
- follow steps
finally finish complete process
you can either use sql server management object api (see task "creating, altering , removing databases"):
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
Post a Comment