Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dani2
Starting Member
32 Posts |
Posted - 2006-11-17 : 04:01:39
|
| DECLARE @DBName varchar(100);SET @DBName = 'TestTest';CREATE DATABASE @DBName ON PRIMARY;message is: wrong syntax near '@DBName'. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-11-17 : 04:13:48
|
[code]exec ( 'CREATE DATABASE ' + @DBName + ' ON PRIMARY;')[/code] KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-17 : 04:19:54
|
| Why do you want to create Database dynamically?Read this fully www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
dani2
Starting Member
32 Posts |
Posted - 2006-11-17 : 04:22:27
|
| now its false syntax near PRIMARY |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-17 : 04:25:05
|
| Read about Create Database in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
dani2
Starting Member
32 Posts |
Posted - 2006-11-17 : 06:23:11
|
quote: Originally posted by madhivanan Read about Create Database in sql server help fileMadhivananFailing to plan is Planning to fail
thanks I figured it out. but i have another problem.If I declare a variable it is visible only until the 1st GO, then I must declare it again. Why is not global? Am i doing something wrong here? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-11-17 : 07:27:35
|
don't use go. GO signify end of script. Why do you need to use GO ? KH |
 |
|
|
dani2
Starting Member
32 Posts |
Posted - 2006-11-17 : 07:53:35
|
quote: Originally posted by khtan don't use go. GO signify end of script. Why do you need to use GO ? KH
must create database, than use it and then create some tables in newly created db |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-11-17 : 07:57:27
|
Post your script here and we will have a look at it KH |
 |
|
|
|
|
|