Creating a new DB from MasterSP

Creating a new DB from MasterSP

Post by Lars Gr?ttelan » Tue, 29 Apr 2003 16:37:59



Hello!

I would do the following. When the master-user is creating a new SQL
Database - I would be happy to run a StoredProcedure and create all stored
Procedures and Tables to this new database
How can I achieve this?

I tried inserting this SP into the MasterDB, but it replied the error saying
that the tables nor the StoredProcedure was not there.

Could anyone help me here?

- Lars

 
 
 

Creating a new DB from MasterSP

Post by Dejan Sark » Tue, 29 Apr 2003 17:08:24


Lars,

When you create a new db, all objects from the Model db are copied there. So
you will have to put SPs in the model db.

--
Dejan Sarka, SQL Server MVP
FAQ from Neil & others at: http://www.sqlserverfaq.com
Please reply only to the newsgroups.
PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


Quote:> Hello!

> I would do the following. When the master-user is creating a new SQL
> Database - I would be happy to run a StoredProcedure and create all stored
> Procedures and Tables to this new database
> How can I achieve this?

> I tried inserting this SP into the MasterDB, but it replied the error
saying
> that the tables nor the StoredProcedure was not there.

> Could anyone help me here?

> - Lars


 
 
 

Creating a new DB from MasterSP

Post by Lars Gr?ttelan » Tue, 29 Apr 2003 17:50:45


Thanks - But that is exactly not what I want to do. I have to apps and they
have to create two seperate databases.

I was thinking of using a script to create this database. Has anyone of you
used the REG_MULTI_SZ entry in Registry. How can I use this? Does anyone
know?



> Lars,

> When you create a new db, all objects from the Model db are copied there.
So
> you will have to put SPs in the model db.

> --
> Dejan Sarka, SQL Server MVP
> FAQ from Neil & others at: http://www.sqlserverfaq.com
> Please reply only to the newsgroups.
> PASS - the definitive, global community
> for SQL Server professionals - http://www.sqlpass.org



> > Hello!

> > I would do the following. When the master-user is creating a new SQL
> > Database - I would be happy to run a StoredProcedure and create all
stored
> > Procedures and Tables to this new database
> > How can I achieve this?

> > I tried inserting this SP into the MasterDB, but it replied the error
> saying
> > that the tables nor the StoredProcedure was not there.

> > Could anyone help me here?

> > - Lars

 
 
 

Creating a new DB from MasterSP

Post by Val Mazu » Tue, 29 Apr 2003 21:25:26


Hi Lars,

What about keeping script in a file and load it from inside application and
execute that script same way as we execute usual SQL statements?

--
Val Mazur
Microsoft MVP


> Thanks - But that is exactly not what I want to do. I have to apps and
they
> have to create two seperate databases.

> I was thinking of using a script to create this database. Has anyone of
you
> used the REG_MULTI_SZ entry in Registry. How can I use this? Does anyone
> know?



> > Lars,

> > When you create a new db, all objects from the Model db are copied
there.
> So
> > you will have to put SPs in the model db.

> > --
> > Dejan Sarka, SQL Server MVP
> > FAQ from Neil & others at: http://www.sqlserverfaq.com
> > Please reply only to the newsgroups.
> > PASS - the definitive, global community
> > for SQL Server professionals - http://www.sqlpass.org



> > > Hello!

> > > I would do the following. When the master-user is creating a new SQL
> > > Database - I would be happy to run a StoredProcedure and create all
> stored
> > > Procedures and Tables to this new database
> > > How can I achieve this?

> > > I tried inserting this SP into the MasterDB, but it replied the error
> > saying
> > > that the tables nor the StoredProcedure was not there.

> > > Could anyone help me here?

> > > - Lars

 
 
 

Creating a new DB from MasterSP

Post by Lars Gr?ttelan » Tue, 29 Apr 2003 21:34:18


Yes!

I really didn't think of that!

If I Receive these items from the file in a CStringList. How do I open that
in SQL then? I'm not thinking of the Query Analyzer, but in c++ code?


> Hi Lars,

> What about keeping script in a file and load it from inside application
and
> execute that script same way as we execute usual SQL statements?

