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
Posted
Updated 29-Nov-14 1:01am
v2
Comments
Maciej Los 29-Nov-14 8:08am    
What you mean: "create a table in unknown database"?
Why?

Supposing SQL server, here you have the T-SQL syntax: http://msdn.microsoft.com/en-us/library/ms174979.aspx[^]
Supposing you want to do it from c#, here you have some examples you can use: http://www.c-sharpcorner.com/UploadFile/mahesh/CreatingDBProgrammaticallyMCB11282005064852AM/CreatingDBProgrammaticallyMCB.aspx[^]

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

--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
) ON [PRIMARY]
'
Exec (@createSql)


thanks for every one helped me
 
Share this answer
 
v2

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