什么是SQL命令返回表的字段名? [英] What is the SQL command to return the field names of a table?

查看:104
本文介绍了什么是SQL命令返回表的字段名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个名为myTable的表。什么是SQL命令以返回此表的所有字段名称?如果答案是数据库特定的,那么我现在需要SQL Server,但也有兴趣看到其他数据库系统的解决方案。

解决方案

MySQL 3和4(和5):

  desc tablename 
/ pre>

这是

的别名

  

SQL Server(从2000开始)和MySQL 5:

 从INFORMATION_SCHEMA.COLUMNS中选择COLUMN_NAME 
其中TABLE_NAME ='tablename'

完成答案:像下面的人说的,在SQL Server中,您还可以使用存储过程 sp_help

  exec sp_help'tablename'


Say I have a table called myTable. What is the SQL command to return all of the field names of this table? If the answer is database specific then I need SQL Server right now but would be interested in seeing the solution for other database systems as well.

解决方案

MySQL 3 and 4 (and 5):

desc tablename

which is an alias for

show fields from tablename

SQL Server (from 2000) and MySQL 5:

select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS 
where TABLE_NAME = 'tablename'

Completing the answer: like people below have said, in SQL Server you can also use the stored procedure sp_help

exec sp_help 'tablename'

这篇关于什么是SQL命令返回表的字段名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