SQL Server Management Objects Introduction

Source: Internet
Author: User
Tags management studio sql server management sql server management studio

SMO is short for objecmanagement objects. It is a management object provided by sql2005. It is a logical evolution version of SQL-DMO. Its main function is C: microsoft under/program files/Microsoft SQL Server/90/SDK/assemblies. sqlserver. SMO. DLL files, which can be directly developed by vs2005.Program.

Msdn reference:

Http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx.

The document lists seven major functions. In fact, it is no exaggeration to say that as long as SQL Server Management studio can implement things, it can be implemented with SMO, because SQL Server Management studio is developed with SMO. If you have enough strength, you can develop a tool that can despise SQL Server Management studio, such as adding smart sensing functions.

The specific detailed application will not be expanded here. There are too many objects... for example, many people ask how to generate the SQL object script:

 
-- Create a test environment first use tempdbcreate table test (ID int identity ))
// Add reference // Microsoft. sqlserver. connectioninfo. DLL // Microsoft. sqlserver. SMO. DLL Microsoft. sqlserver. management. common. serverconnection conn = new Microsoft. sqlserver. management. common. serverconnection (new system. data. sqlclient. sqlconnection ("Server = localhost; uid = sa; Pwd = ***; database = Master"); // a database connection string Microsoft. sqlserver. management. SMO. server = new Microsoft. sqlserver. management. SMO. server (conn); Microsoft. sqlserver. management. SMO. database DB = server. databases ["tempdb"]; Microsoft. sqlserver. management. SMO. table TB = dB. tables ["test"]; system. collections. specialized. stringcollection SC = TB. script (); foreach (string s in SC) {console. writeline (s );}

Output: Set ansi_nulls on set quoted_identifier on create table [DBO]. [test] ([ID] [int] identity (1, 1) not null) on [primary]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.