Solved

How to create a table in SQL Server 2005 using SMO?

Posted on 2008-06-25
3
236 Views
Last Modified: 2013-11-26
How to create a table in SQL Server 2005 using SMO?
Please provide sample code.
0
Comment
Question by:sepknow
3 Comments
 
LVL 13

Accepted Solution

by:
rickchild earned 250 total points
ID: 21866537
0
 
LVL 9

Assisted Solution

by:Rob Siklos
Rob Siklos earned 250 total points
ID: 21866561
Add a reference to:
  Microsoft.SqlServer.ConnectionInfo
  Microsoft.SqlServer.Smo
  Microsoft.SqlServer.SqlEnum

Then:

using Microsoft.SqlServer.Management.Common;

using Microsoft.SqlServer.Management.Smo;
 

class Test {
 

  public void CreateTable() {

    using (SqlConnection dbConn = new SqlConnection(CONN_STRING))

    {

        Server server = new Server(new ServerConnection(dbConn));

        Database db = server.Databases[dbConn.Database];
 

        Table table = new Table(db, "MyTable");
 

        Column col = new Column(table, "MyColumn", DataType.Int);

        col.Nullable = false;

        table.Columns.Add(col);
 

        table.Create();

    }

  }

}

Open in new window

0
 

Author Closing Comment

by:sepknow
ID: 31470592
Thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now