数据库文档管理与开发环境搭建
立即解锁
发布时间: 2025-08-30 01:40:22 阅读量: 10 订阅数: 17 AIGC 

### 数据库文档管理与开发环境搭建
#### 1. 数据库文档发布与 YAML 解析
提取数据库文档后,由于选择了 YAML 作为标准(因其可读性强),需要将其转换为 XML。虽然有 YAXML 这样的工具,但它并不完善,所以可以自己编写一个工具来完成转换。
##### 1.1 YAML 简介
YAML 是 JSON 的超集,由 Clark Evans 在 2001 年首次提出,全称为 “YAML Ain't Markup Language”。它以一种直观的方式序列化对象和关系数据,是面向数据的表示法,而非文档标记。YAML 使用缩进表示层次信息,字符串无需分隔符,能实现比标记语言更好的压缩。若不方便使用缩进,还可采用类似 JSON 的格式。同时,YAML 文件可使用 grep、awk、Perl、Ruby 和 Python 等工具进行过滤。
##### 1.2 文档发布到表格的代码示例
以下是将所有例程的头部发布到表格的代码:
```sql
ALTER PROCEDURE ExtractDocumentation
/**
summary: >
Gets the source of every routine in the database and extracts the header
files from them, and then parses the YAML file to extract a relational table
with all the information.
Revisions:
– version : 1
Modification: Created the procedure
Author : Phil Factor
Date : 01/10/2010
example:
– code: >
returns: >
The documentation table
*/
AS
DECLARE @documentation TABLE
(
[object_type] VARCHAR(32) ,
[schema] SYSNAME ,
[object_name] SYSNAME ,
[sequence_ID] INT ,
[path] VARCHAR(255) ,
[attribute] VARCHAR(255) ,
[sequence] VARCHAR(255) ,
[value] VARCHAR(MAX)
)--the table to take the documentation items
DECLARE @allObjects TABLE
(
TheID INT IDENTITY(1, 1) ,
[object_type] VARCHAR(32) ,
[schema] SYSNAME ,
[object_name] SYSNAME ,
[definition] VARCHAR(MAX)
)-- the table containing all the objects
DECLARE @Definition VARCHAR(MAX) ,
@Header VARCHAR(MAX) ,--what is in the header information
@Object_name SYSNAME ,--the object name
@schema SYSNAME ,--the schema
@Object_type VARCHAR(32) ,--the type of object
@ii INT ,--iteration counter
@iiMax INT -- max value of iteration counter
INSERT INTO @AllObjects
( [object_type] ,
[schema] ,
[object_name] ,
[definition]
)
SELECT REPLACE(SUBSTRING(v.name, 5, 31), 'cns', 'constraint') ,
object_schema_name(o.object_ID) ,
OBJECT_NAME(o.object_ID) ,
definition
FROM sys.sql_modules sm
INNER JOIN sys.objects AS o ON sm.object_id = o.OBJECT_ID
LEFT OUTER JOIN master.dbo.spt_values v -- to get the type of object
```
0
0
复制全文
相关推荐









