I am developing a C # application and I want a window that displays all existing tables in the database the user make the choice of tables that want to recreate in a new database in a sql compact, some tables must contain the initial information and the other just the structure of the table.
Is there any help to recreate this table?
I think to generate the script of the existing table (*.sql) and creating table from file to the new database, but I do not know how to make a query to generate a sql table.
PS: the existing table is in sqlserver, and I want to create a table in sqlcompact.
Have a look at the following views:
I don’t have the code to hand (sorry) but I’ve used these before to recreate a table definition based off the database’s own metadata in pure TSQL and there’s no reason it couldn’t be done in C# within the application just as well. Join them up together, declare a string for your final definition and cursor through the results set to get all the fields in your table, building up the output. When you’re done, return that to the client. For testing purposes compare the output of your code to what SSMS produces when you ask it to script creation of a table and hopefully you’ll be able to get your table definitions recreated relatively quickly.