Solved

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

Posted on 2008-06-25
3
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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