Management Studio 如何知道保存我的 T-SQL 注释?
我对 SQL Server Management Studio 保存视图、存储过程等注释的方式感到困惑。
假设我正在更改视图,并在 ALTER 语句之前添加一些注释:
USE [SomeDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Let's add some comments about this view!
ALTER VIEW [dbo].[MyView]
AS
SELECT Stuff
FROM TableOfStuff
-- To get the other stuff, we have to do an inner join
INNER JOIN OtherStuff
ON TableOfStuff.OtherKey = OtherStuff.StuffKey
GO
当我在 Management 中运行上述代码时工作室,我的观点将被改变,评论将被保存。如果我稍后执行 Script View As -->更改为 -->新的查询窗口
,评论将重新出现。
那么 Management Studio 如何知道这些评论“属于”视图呢?它与SET QUOTED_IDENTIFIER ON
有关吗?
I'm confused about the way that SQL Server Management Studio saves the comments of views, stored procedures, etc.
Let's say I'm altering a view and I put some comments in before the ALTER statement:
USE [SomeDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Let's add some comments about this view!
ALTER VIEW [dbo].[MyView]
AS
SELECT Stuff
FROM TableOfStuff
-- To get the other stuff, we have to do an inner join
INNER JOIN OtherStuff
ON TableOfStuff.OtherKey = OtherStuff.StuffKey
GO
When I run the above code in Management Studio, my view will be altered AND the comments will be saved. If I later do a Script View As --> ALTER TO --> New Query Window
, the comments will reappear.
So how does Management Studio know that those comments 'belong with' the view? Does it have something to do with SET QUOTED_IDENTIFIER ON
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ALTER VIEW 之前的 GO 和 ALTER View 之后的 GO 之间的内容都将被保存
Go 是批处理终止符,因此这 2 个 GO 语句之间的所有内容都是批处理,这就是发送的内容
What ever is between the GO before ALTER VIEW and the GO after ALTER View will be saved
Go is a batch terminator, so everything between those 2 GO statements is a batch, and that is what is sent
它不是 Management Studio,而是 sql server 本身。
无论您在服务器中创建什么(索引、SP,等等),sql server 都会保存您用于创建对象的文本。
It's not management studio but sql server it self
Whatever you create in your server (index, SP, whatever), sql server will save the text you used to create the object.