0

在 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;
4

1 回答 1

2

To get columns and table information, this is a good place to start:

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'
于 2012-11-01T17:05:14.677 回答