数据库分析和理解表[关闭]
Posted
技术标签:
【中文标题】数据库分析和理解表[关闭]【英文标题】:Database analysis and understand tables [closed] 【发布时间】:2016-05-05 07:30:21 【问题描述】:有一个数据库。 后来我被包括在内。 我怎么知道这个数据库?有工具吗?
一个屏幕上的所有表格? 关系? 等等
注意:数据库 SQL 服务器
谢谢。
【问题讨论】:
你为什么不在SQL Server Management Studio
中创建一个New Database Diagram
并包括那里的所有表格? (它会绘制您的表格以及它们之间的关系。)
您是否考虑过与了解数据库的人交谈?
【参考方案1】:
有几个表格和命令可以帮助您。
获取数据库的ER图:
创建新的数据库图并包含您想要查看的表 关系。
要了解数据库中的所有表:
SELECT name Table FROM sys.objects WHERE type = 'U'
要了解数据库中的所有存储过程:
SELECT name Procedure FROM sys.objects WHERE type = 'P'
要了解与表相关的架构、约束和依赖关系:
EXEC sp_help <tablename>
我几年前编写的另一个程序,用于检查对一个或多个关键字的任何依赖关系:
/****** Object: StoredProcedure [dbo].[FindObjectsByKeywords] Script Date: 8/25/2015 2:36:31 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Kunal Chitkara
-- Description: Find dependencies of the delimited keywords entered in the first input.
-- Second input specifies the delimiter used, default being comma.
-- This procedure is dependent upon the utility function
-- Test Run: EXEC FindObjectsByKeywords @searchString = 'UserId,InstanceID', @delimiter = ','
-- =============================================
ALTER PROCEDURE [dbo].[FindObjectsByKeywords]
@searchString NVARCHAR(MAX) = '',
@delimiter NCHAR(1) = ','
AS
BEGIN
BEGIN TRY
IF (@searchString = '')
RAISERROR ('Invalid input', 16, 2)
DECLARE @iterator INT = 1,
@searchCount INT = 0
SELECT value SearchString, ROW_NUMBER() OVER (ORDER BY value) Sort_Order
INTO #SearchStrings
FROM [dbo].[stringlist_to_table] (@searchString, @delimiter)
SELECT @searchCount = MAX(Sort_Order)
FROM #SearchStrings
DECLARE @Result TABLE
(
Dependency NVARCHAR(256),
Type NVARCHAR(120),
KeyWords NVARCHAR(MAX)
)
WHILE (@iterator <= @searchCount)
BEGIN
SELECT @searchString = SearchString
FROM #SearchStrings
WHERE Sort_Order = @iterator
INSERT INTO @Result (Dependency, Type, KeyWords)
SELECT DISTINCT so.name, sysObj.type_desc, @searchString
FROM sysobjects so
INNER JOIN syscomments sc ON sc.id = so.id
INNER JOIN sys.objects sysObj ON sysObj.object_id = so.id
WHERE CHARINDEX(@searchString, sc.text) > 0
ORDER BY name
SET @iterator = @iterator + 1;
END
IF EXISTS (SELECT * FROM @Result)
BEGIN
SELECT
P.Dependency,
P.Type,
STUFF
(
(
SELECT ',' + KeyWords
FROM @Result M
WHERE M.Dependency = P.Dependency AND M.Type = P.Type
ORDER BY KeyWords
FOR XML PATH('')
), 1, 1, ''
) AS KeyWords
FROM @Result P
WHERE P.Dependency != 'FindObjectsByKeywords'
ORDER BY KeyWords, Dependency
END
ELSE
PRINT 'No dependencies of the input keywords found.'
DROP TABLE #SearchStrings
END TRY
BEGIN CATCH
IF (ERROR_STATE() = 2)
RAISERROR ('Invalid input. Make sure you enter at least one keyword. More keywords can be entered in the first delimited parameter', 16, 1);
END CATCH
END
【讨论】:
以上是关于数据库分析和理解表[关闭]的主要内容,如果未能解决你的问题,请参考以下文章
顺序表超详细解析 | 从零开始一步步解读 | 画图理解+调试分析 | 早起狂肝两万字数据结构