`
izuoyan
  • 浏览: 8968081 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

SqlServer Management Objects简介

阅读更多

Smo是SqlServer Management Objects的简称,由SQL2005提供的管理对象,sql-dmo的逻辑进化版本,主要功能由C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies下面的Microsoft.SqlServer.Smo.dll文件中的相关 对象来实现,可以直接由vs2005开发的程序来引用。

msdn参考文档:

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

文档中他列举了7条大的功能,其实毫不夸张地说,只要SQL Server Management Studio能实现的东西,用smo都能实现,因为SQL Server Management Studio就是用smo开发的。如果你有足够的实力,完全可以开发一个可以藐视SQL Server Management Studio的工具,比如加入智能感知的功能。

具体详细应用这里就不展开了,对象太多...只举一个例子,很多人问的如何生成sql对象的脚本:

--先搞一个测试环境

use tempdb

create table test(id int identity(1,1))
//添加引用

            //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"));//一个数据库连接字符串

            Microsoft.SqlServer.Management.Smo.Server 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);

            }

输出: SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE TABLE [dbo].[test]( [id] [int] IDENTITY(1,1) NOT NULL ) ON [PRIMARY]

分享到:
评论

相关推荐

    SQL Server Management Objects的研究与应用.pdf

    SQL Server Management Objects的研究与应用.pdf

    SQL Server 2008 R2详解手册.pdf

    * Manage SQL Server 2008 more effectively with SQL Server Management Studio, the SQLCMD command-line query tool, and Powershell * Efficiently manage security, users, backup/restore, replication, ...

    Beginning T-SQL with Microsoft SQL Server 2005 and 2008

    Beyond the basics of database object management and security concepts, we recommend Beginning SQL Server 2005 Administration and Beginning SQL Server 2008 Administration from Wrox, co-authored in ...

    DevArt dbForge Studio for SQL Server Enterprise Edition 5.0.337

    dbForge Studio for SQL Server is a powerful IDE for SQL Server management, administration, development, data reporting and analysis. The tool will help SQL developers to manage databases, speed up ...

    Beginning Transact-SQL with SQL Server 2000 and 2005 (4 of 5)

    <br>Table of Contents Beginning Transact-SQL with SQL Server 2000 and 2005 Foreword Chapter 1 - Introducing Transact-SQL and Data Management Systems Chapter 2 - SQL Server ...

    SQL Server with C#

    SQL Server with C# Klaus Elk (Author) Paperback: 146 pages 出版社: CreateSpace Independent Publishing Platform (July 5, 2018) Language: English ISBN-10: 1720358672 ISBN-13: 9781720358671 Contents 1 ...

    Inside Microsoft SQL Server 2000

    13. Special Transact-SQL Operations: Working with Cursors and Large Objects [加入我的離線書架] . Cursor Basics . Cursors and ISAMs . Cursor Models . Appropriate Use of Cursors . Working with ...

    SQL Server 2014 Development Essentials - Masood-Al-Farooq, Basit A. [SRG].pdf

    how you can use SQL Server Management Studio to create and manage SQL Server 2014 databases, schemas, and tables. Finally, this chapter covers the purpose of SQL Server 2014 system databases and ...

    Beginning Transact-SQL with SQL Server 2000 and 2005 (2 of 5)

    Chapter 1 - Introducing Transact-SQL and Data Management Systems Chapter 2 - SQL Server Fundamentals Chapter 3 - Tools for Accessing SQL Server Chapter 4 - Introducing Transact-SQL Language ...

    Beginning Transact-SQL with SQL Server 2000 and 2005 (1 of 5)

    Chapter 1 - Introducing Transact-SQL and Data Management Systems Chapter 2 - SQL Server Fundamentals Chapter 3 - Tools for Accessing SQL Server Chapter 4 - Introducing Transact-SQL Language ...

    Beginning Transact-SQL with SQL Server 2000 and 2005 (5 of 5)

    <br>Table of Contents Beginning Transact-SQL with SQL Server 2000 and 2005 Foreword Chapter 1 - Introducing Transact-SQL and Data Management Systems Chapter 2 - SQL Server ...

    Beginning Transact-SQL with SQL Server 2000 and 2005 (3 of 5)

    <br>Table of Contents Beginning Transact-SQL with SQL Server 2000 and 2005 Foreword Chapter 1 - Introducing Transact-SQL and Data Management Systems Chapter 2 - SQL Server ...

    C#列出局域网中可用SQL Server服务器

    SQLDMO(SQL Distributed Management Objects,SQL分布式管理对象)封装了Microsoft SQL Server数据库中的对象。SQLDMO是Microsoft SQL Server中企业管理器所使用的应用程序接口,所以它可以执行很多功能,其中当然也...

    Troubleshooting SQL Server - A Guide for the Accidental DBA

    其次再说,这是一份非常好的资料,关于SQL Server性能调优和故障排除的难得的一本好书。前提是你的有良好的英文阅读能力。 最后,目录如下: 1、A Performance Troubleshooting Methodology 2、Disk I/O ...

    sqldmo.dll

    SQL-DMO的全称是SQL Distributed Management Objects。它是一个集合,包含一组有双重接口的COM。通过SQL-DMO我们可以控制操作SQL Server 的数据库引擎和复制管理。由于SQL-DMO是一组COM,所以任何可以使用COM的开发...

    Beginning T-SQL 2012, 2nd Edition.pdf

    If you are reading this book, you probably know about T-SQL....quick tour of SQL Server Management Studio (SSMS) and introduces a few concepts to help you become a proficient T-SQL programmer.

    [开发工具] SQL Toolbelt 1.8.2.238

    SQL Refactor - helps the user to automatically format your SQL code and database objects that provides a fast and easy management of databases. SQL Doc - provides a mnogodokumentalnoy database. SQL ...

    用SQL分布式管理对象创建数据库备份

    SQL分布式管理对象(SQL Distributed Management objects, SQL-DMO)为开发者提供了使用程序和脚本语言执行普通任务的方法,从而扩展了SQL Server功能。本文谈论如何用SQL-DMO创建数据库备份和校验的ASP应用。

    C#使用SQLDMO操作数据库的方法

    SQLDMO(SQL Distributed Management Objects,SQL分布式管理对象)封装 Microsoft SQL Server 2000 数据库中的对象。SQL-DMO 允许用支持自动化或 COM 的语言编写应用程序,以管理 SQL Server 安装的所有部分。SQL-...

    RedGate.SQL.Prompt.v.5.1.8.2完美破解版

    Visual Studio 和 SQL Server Management Studio 均破解 RedGate SQL Prompt 5.1.8.2 SQL Prompt”充斥着的特点,采取日常工作与SQL出来的,离开你把重点放在棘手位。 当你写代码,SQL Prompt建议适当的关键字和...

Global site tag (gtag.js) - Google Analytics