由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 给一堆table,怎样能自动生成ERD
相关主题
the most stupid question请教:SQL面试题。
another question--怎么delete a row from a table急问一个关于T-SQL的问题,谢谢
How to find primary keytbl1.col1 = tbl2.col2 (+)
1. Oracle vs. SQL92 Re: JustMS SQL Group By Question
Help on migrating oracle to db2, outerjoin万佛,请教一个数据库问题 (转载)
难。想了一天了。大牛请进。求助SQL高手,这个join怎么做比较好
aks a simple SQL question求解释
如何在将学生成绩排序后,再加一个rank域新手请教:无数据库,有数据,需要SQL 做表join
相关话题的讨论汇总
话题: join话题: name话题: object话题: outer话题: table
进入Database版参与讨论
1 (共1页)
s********e
发帖数: 893
1
一个常见的问题是做一个新的复杂的数据库项目时,很多个table你不知道他们之间都
是什么关系。通过看每个table的constraints和dependecy,可以看到一个table的所有
FK都是reference哪个table的。我目前知道的在Oracle Sql Developer或Sq Server
management studio里都可以这样看到,但是只能一个table一个table的看。我想肯定
有一个tool,可以把这很多个table的关系自动生成一个ERD表,比如Table A的PK跟
Table B的FK自动连起来。请问Sql developer或sql server里都可以做吗?多谢了!
n***l
发帖数: 143
2
In SSMS, click on the database, then database diagrams, choose create new
database diagram. Add the table of interest, then right click on that table
to add the related tables.
My question is how to quickly figure out the relationships if the database
has over 5000 tables?
H*********e
发帖数: 276
3
在任何一个database 下, 用这个code 找, 我以前工作里面一个大牛给我的
select
pt.[name] as [ParentTable],
pc.[name] as [ParentColumn],
ct.[name] as [ChildTable],
cc.[name] as [ChildColumn]
from sys.foreign_key_columns fk
JOIN sys.columns pc on pc.column_id = fk.parent_column_id and pc.object_id =
fk.parent_object_id
JOIN sys.columns cc on cc.column_id = fk.referenced_column_id and cc.object
_id = fk.referenced_object_id
JOIN sys.objects pt on pt.object_id = pc.object_id
JOIN sys.objects ct on ct.object_id = cc.object_id
-----MetaLayer:
select
t.[name] as [TableName],
c.[name] as [ColumnName],
c.is_identity as [IsPk],
k.type as [ContraintType],
case when tFK.[name] is not null and cFk.[name] is not null then 1
else 0 end as [IsFk],
c.[is_nullable] as [IsNullable],
y.[name] as [DataType],

tFK.[name] + '.' +
cFk.[name] as [FkName],
c.max_length as [MaxLength],


c.precision as [ColumnPrecision],
c.scale as [ColumnScale],
def.definition as [DefaultValue]

from sys.objects t
join sys.columns c on c.object_id = t.object_id
join sys.types y on y.system_type_id = c.system_type_id
left outer join sys.foreign_key_columns fk on fk.parent_column_id = c.column
_id and fk.parent_object_id = c.object_id
left outer join sys.columns cFk on cFk.column_id = fk.referenced_column_id
and cFk.object_id = fk.referenced_object_id
left outer join sys.objects tFK on tFK.object_id = cFk.object_id
left outer join sys.default_constraints def on def.object_id = c.default_
object_id
left outer join sys.key_constraints k on k.parent_object_id = c.object_id
and k.unique_index_id = c.column_id
where t.type = 'U' and y.[name]!= 'sysname';
m******u
发帖数: 12400
4
thanks for sharing.
发信人: HoneyCoffee (贝贝), 信区: Database
标 题: Re: 给一堆table,怎样能自动生成ERD
发信站: BBS 未名空间站 (Sun Oct 11 22:24:08 2015, 美东)
在任何一个database 下, 用这个code 找, 我以前工作里面一个大牛给我的
select
pt.[name] as [ParentTable],
pc.[name] as [ParentColumn],
ct.[name] as [ChildTable],
cc.[name] as [ChildColumn]
from sys.foreign_key_columns fk
JOIN sys.columns pc on pc.column_id = fk.parent_column_id and pc.object_id =
fk.parent_object_id
JOIN sys.columns cc on cc.column_id = fk.referenced_column_id and cc.object
_id = fk.referenced_object_id
JOIN sys.objects pt on pt.object_id = pc.object_id
JOIN sys.objects ct on ct.object_id = cc.object_id
-----MetaLayer:
select
t.[name] as [TableName],
c.[name] as [ColumnName],
c.is_identity as [IsPk],
k.type as [ContraintType],
case when tFK.[name] is not null and cFk.[name] is not null then 1
else 0 end as [IsFk],
c.[is_nullable] as [IsNullable],
y.[name] as [DataType],

tFK.[name] + '.' +
cFk.[name] as [FkName],
c.max_length as [MaxLength],


c.precision as [ColumnPrecision],
c.scale as [ColumnScale],
def.definition as [DefaultValue]

from sys.objects t
join sys.columns c on c.object_id = t.object_id
join sys.types y on y.system_type_id = c.system_type_id
left outer join sys.foreign_key_columns fk on fk.parent_column_id = c.column
_id and fk.parent_object_id = c.object_id
left outer join sys.columns cFk on cFk.column_id = fk.referenced_column_id
and cFk.object_id = fk.referenced_object_id
left outer join sys.objects tFK on tFK.object_id = cFk.object_id
left outer join sys.default_constraints def on def.object_id = c.default_
object_id
left outer join sys.key_constraints k on k.parent_object_id = c.object_id
and k.unique_index_id = c.column_id
where t.type = 'U' and y.[name]!= 'sysname';
s**********o
发帖数: 14359
5
VISIO PREMIER可以直接REVERSE ENIGNEERING
1 (共1页)
进入Database版参与讨论
相关主题
新手请教:无数据库,有数据,需要SQL 做表joinHelp on migrating oracle to db2, outerjoin
long and CLOB.. any differences?难。想了一天了。大牛请进。
disable constraintaks a simple SQL question
请教constraints 如何在将学生成绩排序后,再加一个rank域
the most stupid question请教:SQL面试题。
another question--怎么delete a row from a table急问一个关于T-SQL的问题,谢谢
How to find primary keytbl1.col1 = tbl2.col2 (+)
1. Oracle vs. SQL92 Re: JustMS SQL Group By Question
相关话题的讨论汇总
话题: join话题: name话题: object话题: outer话题: table