简体   繁体   English

从 SQL 服务器中的表中删除特定列时,更改存储过程不会引发“无效列名”错误

[英]Altering a stored procedure not throwing “Invalid column name” error when that particular column is removed from the table in SQL Server

I have removed a column from a table which is referred in a stored procedure.我从存储过程中引用的表中删除了一个列。 When I alter that stored procedure, there is no error, but when executing it, an error当我更改该存储过程时,没有错误,但是在执行它时,出现错误

Invalid column name列名无效

is thrown.被抛出。

I'm using SSMS 2017我正在使用 SSMS 2017

You are looking for functionality called "schema binding".您正在寻找称为“模式绑定”的功能。 This means that if you cannot change the schema of an object if it is being referenced in a view or stored procedure.这意味着如果 object 在视图或存储过程中被引用,则无法更改它的架构。

This is handled on the dependent level, rather than on the original object.这是在依赖级别上处理的,而不是在原始 object 上处理。 The place to start is with the documentation on SCHEMABINDING .开始的地方是SCHEMABINDING上的文档。

In practice, this means the following procedure:在实践中,这意味着以下程序:

  1. Alter the object (ie table).更改 object(即表)。
  2. Get a schema binding error.获取架构绑定错误。
  3. Drop the schemabinding option on all objects that refer to the original object.删除引用原始 object 的所有对象的模式绑定选项。
  4. Modify the original object.修改原来的object。
  5. Modify the dependent objects.修改依赖对象。
  6. Be sure schema binding is back "on" the dependent objects.确保模式绑定重新“打开”依赖对象。

It is a bit cumbersome, but it helps enforce database dependencies.这有点麻烦,但它有助于强制执行数据库依赖关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server - 只有通过 ADO.NET 执行存储过程时才会出现“无效的列名”异常 - SQL Server - 'Invalid column name' exception only when executing stored procedure through ADO.NET 创建存储过程时,无效的列名错误 - Invalid column name error when creating a stored procedure 存储过程中的“无效的列名” - 'Invalid column name' from within a stored procedure 尝试从表映射中选择时,SQL Server错误“无效的列名” - SQL Server error “Invalid Column Name” when trying to select from table mapping 插入/更新过程给出无效的列名错误SQL Server - Insert/ Update Procedure gives Invalid Column Name Error SQL Server 创建合并过程时,SQL Server 2014中出现“无效的列名”错误 - “Invalid column name” error in SQL Server 2014 when creating a merge procedure 存储过程在列名上引发错误 - Stored Procedure throwing errors on Column Name 如何在SQL Server中将列名和表名作为参数传递给存储过程? - How to pass column name as well as Table Name to a stored procedure as a parameter in SQL Server? 将表名和列名动态传递给 PL/SQL 存储过程 - Passing table name and column name dynamically to PL/SQL Stored procedure 存储过程执行期间无效的列名错误 - Invalid Column name error during execution of stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM