YoungManB
YoungManB

Reputation: 33

Best way to CREATE a SQL Server table via flat file schema?

I have a flat file table schema (tab delimited) from another type of database (I don't know what type), but it gives me the basics of what I need such as column name, data type, description. This table has many columns.

What is the best way to create a table in SQL Server 2008 from this flat file?

Upvotes: 1

Views: 898

Answers (1)

rs.
rs.

Reputation: 27437

Ex:

You can import file into a table with following columns

TableA:
    TABLE_NAME, COLUMN_NAME, DATA_TYPE, DESCRIPTION

Then generate create statement using script below and copy output and save as sql script

SELECT 'CREATE TABLE TABLE1 (' + cols + ')' FROM  (
SELECT SUBSTRING(
(SELECT ',' + s.COLUMN_NAME + ' ' DATA_TYPE
FROM tableA s WHERE TABLE_NAME = 'TABLE1'
FOR XML PATH('')),2,200000) AS Cols) A

Upvotes: 3

Related Questions