[转]SQL 读取表结构

Posted z5337

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转]SQL 读取表结构相关的知识,希望对你有一定的参考价值。

1、Sql
SELECT column_name as FName,data_type as FType,CHARACTER_MAXIMUM_LENGTH as FLen from information_schema.columns where table_name=‘" + Table + "‘";
SELECT b.name, a.name FName from sysobjects b join syscolumns a on b.id = a.cdefault where a.id = object_id(‘" + Table + "‘) ";

2、Oracle
SELECT DATA_LENGTH AS LEN FROM USER_TAB_COLUMNS WHERE UPPER(TABLE_NAME)=‘" + Table.ToUpper() + "‘ AND UPPER(COLUMN_NAME)=‘" + Field.ToUpper() + "‘"
SELECT DATA_TYPE,OWNER FROM ALL_TAB_COLUMNS WHERE upper(TABLE_NAME)=‘" + Table.ToUpper() + "‘ AND UPPER(COLUMN_NAME)=‘" + Field.ToUpper() + "‘"

3、mysql
select character_maximum_length as Len, table_schema as OWNER,DATA_TYPE FROM information_schema.columns WHERE TABLE_SCHEMA=‘" + DBDatabase + "‘ AND table_name =‘" + Table + "‘ and column_Name=‘" + Field + "‘"

 

来自:https://gitee.com/opencc

以上是关于[转]SQL 读取表结构的主要内容,如果未能解决你的问题,请参考以下文章

sqlserver转oracle(三) 数据迁移及数据结构处理

MySQL索引优化-性能分析Explain(转)

用户定义函数内的 Sql Server 表结构

实战:从Mysql数据库frm文件中,提取表结构创建SQL语句

[sql]mysql指引(整理中...)

[转]SQL truncate delete与drop区别