小编mou*_*aim的帖子

级联主键更新所有引用外键

是否可以通过在引用它的所有外键之间级联更新来更新主键列值?

# EDIT 1: 当我运行 followinq 查询

select * from sys.foreign_keys where referenced_object_id=OBJECT_ID('myTable') 
Run Code Online (Sandbox Code Playgroud)

,我看到 update_referential_action 设置为 0。因此更新我的主键列后没有采取任何操作。如何更新外键以使其ON CASCADE UPDATE

# EDIT 2:
为了编写或删除架构中所有外键的脚本,请运行以下脚本(取自此处

DECLARE @schema_name sysname;

DECLARE @table_name sysname;

DECLARE @constraint_name sysname;

DECLARE @constraint_object_id int;

DECLARE @referenced_object_name sysname;

DECLARE @is_disabled bit;

DECLARE @is_not_for_replication bit;

DECLARE @is_not_trusted bit;

DECLARE @delete_referential_action tinyint;

DECLARE @update_referential_action tinyint;

DECLARE @tsql nvarchar(4000);

DECLARE @tsql2 nvarchar(4000);

DECLARE @fkCol sysname;

DECLARE @pkCol sysname;

DECLARE @col1 bit;

DECLARE @action char(6);  

DECLARE @referenced_schema_name sysname;



DECLARE FKcursor …
Run Code Online (Sandbox Code Playgroud)

sql-server-2008 foreign-key sql-server referential-integrity update

13
推荐指数
2
解决办法
6万
查看次数

为什么我收到此请求的错误“在预期条件的上下文中指定的非布尔类型”?

我收到此错误:
"Error 102 : non-boolean type specified in a context where a condition is expected"
对于此请求:

DECLARE @num_dossiers TABLE (num_dossier INT,indice NVARCHAR(3))
insert into @num_dossiers
select num_dossier,indice from dossier where num_sec=57

delete from constitue where (num_dossier,indice) in select (num_dossier,indice) from @num_dossiers  
Run Code Online (Sandbox Code Playgroud)

触发错误的请求是最后一个:

delete from constitue where (num_dossier,indice) in select (num_dossier,indice) from @num_dossiers   
Run Code Online (Sandbox Code Playgroud)

导致此错误的原因可能是什么?

sql-server-2008 sql-server

6
推荐指数
1
解决办法
1万
查看次数

主键和外键的大小

在 sql server 2008 中,主键和引用它的外键是否必须具有相同的列大小?有人可以告诉我一个解释这个的文档的链接吗?

谢谢你的帮助。

sql-server-2008 foreign-key primary-key

2
推荐指数
1
解决办法
3913
查看次数

查找列是否属于用户表

我想计算数据库中非空约束的列数。于是想到了查询表sys.all_columns:
select * from sys.all_columns

问题是它为我提供了我不需要的额外信息(系统定义表中的列)。

所以我必须添加一些SQL 代码来确定某些列是否属于用户定义表。最好的方法是什么?

sql-server-2008 sql-server

2
推荐指数
1
解决办法
1297
查看次数