> --
> Val Mazur
> Microsoft MVP



> > Thanks - But that is exactly not what I want to do. I have to apps and
> they
> > have to create two seperate databases.

> > I was thinking of using a script to create this database. Has anyone of
> you
> > used the REG_MULTI_SZ entry in Registry. How can I use this? Does anyone
> > know?


in

> > > Lars,

> > > When you create a new db, all objects from the Model db are copied
> there.
> > So
> > > you will have to put SPs in the model db.

> > > --
> > > Dejan Sarka, SQL Server MVP
> > > FAQ from Neil & others at: http://www.sqlserverfaq.com
> > > Please reply only to the newsgroups.
> > > PASS - the definitive, global community
> > > for SQL Server professionals - http://www.sqlpass.org



> > > > Hello!

> > > > I would do the following. When the master-user is creating a new SQL
> > > > Database - I would be happy to run a StoredProcedure and create all
> > stored
> > > > Procedures and Tables to this new database
> > > > How can I achieve this?

> > > > I tried inserting this SP into the MasterDB, but it replied the
error
> > > saying
> > > > that the tables nor the StoredProcedure was not there.

> > > > Could anyone help me here?

> > > > - Lars

 
 
 

Creating a new DB from MasterSP

Post by Val Mazu » Tue, 29 Apr 2003 21:54:04


Hi,

Do not know anything about C++, but in VB I could use FileSystemObject class
library to read text files. Then you would need to chunk that text to parts
between GOs (provider does not understand GO statements) and execute that
string using Execute method of Connection

It would look like

MyADOConnection.Execute "CREATE TABLE ...."
or

mySQL=load statement string here from file

MyADOConnection.Execute mySQL

--
Val Mazur
Microsoft MVP


> Yes!

> I really didn't think of that!

> If I Receive these items from the file in a CStringList. How do I open
that
> in SQL then? I'm not thinking of the Query Analyzer, but in c++ code?



> > Hi Lars,

> > What about keeping script in a file and load it from inside application
> and
> > execute that script same way as we execute usual SQL statements?

> > --
> > Val Mazur
> > Microsoft MVP



> > > Thanks - But that is exactly not what I want to do. I have to apps and
> > they
> > > have to create two seperate databases.

> > > I was thinking of using a script to create this database. Has anyone
of
> > you
> > > used the REG_MULTI_SZ entry in Registry. How can I use this? Does
anyone
> > > know?


wrote
> in

> > > > Lars,

> > > > When you create a new db, all objects from the Model db are copied
> > there.
> > > So
> > > > you will have to put SPs in the model db.

> > > > --
> > > > Dejan Sarka, SQL Server MVP
> > > > FAQ from Neil & others at: http://www.sqlserverfaq.com
> > > > Please reply only to the newsgroups.
> > > > PASS - the definitive, global community
> > > > for SQL Server professionals - http://www.sqlpass.org


message

> > > > > Hello!

> > > > > I would do the following. When the master-user is creating a new
SQL
> > > > > Database - I would be happy to run a StoredProcedure and create
all
> > > stored
> > > > > Procedures and Tables to this new database
> > > > > How can I achieve this?

> > > > > I tried inserting this SP into the MasterDB, but it replied the
> error
> > > > saying
> > > > > that the tables nor the StoredProcedure was not there.

> > > > > Could anyone help me here?

> > > > > - Lars

 
 
 

Creating a new DB from MasterSP

Post by Lars Gr?ttelan » Tue, 29 Apr 2003 22:14:35


OK Thanks!

I have now parsed the items into one text string in C++ - and I took away
all the "GO" in the SQL string. But now I receive error from the SQL Server:

Server: Msg 111, Level 15, State 1, Line 354
'CREATE PROCEDURE' must be the first statement in a query batch.

So the question here is what to do with StoredProcedure in this file? It
seems like it only handles Tables without "GO" statement

- Lars


> Hi,

> Do not know anything about C++, but in VB I could use FileSystemObject
class
> library to read text files. Then you would need to chunk that text to
parts
> between GOs (provider does not understand GO statements) and execute that
> string using Execute method of Connection

> It would look like

