CREATE VIEW SQL:通过SQL Server中的视图插入数据

This is the third article in a series of learning the CREATE VIEW SQL statement. So far, I’d say that we’re comfortable and familiar with the syntax, and we’ve learned how to create and modify views. In this part, we’ll continue to work on views using the sample database and data that we created so far.

这是学习CREATE VIEW SQL语句系列的第三篇文章。 到目前为止,我想说我们对语法很熟悉并且很熟悉,并且我们已经学习了如何创建和修改视图。 在这一部分中,我们将继续使用迄今为止创建的示例数据库和数据来处理视图。

To briefly summarize the series, in the first part about Creating views in SQL Server, the idea was to get familiar with the CREATE VIEW SQL syntax, all the different things we can do with views, and creating a really basic view.

为了简要总结该系列,在关于在SQL Server中创建视图的第一部分 ,其想法是熟悉CREATE VIEW SQL语法,我们可以使用视图进行的所有不同操作以及创建一个真正的基本视图。

In the second part about Modifying views in SQL Server, we upped the difficulty a little bit and created a more complex view with aggregates in it. Furthermore, we got familiar with the ALTER VIEW statement used to change the output by changing the definition and structure of a query.

在有关在SQL Server中修改视图的第二部分 ,我们稍微提高了难度,并创建了一个更复杂的视图,其中包含聚合。 此外,我们熟悉了用于通过更改查询的定义和结构来更改输出的ALTER VIEW语句。

介绍 (Introduction)

Although this article can be read independently from the first two, it’s highly advisable to head over and read the previous two parts to get the full picture and because it will be easier to follow along.

尽管可以从前两部分中独立阅读本文,但还是建议您先阅读并阅读前两部分以获取完整信息,因为这样做会更容易。

Now it’s time to start using Data Manipulation Language (DML) that is used to manipulate data itself and see how we can insert data into a table through a view.

现在是时候开始使用数据操纵语言(DML)了,该语言用于操纵数据本身,并了解如何通过视图将数据插入表中。

However, before we actually insert data through a view, let’s see how we can rename a view. I also want to show you one neat thing that we can do WITH CHECK OPTION which is a part of the CREATE VIEW SQL syntax. This option can be useful when inserting data through a view which you’ll see later in this article.

但是,在实际通过视图插入数据之前,让我们看看如何重命名视图。 我还想向您展示我们可以使用WITH CHECK OPTION进行的一件整洁的事情,它是CREATE VIEW SQL语法的一部分。 通过视图插入数据时,此选项很有用,您将在本文后面看到。

重命名视图 (Renaming views)

Views are renamed using the sp_rename system stored procedure. By definition, this SP is used for changing the name of a user-created object in the current database. Having said that, changing any part of an object name, including views, can break scripts and dependencies, which is why it’s not recommended to use this statement to rename views or any other user-created object. The smart thing to do would be to drop the object and re-create it with the new name using the CREATE VIEW SQL statement.

使用sp_rename系统存储过程将视图重命名。 根据定义,此SP用于更改当前数据库中用户创建的对象的名称。 话虽如此,更改对象名称的任何部分(包括视图)都可能破坏脚本和依赖关系,这就是为什么不建议使用此语句来重命名视图或任何其他用户创建的对象的原因。 明智的做法是删除对象,然后使用CREATE VIEW SQL语句以新名称重新创建该对象。

使用第三方软件解决方案重命名视图 (Renaming views using a third-party software solution)

If you want to play it safe, I’d suggest a third-party software solution for safely renaming SQL objects. I, personally, use free SQL Server Management Studio and Visual Studio add-ins for SQL Server called ApexSQL Search and ApexSQL Refactor. Both add-ins have a feature called Safe rename that renames tables, procedures, views, functions, and columns without breaking dependencies.

如果您想安全地使用它,我建议使用第三方软件解决方案来安全地重命名SQL对象。 我个人使用免费SQL Server Management Studio和Visual Studio加载项(用于ApexSQL SearchApexSQL Refactor)来访问SQL Server。 这两个加载项均具有称为“ 安全重

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值