有没有一种简单的方法可以将自定义迁移脚本添加到 SQL Compare 脚本中?

发布于 2024-07-19 11:28:30 字数 167 浏览 4 评论 0原文

在我的工作中,我们目前在跨环境推动数据库更改方面遇到了一些严重的困难。 当我们在现有表上创建新的不可空列时,问题就开始出现。 SQL Compare 生成的脚本将该列创建为不可空列,因此它始终会失败。 我希望有一些替代方法可以替代手动编辑脚本。 有什么办法可以解决这个问题吗? 如果没有的话,你们是怎么处理的?

At my work we are currently having some serious pains pushing our database changes across environments. The issue starts to show up when we create a new non-nullable column on an existing table. The script that SQL Compare generates creates the column as non-nullable, so it will always fail. I was hoping that there was some alternative to having to manually edit the script. Is there any way to get around this? If not, how do you guys handle it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

话少情深 2024-07-26 11:28:31

创建表:

create table #bingo ( id int )

添加值:

insert into #bingo values (1)

添加新列:

alter table #bingo add userid int

填充新列:

update #bingo set userid = 1 where id = 1

将新列更改为不可为空:

alter table #bingo alter column userid int not null

您必须手动编辑 RedGate Sql Compare 才能使其像这样工作。

Create a table:

create table #bingo ( id int )

Add a value:

insert into #bingo values (1)

Add a new column:

alter table #bingo add userid int

Populate the new column:

update #bingo set userid = 1 where id = 1

Change the new column to not nullable:

alter table #bingo alter column userid int not null

You would have to manually edit the RedGate Sql Compare to make it work like this.

黯淡〆 2024-07-26 11:28:31

您打算如何填充 NOT NULL 列? 我不明白 SQL Compare 如何真正提出解决方案,因为它无法知道如何填充它。

您可以使用 DEFAULT 创建列,然后只需在生成的脚本末尾添加更新语句即可正确更新列(如果您有值的某些来源)。

How do you plan on filling the NOT NULL column? I don't see how SQL Compare could really come up with a solution since it has no way of knowing how you would fill it.

You could create the column with a DEFAULT, then simply add an update statement at the end of the generated scripts to properly update the column if you have some source for the values.

欢烬 2024-07-26 11:28:31

在新的非空列上添加默认值

创建新的非空列时,所有现有行会获得什么值? 如果您不知道,请将该列设为可为空。

add a default onto the new not null column

when creating a new not null column, what value do all the existing rows get? If you don't know, make the column nullable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文