Click here to Skip to main content
15,936,821 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a table that has the following definition
column1 int
column2 nvarchar(50)
i know the table schema but i want to create this table in a database that idon't
know its name until execution
so i need a dynamic script to create a table in unknown database
can you help me?

iwant the solution in script in sql server and i want it dynamic
Updated 29-Nov-14 1:01am
Maciej Los 29-Nov-14 8:08am    
What you mean: "create a table in unknown database"?

Supposing SQL server, here you have the T-SQL syntax:[^]
Supposing you want to do it from c#, here you have some examples you can use:[^]

By the way, how do you think we can guess which RDBMS and language you intend to use?
Share this answer
Create Procedure [dbo].[PrepareDataBase]
@DataBaseName sysname

--create table Relations Definition in specific database
Declare @createSql nvarchar(2000)
set @createSql='use' + QUOTENAME(@DataBaseName)

Set  @createSql = @createSql + ' Create Table Relations
	[Foreign_Table] [nvarchar](255) NULL,
	[Foreign_Key] [nvarchar](255) NULL,
	[Primary_Table] [nvarchar](255) NULL,
	[Primary_Key] [nvarchar](255) NULL
Exec (@createSql)

thanks for every one helped me
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900