锄头我可以比较两个数据库表吗? [英] Hoe can i compare two databse table column wise ?
问题描述
Hii,
我有两个数据库..我想在其他数据库表中检查第一个具有相同名称的数据库表...我的意思是我要检查两个列和数据类型和约束是否正确..如何在sql server 2012中执行此操作
Hii,
I have two databses .. I want to check first database table with same name in other database table .. i mean i want to check both columns and datatypes and constraints are proper or not .. how can i do that in sql server 2012
推荐答案
有几种方法可以做到这一点 - 但要么你需要一个工具,或者编写一些代码(因为这是一项单调乏味的工作)你可以检索表信息:
There are a couple of ways to do that - but either you need a tool, or to write some code (because it's a tedious job to do by eye) You can retrieve the table info:
SELECT column_name, data_type, is_nullable, character_maximum_length FROM information_schema.COLUMNS WHERE table_name='MyTable'
并重复一遍您感兴趣的其他信息:如果相同的查询返回两个表的相同数据,它们实际上是相同的。
但我使用的工具:ther e是相当多的(谷歌可以帮你找到它们),但RedGate会付出代价( http://www.red-gate.com/products/sql-development/sql-compare/ [ ^ ]但如果你只想使用它一次,价格会有点令人费解)并且有很多免费的: Google [ ^ ]
And repeat that for the other info you are interested in: if the same query returns the same data for both tables, they are effectively the same.
But I'd use a tool: there are quite a few (and Google can help you find them), but RedGate do one at a cost (http://www.red-gate.com/products/sql-development/sql-compare/[^] but the price is a little eye-watering if you are only going to use it once) and there are a number of free ones: Google[^]
如果它对你有帮助,可以在SQL Server 2012中试试这个。
http://stackoverflow.com/questions/11221183/sql-server-2008-compare-two -different-database-tables-for-column-name-data-type [ ^ ]
Try this in SQL Server 2012 if it helps you.
http://stackoverflow.com/questions/11221183/sql-server-2008-compare-two-different-database-tables-for-column-name-data-type[^]
这篇关于锄头我可以比较两个数据库表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!