SQL Server 防止脚本在错误的实例上运行

发布于 2024-07-16 11:20:51 字数 1542 浏览 10 评论 0原文

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

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

发布评论

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

评论(4

深陷 2024-07-23 11:20:51

我的所有脚本都以此开头:

if exists (select 1 from dbo.environment where value in('production', 'qa'))
  return

当然,这意味着我有一个环境表,并且其中有“生产”、“开发”、“质量保证”等,具体取决于它的托管位置。

All my scripts start with this :

if exists (select 1 from dbo.environment where value in('production', 'qa'))
  return

Of course this means that I have an environment table and have 'production' , 'development' , 'qa' etc. in it depending on where it is hosted.

近箐 2024-07-23 11:20:51

干得好:
http://www.ssmstoolspack.com/

这个免费的 SSMS 插件为每个服务器提供窗口着色。

here you go:
http://www.ssmstoolspack.com/

this free SSMS addin provides windows coloring per server.

巨坚强 2024-07-23 11:20:51

此 SQL 代码检查您是否位于正确的服务器上:

if @@servername <> 'testserver'
  RAISERROR ( 'Wrong server', 16, 1 );

错误(或就此而言返回)将阻止执行,直到下一个 GO 语句为止。 例如,以下命令仍会打印 hello world,并删除 user 表:

RAISERROR ( 'Wrong server', 16, 1 );
go
drop table users
print 'Hello world!'
go

This SQL code checks if you're on the right server:

if @@servername <> 'testserver'
  RAISERROR ( 'Wrong server', 16, 1 );

An error (or return for that matter), will prevent execution until the next GO statement. For example, the following will still print hello world, and delete the user table:

RAISERROR ( 'Wrong server', 16, 1 );
go
drop table users
print 'Hello world!'
go
最单纯的乌龟 2024-07-23 11:20:51

您可以为您通常使用的用户在您的实时实例上设置不同的(有限的)访问权限。
然后使用不同的用户名在实时系统上执行任何重要的操作。

You can set different (limited) access right on you live instance for the user you normally use.
And then have a different user name for doing any serious stuff on the live system.

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