我正在运行 SQL Server 2012。
SQL Server Management Studio 可以选择右键单击数据库,然后选择任务和生成脚本。
有没有办法通过命令行以某种方式自动化?
我想创建一个包含整个数据库的架构和数据的脚本。
之类的工具ScriptDB
,并sqlpubwiz.exe
似乎都针对SQL Server 2005的什么有关SQL Server 2012?
使用 Sql Server 2012,有人可以向我展示一个简单的 powershell 3 脚本来生成我的整个数据库(架构和数据)吗?
我试过这个:
$Filepath='d:\b\t' # local directory to save build-scripts to
$DataSource='HH' # server name and instance
$Database='HMovies'# the database to copy from
# set "Option Explicit" to catch subtle errors
set-psdebug -strict
$ErrorActionPreference = "stop" # you can opt to stagger on, bleeding, if an error occurs
# Load SMO assembly, and if we're running SQL 2008 DLLs load the SMOExtended and SQLWMIManagement libraries
$ms='Microsoft.SqlServer'
$v = [System.Reflection.Assembly]::LoadWithPartialName( "$ms.SMO")
if ((($v.FullName.Split(','))[1].Split('='))[1].Split('.')[0] -ne '9') { …
Run Code Online (Sandbox Code Playgroud)