> MyADOConnection.Execute "CREATE TABLE ...."
> or

> mySQL=load statement string here from file

> MyADOConnection.Execute mySQL

> --
> Val Mazur
> Microsoft MVP



> > Yes!

> > I really didn't think of that!

> > If I Receive these items from the file in a CStringList. How do I open
> that
> > in SQL then? I'm not thinking of the Query Analyzer, but in c++ code?



> > > Hi Lars,

> > > What about keeping script in a file and load it from inside
application
> > and
> > > execute that script same way as we execute usual SQL statements?

> > > --
> > > Val Mazur
> > > Microsoft MVP



> > > > Thanks - But that is exactly not what I want to do. I have to apps
and
> > > they
> > > > have to create two seperate databases.

> > > > I was thinking of using a script to create this database. Has anyone
> of
> > > you
> > > > used the REG_MULTI_SZ entry in Registry. How can I use this? Does
> anyone
> > > > know?


> wrote
> > in

> > > > > Lars,

> > > > > When you create a new db, all objects from the Model db are copied
> > > there.
> > > > So
> > > > > you will have to put SPs in the model db.

> > > > > --
> > > > > Dejan Sarka, SQL Server MVP
> > > > > FAQ from Neil & others at: http://www.sqlserverfaq.com
> > > > > Please reply only to the newsgroups.
> > > > > PASS - the definitive, global community
> > > > > for SQL Server professionals - http://www.sqlpass.org


> message

> > > > > > Hello!

> > > > > > I would do the following. When the master-user is creating a new
> SQL
> > > > > > Database - I would be happy to run a StoredProcedure and create
> all
> > > > stored
> > > > > > Procedures and Tables to this new database
> > > > > > How can I achieve this?

> > > > > > I tried inserting this SP into the MasterDB, but it replied the
> > error
> > > > > saying
> > > > > > that the tables nor the StoredProcedure was not there.

> > > > > > Could anyone help me here?

> > > > > > - Lars

 
 
 

Creating a new DB from MasterSP

Post by Val Mazu » Tue, 29 Apr 2003 22:44:54


Hi,

It handles everything. You could execute any valid statement. How did you
execute them? As a one string for all statements or not. If yes, then you
could try to execute them separating by semicolon (;) or execute them
one-by-one

--
Val Mazur
Microsoft MVP


> OK Thanks!

> I have now parsed the items into one text string in C++ - and I took away
> all the "GO" in the SQL string. But now I receive error from the SQL
Server:

> Server: Msg 111, Level 15, State 1, Line 354
> 'CREATE PROCEDURE' must be the first statement in a query batch.

> So the question here is what to do with StoredProcedure in this file? It
> seems like it only handles Tables without "GO" statement

> - Lars



> > Hi,

> > Do not know anything about C++, but in VB I could use FileSystemObject
> class
> > library to read text files. Then you would need to chunk that text to
> parts
> > between GOs (provider does not understand GO statements) and execute
that
> > string using Execute method of Connection

> > It would look like

> > MyADOConnection.Execute "CREATE TABLE ...."
> > or

> > mySQL=load statement string here from file

> > MyADOConnection.Execute mySQL

> > --
> > Val Mazur
> > Microsoft MVP



> > > Yes!

> > > I really didn't think of that!

> > > If I Receive these items from the file in a CStringList. How do I open
> > that
> > > in SQL then? I'm not thinking of the Query Analyzer, but in c++ code?



> > > > Hi Lars,

> > > > What about keeping script in a file and load it from inside
> application
> > > and
> > > > execute that script same way as we execute usual SQL statements?

> > > > --
> > > > Val Mazur
> > > > Microsoft MVP


message

> > > > > Thanks - But that is exactly not what I want to do. I have to apps
> and
> > > > they
> > > > > have to create two seperate databases.

> > > > > I was thinking of using a script to create this database. Has
anyone
> > of
> > > > you
> > > > > used the REG_MULTI_SZ entry in Registry. How can I use this? Does
> > anyone
> > > > > know?


> > wrote
> > > in

> > > > > > Lars,

> > > > > > When you create a new db, all objects from the Model db are
copied
> > > > there.
> > > > > So
> > > > > > you will have to put SPs in the model db.

