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]