Reputation: 33
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
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