> > > > > > --
> > > > > > Dejan Sarka, SQL Server MVP
> > > > > > FAQ from Neil & others at: http://www.sqlserverfaq.com
> > > > > > Please reply only to the newsgroups.
> > > > > > PASS - the definitive, global community
> > > > > > for SQL Server professionals - http://www.sqlpass.org


> > message

> > > > > > > Hello!

> > > > > > > I would do the following. When the master-user is creating a
new
> > SQL
> > > > > > > Database - I would be happy to run a StoredProcedure and
create
> > all
> > > > > stored
> > > > > > > Procedures and Tables to this new database
> > > > > > > How can I achieve this?

> > > > > > > I tried inserting this SP into the MasterDB, but it replied
the
> > > error
> > > > > > saying
> > > > > > > that the tables nor the StoredProcedure was not there.

> > > > > > > Could anyone help me here?

> > > > > > > - Lars

 
 
 

Creating a new DB from MasterSP

Post by Tibor Karasz » Tue, 29 Apr 2003 22:50:19


You can't just remove the GO's.
For each GO, do an .Execute (or however you execute the string). Then clear the string variable
start over adding stuff until next GO.

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sql...


> OK Thanks!

> I have now parsed the items into one text string in C++ - and I took away
> all the "GO" in the SQL string. But now I receive error from the SQL Server:

> Server: Msg 111, Level 15, State 1, Line 354
> 'CREATE PROCEDURE' must be the first statement in a query batch.

> So the question here is what to do with StoredProcedure in this file? It
> seems like it only handles Tables without "GO" statement

> - Lars



> > Hi,

> > Do not know anything about C++, but in VB I could use FileSystemObject
> class
> > library to read text files. Then you would need to chunk that text to
> parts
> > between GOs (provider does not understand GO statements) and execute that
> > string using Execute method of Connection

> > It would look like

> > MyADOConnection.Execute "CREATE TABLE ...."
> > or

> > mySQL=load statement string here from file

> > MyADOConnection.Execute mySQL

> > --
> > Val Mazur
> > Microsoft MVP



> > > Yes!

> > > I really didn't think of that!

> > > If I Receive these items from the file in a CStringList. How do I open
> > that
> > > in SQL then? I'm not thinking of the Query Analyzer, but in c++ code?



> > > > Hi Lars,

> > > > What about keeping script in a file and load it from inside
> application
> > > and
> > > > execute that script same way as we execute usual SQL statements?

> > > > --
> > > > Val Mazur
> > > > Microsoft MVP



> > > > > Thanks - But that is exactly not what I want to do. I have to apps
> and
> > > > they
> > > > > have to create two seperate databases.

> > > > > I was thinking of using a script to create this database. Has anyone
> > of
> > > > you
> > > > > used the REG_MULTI_SZ entry in Registry. How can I use this? Does
> > anyone
> > > > > know?


> > wrote
> > > in

> > > > > > Lars,

> > > > > > When you create a new db, all objects from the Model db are copied
> > > > there.
> > > > > So
> > > > > > you will have to put SPs in the model db.

> > > > > > --
> > > > > > Dejan Sarka, SQL Server MVP
> > > > > > FAQ from Neil & others at: http://www.sqlserverfaq.com
> > > > > > Please reply only to the newsgroups.
> > > > > > PASS - the definitive, global community
> > > > > > for SQL Server professionals - http://www.sqlpass.org


> > message

> > > > > > > Hello!

> > > > > > > I would do the following. When the master-user is creating a new
> > SQL
> > > > > > > Database - I would be happy to run a StoredProcedure and create
> > all
> > > > > stored
> > > > > > > Procedures and Tables to this new database
> > > > > > > How can I achieve this?

> > > > > > > I tried inserting this SP into the MasterDB, but it replied the
> > > error
> > > > > > saying
> > > > > > > that the tables nor the StoredProcedure was not there.

> > > > > > > Could anyone help me here?

> > > > > > > - Lars

 
 
 

Creating a new DB from MasterSP

Post by Lars Gr?ttelan » Wed, 30 Apr 2003 19:10:51


Thanks!

That really worked!



