?
Solved

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

Posted on 2008-06-25
3
Medium Priority
?
248 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 1000 total points
ID: 21866537
0
 
LVL 9

Assisted Solution

by:Rob Siklos
Rob Siklos earned 1000 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

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

864 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