SQL 获取表结构
select
[表名]=c.Name,
[表说明]=isnull(f.[value],''),
[列序号]=a.Column_id,
[列名]=a.Name,
[列说明]=isnull(e.[value],''),
[数据库类型]=b.Name,
[类型]= case when b.Name = 'image' then 'byte[]'
when b.Name in('image','uniqueidentifier','ntext','varchar','ntext','nchar','nvarchar','text','char') then 'string'
when b.Name in('tinyint','smallint','int','bigint') then 'int'
when b.Name in('datetime','smalldatetime') then 'DateTime'
when b.Name in('float','decimal','numeric','money','real','smallmoney') then 'decimal'
when b.Name ='bit' then 'bool' else b.name end ,
[标识]= case when is_identity=1 then '是' else '' end,
[主键]= case when exists(select 1 from sys.objects x join sys.indexes y on x.Type=N'PK' and x.Name=y.Name
join sysindexkeys z on z.ID=a.Object_id and z.indid=y.index_id and z.Colid=a.Column_id)
then '是' else '' end,
[字节数]=case when a.[max_length]=-1 and b.Name!='xml' then 'max/2G'
when b.Name='xml' then '2^31-1字节/2G'
else rtrim(a.[max_length]) end,
[长度]=case when ColumnProperty(a.object_id,a.Name,'Precision')=-1 then '2^31-1'
else rtrim(ColumnProperty(a.object_id,a.Name,'Precision')) end,
[小数位]=isnull(ColumnProperty(a.object_id,a.Name,'Scale'),0),
[是否为空]=case when a.is_nullable=1 then '是' else '' end,
[默认值]=isnull(d.text,'')
from sys.columns a
left join sys.types b on a.user_type_id=b.user_type_id
inner join sys.objects c on a.object_id=c.object_id and c.Type='U'
left join syscomments d on a.default_object_id=d.ID
left join sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.Column_id and e.class=1
left join sys.extended_properties f on f.major_id=c.object_id and f.minor_id=0 and f.class=1
ORDER BY c.Name,a.Column_id
SQL 获取表结构的更多相关文章
- Sql中获取表结构(字段名称,类型,长度,说明)
Sql中获取表结构(字段名称,类型,长度,说明) SELECT TableName = OBJECT_NAME(c.object_id), ColumnsName = c.name, Descript ...
- Greenplum获取表结构
最近在折腾greenplum,遇到一个蛋疼的问题,那就是获取表结构,也就是建表语句.大家都知道在MySQL里面是非常easy的,show create table table_name 就搞定了,在g ...
- MySql 、Oracle 获取表结构和字段信息
1.MySql获取表结构信息 SELECT TABLE_NAME, TABLE_COMMENT FROM information_schema.`TABLES` WHERE TABLE_SCHEMA ...
- 【Navicat】获取表结构的DDL语句以及获取更新表字段的操作的DDL
1.获取表结构的DDL语句 2.获取修改表结构某一字段的DDL语句 设计表-修改表字段(记住不要保存)-SQL预览
- SQL Server 一句Sql把表结构全部查询出来
--一句Sql把表结构全部查询出来 SELECT 表名 = Case When A.colorder=1 Then D.name Else '' End, 表说明 = Case When A.colo ...
- sql复制表结构,复制表内容语句
sql复制表结构,复制表内容语句 select * into b from a where 1<>1 select top 0 * into b from a insert into a ...
- SQL server 表结构转Oracle SQL脚本
SQL server 表结构转Oracle SQL脚本 /****** Object: StoredProcedure [dbo].[getOracle] Script Date: 2019/7/25 ...
- sql server 获取表结构和记录数
表结构 then d.name else null end) 表名, a.colorder 字段序号,a.name 字段名, ( then '√'else '' end) 标识, (case when ...
- Oracle安装、Navicat for Oracle、JDBCl连接、获取表结构
Oracle安装 Navicat for Oracle配置 Oracle JDBC连接(增删改查) Oracle安装 环境windows 7 64位 安装版本:oracle 11g(64位) 下载地址 ...
随机推荐
- SQL 农经权数据库问题提取_身份证号码相同(字段值出现多次);身份证号码相同但姓名不同(A字段相同,B字段不相同);发包方无承包方信息(A表有,B表无)等
身份证号码相同(字段值出现多次) select * from CBF_JTCY a,(select CYZJHM, count(*) from CBF_JTCY group by CYZJHM h ...
- Fatal error encountered during command execution
MySQL + .net + EF 开发环境,调用一处sql语句报错: Fatal error encountered during command execution[sql] view plain ...
- Java读取一个文本文件拼接成一个字符串(readFileToString)
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.I ...
- ARDUINO驱动LCD1602 (利用库函数)
LCD 1602简介 工业字符型液晶,能够同时显示16x02即32个字符.(16列2行) 1602液晶也叫1602字符型液晶,它是一种专门用来显示字母.数字.符号等的点阵型液晶模块.它由若干个5X7或 ...
- Python 并发编程
进程 开启进程 from multiprocessing import Process import time def task(name): print('%s is running' %name) ...
- Agiliq署名的免费python书籍
在他们的官网介绍中,说他们团队自2009年开始使用Django,Python,Postgres,Augular等工具来开发webapp,移动应用后台等.并且,他们还有一个Github组织,开源了相当多 ...
- [吐槽]webpack4
https://webpack.js.org/guides/tree-shaking/ https://www.webpackjs.com/guides/ 插件都过时被替代了,中文文档也没更新过来,坑 ...
- ubuntu系统检测端口占用情况
参考链接: https://blog.csdn.net/qwfys200/article/details/80837036 命令: $ sudo netstat -tupln
- Error occurred during initialization of VM Incompatible initial and maximum heap sizes specified
双击Tomcat server在eclipse弹出的Tomcat配置项里面选择open launch configuration 选择arguments在 vm arguments 里面添加 -Xms ...
- window mysql8.0 zip版本安装
第一步下载安装包 官方下载地址:https://dev.mysql.com/downloads/mysql/ 解压到D盘目录中D://db 第二步配置环境变量 编辑path内容 添加mysql地址 第 ...