如何将表模式和约束复制到不同数据库的表? [英] How to copy a table schema and constraints to a table of different database?

查看:40
本文介绍了如何将表模式和约束复制到不同数据库的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用什么 SQL 将指定表的模式复制到不同数据库中的表?

What SQL can be used to copy the schema of a specified table to a table in different database?

推荐答案

SELECT INTO 将创建一个具有相同架构的新表.所以你可以:

SELECT INTO will create a new table with the same schema. So you could:

 SELECT *
 INTO newdb.dbo.newtable
 FROM olddb.dbo.oldtable

只复制架构而不是数据:

To just copy the schema and not the data:

 SELECT TOP 0 *
 INTO newdb.dbo.newtable
 FROM olddb.dbo.oldtable

这不会复制索引或键.要复制这些内容,请右键单击 SQL Sever Management Studio 中的表并选择脚本表为".这将为您提供一个可以在新数据库上运行的脚本.

This would not copy indexes or keys. To copy those, right click the table in SQL Sever Management Studio and choose 'Script table as'. That will give you a script you can run on the new database.

这篇关于如何将表模式和约束复制到不同数据库的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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