all groups > sql server programming > april 2004 >
You're in the

sql server programming

group:

Is it possible to create a DB and tables in the same Stored Procedure


Is it possible to create a DB and tables in the same Stored Procedure Veda
4/14/2004 8:51:05 PM
sql server programming: Hai
I want to create a Database say, (MyTestDB) and few tables for it in one SP
That SP is present in the database (MyDB)
when i try to do this, it says, Database "MyTestDB" does not exist
Plz let me know how it can be resolved..??!
Thank u
Re: Is it possible to create a DB and tables in the same Stored Procedure Uri Dimant
4/15/2004 6:42:01 AM
Veda
No. But why do you want to do that within one stored procedure?
[quoted text, click to view]

Re: Is it possible to create a DB and tables in the same Stored Procedure Vinodk
4/15/2004 10:05:13 AM
Try to create the database and the the create procedures in a Dynamic SQL
method.

--
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp


[quoted text, click to view]

Re: Is it possible to create a DB and tables in the same Stored Procedure Hari
4/15/2004 10:40:48 AM
Hi,

Instead of stored procedure , you can do it using a .SQL file and execute
the .SQL file using OSQL.

Steps:

1. Create a new text file in notepad
2. Contents of the file should be

Create database MyTestDB
go
use MyTestDB
go
create table test1(i int)
go
create table test2(i int , j varchar(10))

3. Save the file as c:\script.SQL

4. Execute the c:\script.sql using OSQL

OSQL -Usa -Ppassword -S SQL_Server_name -d master -i
c:\script.sql -oc:\error.log


Thanks
Hari
MCDBA






[quoted text, click to view]

OSQL -Usa -Phari -SA266uss\harisql -d master -i c:\script.sql -oc:\error.log

AddThis Social Bookmark Button