4922: ALTER TABLE ALTER COLUMN failed because one or more objects access this column(ALTER TABLE ALTER COLUMN 失败,因为有一个或多个对象访问此列)
SQL Server含义
您试图更改列的类型/属性,但依赖该列的对象(索引、约束、计算列、统计信息、架构绑定视图等)阻止了此操作。在解除依赖之前无法更改该列。
原因
该列被用于索引、PRIMARY KEY/UNIQUE/CHECK/DEFAULT 约束、计算列表达式、以 WITH SCHEMABINDING 定义的视图/函数,或统计信息对象。类型/大小的更改会使这些对象失效,因此 ALTER 被拒绝。
解决方法
先找出依赖对象并暂时删除或禁用它们,修改列后再重新创建。查询 sys.sql_expression_dependencies 和 sys.indexes/sys.default_constraints 查看依赖关系。典型顺序:DROP CONSTRAINT/INDEX -> ALTER COLUMN -> 重新 CREATE。对于架构绑定视图,暂时去掉 SCHEMABINDING,之后再加回。
同一数据库的其他条目
- 15023User already exists in the current database(用户在当前数据库中已存在)
- 18452Login failed. The login is from an untrusted domain and cannot be used with Windows authentication(登录失败。该登录名来自不受信任的域,不能用于 Windows 身份验证)
- 605Attempt to fetch logical page belongs to a different allocation unit(尝试获取的逻辑页属于另一个分配单元)
- 7202Could not find server 'name' in sys.servers(在 sys.servers 中找不到服务器 'name')
- 40501The service is currently busy. Retry the request after 10 seconds(服务当前繁忙。请在 10 秒后重试请求)
- 8645A time out occurred while waiting for memory resources to execute the query(等待执行查询所需的内存资源时超时)
- 8651Could not perform the operation because the requested memory grant was not available(无法执行操作,因为请求的内存授予不可用)