Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return the SQL data types from my query?

I've a SQL query that queries an enormous (as in, hundreds of views/tables with hard-to-read names like CMM-CPP-FAP-ADD) database that I don't need nor want to understand. The result of this query needs to be stored in a staging table to feed a report.

I need to create the staging table, but with hundreds of views/tables to dig through to find the data types that are being represented here, I have to wonder if there's a better way to construct this table.

Can anyone advise how I would use any of the SQL Server 2008 tools to divine the source data types in my SQL 2000 database?

As a general example, I want to know from a query like:

SELECT Auth_First_Name, Auth_Last_Name, Auth_Favorite_Number  FROM Authors 

Instead of the actual results, I want to know that:

Auth_First_Name is char(25) Auth_Last_Name is char(50) Auth_Favorite_Number is int 

I'm not interested in constraints, I really just want to know the data types.

like image 313
JMP Avatar asked Oct 21 '09 15:10

JMP


People also ask

How do I find the datatype of a table in SQL?

You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.

What command do you use to retrieve specific types of data from a SQL database?

SELECT statements An SQL SELECT statement retrieves records from a database table according to clauses (for example, FROM and WHERE ) that specify criteria. The syntax is: SELECT column1, column2 FROM table1, table2 WHERE column2='value';

How do I export data from a query?

Select a view in the User-Defined Data Views log and click the Data button. The results window will display the query results. Click the Export As CSV button. At the prompt, you can choose to Open or Save the resulting CSV file to your local drive.


1 Answers

select * from information_schema.columns 

could get you started.

like image 136
erikkallen Avatar answered Oct 08 '22 09:10

erikkallen