在SSMS中,我使用以下脚本创建数据库。当脚本执行完成时,我希望在sql_modules表中看到CREATE TABLE语句。但是我找不到它。
CREATE DATABASE [MyDb]
GO
USE [MyDb]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MyTable] (
[UID] [uniqueidentifier] NOT NULL,
[DateTime] [datetime] NOT NULL
)
这是我运行获取表定义的查询。但是,我得到三个空结果集。知道为什么我得到这三个空结果?
USE MyDb
GO
SELECT *
FROM sys.sql_modules
SELECT *
FROM sys.triggers
SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_desc, sm.definition
FROM sys.sql_modules AS sm
JOIN sys.objects AS o ON sm.object_id = o.object_id
ORDER BY o.type;
答案 0 :(得分:2)
要获取列和表信息,这是一个很好的起点:
SELECT c.*, t.*
FROM sys.tables AS t
INNER JOIN sys.columns AS c ON t.object_id = c.object_id
INNER JOIN sys.schemas AS sch ON t.schema_id = sch.schema_id
WHERE sch.name = 'dbo'
AND t.name = 'YourTable'