如何在sql server 2008中获取alter table脚本? [英] How to get alter table script in sql server 2008?

查看:85
本文介绍了如何在sql server 2008中获取alter table脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sql server 2008中获取alter table脚本?

How to get alter table script in sql server 2008?

推荐答案

这不是那么简单,因为该选项是灰色的(可以理解,因为没有变化在保存的表中)

但是,你可以这样做。



打开SSMS,在对象资源管理器窗格中选择你的数据库。 br />
打开Tables分支,右键单击要编写脚本的表格。

从菜单中选择设计

进行一项微不足道的更改(将允许空列切换为是并返回否)或进行真正的更改。

不要保存!

现在右键单击上部窗格(不是带有列属性选项卡的窗格)。

从上下文菜单中选择生成更改脚本...。

你系统会询问您是否要将其保存为文本文件。



It's not that simple, because the option is greyed out (understandably, since there are no changes in a saved table)
But, you can do it.

Open SSMS, and select your database in the Object explorer pane.
Open the Tables branch, and right click the table you want to script.
From the menu, select "Design"
Make a trivial change (switch a "Allow Nulls" column to "Yes" and back to "No") or make genuine changes that you need to make.
DO NOT SAVE!
Now right click in the upper pane (not the pane with the "Column Properties" tab).
Select "Generate Change Script..." from the context menu.
You will be asked if you want to save this to a text file.

/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.MyTable SET (LOCK_ESCALATION = TABLE)
GO
COMMIT





请注意,这不包含表结构的完整信息。

如果您想要ALTER脚本中的完整信息,请生成CREATE TO脚本,然后更改手动更改指令。



Note that this doesn't contain full info on the table structure.
If you want full info in the ALTER script, generate a CREATE TO script instead, and change the instruction to ALTER manually.


这篇关于如何在sql server 2008中获取alter table脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