【问题标题】:Copy a table with constraints in SQL server在 SQL Server 中复制带有约束的表
【发布时间】:2023-04-04 13:27:01
【问题描述】:

当我执行以下查询时,我可以制作一个没有约束的表的副本

Select * into B from A

如何通过 SQL 查询复制带约束的表?

【问题讨论】:

  • 您可以执行该表的脚本,在此期间您可以查看include indexesinclude foreign keysinclude constraintsinclude drop table等高级设置。
  • 这能回答你的问题吗? Copy or Clone SQL table with constraints
  • 您不能复制或克隆导出的 FK 约束(指向该约束的其他表)。在这些情况下你想做什么?
  • 我只需要主键约束

标签: sql sql-server tsql


【解决方案1】:

试试下面的查询:

SELECT *
INTO New Table  
FROM old table
WHERE Constraints  

例子:

SELECT *
INTO Employee3  
FROM Employee  
WHERE [EMP Id] > 1  

【讨论】:

  • 约束未复制
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-17
  • 2018-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多