Return only Metadata

  • Hi there,

    I've been searching everywhere for this, but can't seem to find something I can use. Thought I'll ask you guys!!

    We are busy developing an application that creates tables on the fly. the application takes an external datasource & imports this into a SQL database. Data comes from various sources & have different columns.

    The application then tries to create another table based on the columns in the "import table", if I can call it that. The final table that needs to be created, depends on data & source, so no table will be the same.

    Doing this seems more difficult than anticipated. I know of the setting to only return metadata...

    SET FMTONLY ON.

    The problem we face here is that you can't do anything with that result set, so it means nothing.

    Does anyone know how I can return only column names from a table, but be able to use it?

    Regards & thanks in advance!!

    T.

  • SELECT * FROM syscolumns where id=object_id('dbo.yourtable')

  • You can always go looking i nthe INFORMATION_SCHEMA views that are available

    SELECT *

    FROM INFORMATION_SCHEMA.Columns

    WHERE TABLE_NAME = 'your_table_name'


    Regards,

    Steve

    Life without beer is no life at all

    All beer is good, some beers are just better than others

  • what are you using to develop the application? You might want to try using ADOX. It's supported by the SQL Server ADO provider.

  • Tobie,

    I am not sure I follow you. Are you saying you want to create a table, then get its schema loaded into a result set so that you can use that result set to add rows to the table?

    How about ....

     

    SELECT Top 0 * from table

    What this will do is it will return a zero-row record set with the schema filled out as if you returned several rows.

      

    I am Doing it with .Net, are you?

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply