SQL statement to get column type

2019-01-10 00:21发布

Is there a SQL statement that can return the type of a column in a table?

标签: sql schema
18条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-10 00:41

For SQL Server, this system stored procedure will return all table information, including column datatypes:

exec sp_help YOURTABLENAME
查看更多
萌系小妹纸
3楼-- · 2019-01-10 00:42

For Spark SQL:

DESCRIBE [db_name.]table_name column_name
查看更多
一夜七次
4楼-- · 2019-01-10 00:43

For IBM DB2 :

SELECT TYPENAME FROM SYSCAT.COLUMNS WHERE TABSCHEMA='your_schema_name' AND TABNAME='your_table_name' AND COLNAME='your_column_name'
查看更多
Anthone
5楼-- · 2019-01-10 00:43

Using TSQL/MSSQL

You can use INTO keyword.

The result of SELECT into a real TABLE

Example: select .... INTO real_table_name

After

sp_help real_table_name
查看更多
趁早两清
6楼-- · 2019-01-10 00:45

In my case I needed to get the data type for Dynamic SQL (Shudder!) anyway here is a function that I created that returns the full data type. For example instead of returning 'decimal' it would return DECIMAL(18,4): dbo.GetLiteralDataType

查看更多
戒情不戒烟
7楼-- · 2019-01-10 00:46

Using SQL Server:

SELECT DATA_TYPE 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE 
     TABLE_NAME = 'yourTableName' AND 
     COLUMN_NAME = 'yourColumnName'
查看更多
登录 后发表回答