SQL 描述表结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3362225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Describe table structure
提问by Antoops
Which query will give the table structure with column definitions in SQL?
哪个查询将在 SQL 中给出带有列定义的表结构?
采纳答案by Pranay Rana
回答by schmijos
It depends from the database you use. Here is an incomplete list:
这取决于您使用的数据库。这是一个不完整的列表:
- sqlite3:
.schema table_name
- Postgres (psql):
\d table_name
- SQL Server:
sp_help table_name
(orsp_columns table_name
for only columns) - Oracle DB2:
desc table_name
ordescribe table_name
- MySQL:
describe table_name
(orshow columns from table_name
for only columns)
- sqlite3:
.schema table_name
- Postgres (psql):
\d table_name
- SQL Server:(
sp_help table_name
或sp_columns table_name
仅用于列) - 甲骨文 DB2:
desc table_name
或describe table_name
- MySQL:(
describe table_name
或show columns from table_name
仅用于列)
回答by Anax
In MySQL you can use DESCRIBE <table_name>
在 MySQL 中,您可以使用 DESCRIBE <table_name>
回答by Pankaj Upadhyay
select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='<Table Name>'
You can get details like column datatype and size by this query
您可以通过此查询获取列数据类型和大小等详细信息
回答by neeraj
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'student'
回答by Amarghosh
回答by Ozair Kafray
For Sybase aka SQL Anywhere the following command outputs the structure of a table:
对于 Sybase aka SQL Anywhere,以下命令输出表的结构:
DESCRIBE 'TABLE_NAME';
回答by Krishna Teja
Highlight table name in the console and press ALT+F1
在控制台中突出显示表名称并按 ALT+F1
回答by Karel Petranek
This depends on your database vendor. Mostly it's the "information schema" you should Google for (applies to MySQL, MSSQL and perhaps others).
这取决于您的数据库供应商。大多数情况下,它是您应该在 Google 上搜索的“信息模式”(适用于 MySQL、MSSQL 和其他可能)。
回答by Gabriele Petrioli
Sql server
数据库服务器
DECLARE @tableName nvarchar(100)
SET @tableName = N'members' -- change with table name
SELECT
[column].*,
COLUMNPROPERTY(object_id([column].[TABLE_NAME]), [column].[COLUMN_NAME], 'IsIdentity') AS [identity]
FROM
INFORMATION_SCHEMA.COLUMNS [column]
WHERE
[column].[Table_Name] = @tableName