关于包含外键约束的截断表 [英] Regarding Truncate Table including Foreign key constraint

查看:77
本文介绍了关于包含外键约束的截断表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多表包含外键,我想使用存储过程截断所有表.

如果有人有解决办法,请给我发邮件

Many tables contain a Foreign key and I would like to truncate all tables using a stored procedure.

If any one have solution kindly mail me

推荐答案

您不能截断具有父子关系的表
最好先从子表中删除记录,然后再从父表中删除记录.然后使用以下方法将父表的标识(如果有)重新设置为0:
DBCC CHECKIDENT(表名,种子,0)
You can not truncate a table which has parent-child relationship
It would be better if you first delete the records from the child tables and then from parent tables. Then reseed the identity (if any) of parent table to 0 using:
DBCC CHECKIDENT(tablename,reseed,0)


这篇关于关于包含外键约束的截断表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