SQL Server:删除表级联等效吗?

编程入门 行业动态 更新时间:2024-10-28 02:22:44
本文介绍了SQL Server:删除表级联等效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在oracle中,要删除所有表和约束,您将键入以下内容

In oracle, to drop all tables and constraints you would type something like

DROP TABLE myTable CASCADE CONSTRAINTS PURGE;

,这将完全删除表及其依赖项。什么是SQL Server等效项?

and this would completely delete the tables and their dependencies. What's the SQL server equivalent??

推荐答案

我不认为SQL具有类似的优雅解决方案。

I don't believe SQL has a similarly elegant solution. You have to drop any related constraints first before you can drop the table.

幸运的是,所有这些约束都存储在信息模式中,您可以访问它以获取表名。

Fortunately, this is all stored in the information schema and you can access that to get your whack list.

此博客文章应该能够为您提供所需的信息: weblogs.asp/jgalloway/archive/2006/04/12/442616.aspx

This blog post should be able to get you what you need: weblogs.asp/jgalloway/archive/2006/04/12/442616.aspx

-- t-sql scriptlet to drop all constraints on a table DECLARE @database nvarchar(50) DECLARE @table nvarchar(50) set @database = 'DatabaseName' set @table = 'TableName' DECLARE @sql nvarchar(255) WHILE EXISTS(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table) BEGIN select @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT ' + CONSTRAINT_NAME from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table exec sp_executesql @sql END

更多推荐

SQL Server:删除表级联等效吗?

本文发布于:2023-10-16 05:10:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:级联   SQL   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!