Quote:> You can't just remove the GO's.
> For each GO, do an .Execute (or however you execute the string). Then

clear the string variable
Quote:> start over adding stuff until next GO.

> --
> Tibor Karaszi, SQL Server MVP
> Archive at:

http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sql...



> > OK Thanks!

> > I have now parsed the items into one text string in C++ - and I took
away
> > all the "GO" in the SQL string. But now I receive error from the SQL
Server:

> > Server: Msg 111, Level 15, State 1, Line 354
> > 'CREATE PROCEDURE' must be the first statement in a query batch.

> > So the question here is what to do with StoredProcedure in this file? It
> > seems like it only handles Tables without "GO" statement

> > - Lars



> > > Hi,

> > > Do not know anything about C++, but in VB I could use FileSystemObject
> > class
> > > library to read text files. Then you would need to chunk that text to
> > parts
> > > between GOs (provider does not understand GO statements) and execute
that
> > > string using Execute method of Connection

> > > It would look like

> > > MyADOConnection.Execute "CREATE TABLE ...."
> > > or

> > > mySQL=load statement string here from file

> > > MyADOConnection.Execute mySQL

> > > --
> > > Val Mazur
> > > Microsoft MVP



> > > > Yes!

> > > > I really didn't think of that!

> > > > If I Receive these items from the file in a CStringList. How do I
open
> > > that
> > > > in SQL then? I'm not thinking of the Query Analyzer, but in c++
code?



> > > > > Hi Lars,

> > > > > What about keeping script in a file and load it from inside
> > application
> > > > and
> > > > > execute that script same way as we execute usual SQL statements?

> > > > > --
> > > > > Val Mazur
> > > > > Microsoft MVP


message

> > > > > > Thanks - But that is exactly not what I want to do. I have to
apps
> > and
> > > > > they
> > > > > > have to create two seperate databases.

> > > > > > I was thinking of using a script to create this database. Has
anyone
> > > of
> > > > > you
> > > > > > used the REG_MULTI_SZ entry in Registry. How can I use this?
Does
> > > anyone
> > > > > > know?

> > > > > > "Dejan Sarka"


- Show quoted text -

> > > wrote
> > > > in

> > > > > > > Lars,

> > > > > > > When you create a new db, all objects from the Model db are
copied
> > > > > there.
> > > > > > So
> > > > > > > you will have to put SPs in the model db.

> > > > > > > --
> > > > > > > Dejan Sarka, SQL Server MVP
> > > > > > > FAQ from Neil & others at: http://www.sqlserverfaq.com
> > > > > > > Please reply only to the newsgroups.
> > > > > > > PASS - the definitive, global community
> > > > > > > for SQL Server professionals - http://www.sqlpass.org


> > > message

> > > > > > > > Hello!

> > > > > > > > I would do the following. When the master-user is creating a
new
> > > SQL
> > > > > > > > Database - I would be happy to run a StoredProcedure and
create
> > > all
> > > > > > stored
> > > > > > > > Procedures and Tables to this new database
> > > > > > > > How can I achieve this?

> > > > > > > > I tried inserting this SP into the MasterDB, but it replied
the
> > > > error
> > > > > > > saying
> > > > > > > > that the tables nor the StoredProcedure was not there.

> > > > > > > > Could anyone help me here?

> > > > > > > > - Lars

 
 
 

1. Creating a new DB from MasterSP

Hello!

I would do the following. When the master-user is creating a new SQL
Database - I would be happy to run a StoredProcedure and create all stored
Procedures and Tables to this new database
How can I achieve this?

I tried inserting this SP into the MasterDB, but it replied the error saying
that the tables nor the StoredProcedure was not there.

Could anyone help me here?

- Lars

2. ODBC Drivers For Access 2.0

3. Creating New DB doesn't create dbo user

4. Disk space with backups

5. Creating procedure to exec when new DB is created

6. MMC cannot open specified file

7. Oracle 8i and WebDB - TNS

8. Creating New DB doesn't create dbo user

9. Creating procedure to exec when new DB is created

10. Create new db from old db files?

11. Creating a new instance of a DB

12. OLE DB Provider to create a new FoxPro database from Visual Basic