Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 将从数据库生成SQL Server脚本的脚本_Sql Server_Automation_Scripting_Containers - Fatal编程技术网

Sql server 将从数据库生成SQL Server脚本的脚本

Sql server 将从数据库生成SQL Server脚本的脚本,sql-server,automation,scripting,containers,Sql Server,Automation,Scripting,Containers,我有一个SQL Server数据库,其中包含我希望定期编写脚本的表和其他对象。我的想法是,我将创建一个autobuild,它将创建一个容器,该容器是该数据库的缩小版本(用于测试) 我可以很容易地手动编写数据库脚本,但随后我必须使生成的脚本保持最新 我想知道是否有一种方法可以通过编程方式连接到正在运行的SQL Server实例,并(根据一些输入)生成特定表、存储过程、用户定义类型和数据的脚本?如果您使用.NET或其他可以调用.NET对象的语言进行编码,您可以使用SMO中的脚本类(SQL管理对象)

我有一个SQL Server数据库,其中包含我希望定期编写脚本的表和其他对象。我的想法是,我将创建一个autobuild,它将创建一个容器,该容器是该数据库的缩小版本(用于测试)

我可以很容易地手动编写数据库脚本,但随后我必须使生成的脚本保持最新


我想知道是否有一种方法可以通过编程方式连接到正在运行的SQL Server实例,并(根据一些输入)生成特定表、存储过程、用户定义类型和数据的脚本?

如果您使用.NET或其他可以调用.NET对象的语言进行编码,您可以使用SMO中的脚本类(SQL管理对象)

SQL Server文档中有以下示例:


它们的设计完全符合您的要求。

嗯,我认为备份是最简单的方法

或者,设置几个作业,将所有内容打包成存储过程,并安排以您希望的频率运行

To create and attach a schedule to a job

    In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.

    Expand SQL Server Agent, expand Jobs, right-click the job you want to schedule, and click Properties.

    Select the Schedules page, and then click New.

    In the Name box, type a name for the new schedule.

    Clear the Enabled check box if you do not want the schedule to take effect immediately following its creation.

    For Schedule Type, select one of the following:

        Click Start automatically when SQL Server Agent starts to start the job when the SQL Server Agent service is started.

        Click Start whenever the CPUs become idle to start the job when the CPUs reach an idle condition.

        Click Recurring if you want a schedule to run repeatedly. To set the recurring schedule, complete the Frequency, Daily Frequency, and Duration groups on the dialog.

        Click One time if you want the schedule to run only once. To set the One time schedule, complete the One-time occurrence group on the dialog.

Autobuild SQL Server数据库?使用VS SQL数据库项目并通过.dacpac文件部署可以很好地解决这一问题。使用SQL Server阅读此内容,最好使用.bak文件。您可以在其他计算机上从该文件还原。