如何使用SQL查询在SQL SERVER 2008 R2中获取表定义? [英] How I can get table definition in SQL SERVER 2008 R2 using SQL query?
问题描述
我创建了一个示例java程序,使用以下查询获取视图,触发器,函数等所有对象的定义: -
I have created a sample java program in which I get the definition of all objects like views, triggers, functions, etc. using the following queries:-
select object_definition(object_id) from sys.objects where type='V'; //for Views
select object_definition(object_id) from sys.objects where type='TF'; //for Functions
select object_definition(object_id) from sys.objects where type='TR'; //for Triggers
select object_definition(object_id) from sys.objects where type='P'; //for Stored Procedures
但是以下查询无法获取ddl(表定义)表: -
But the following query doesn't work to get ddl(table definition) for tables:-
select object_definition(object_id) from sys.objects where type='U'; //for User defined Tables
现在我正在使用此处给出的解决方案:为包含查询的现有表生成SQL创建脚本
和< a href =http://www.c-sharpcorner.com/uploadfile/67b45a/how-to-generate-a-create-table-script-for-an-existing-table/ =nofollow noreferrer>如何为现有表生成CREATE TABLE脚本:第1部分
Right now I am using the solutions given here: Generate SQL Create Scripts for existing tables with Query and How to Generate a CREATE TABLE Script For an Existing Table: Part 1
是否有任何直接的SQL查询,我可以使用它来获取表定义。
Is there any direct sql query using which I can get the Table definition.
推荐答案
查看
SELECT * FROM INFORMATION_SCHEMA.TABLES
和
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
这篇关于如何使用SQL查询在SQL SERVER 2008 R2中获取表定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!