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 |
|
swoozie
Starting Member
25 Posts |
Posted - 2007-10-26 : 15:19:52
|
| i have 20 .sql files that were written to create new views in a Database. We are moving over to a new database and need to run all of these scripts against the new database to add the views (each time we refresh for testing) Is there away to write a procedure that calls all of these .sql files so they do not have to be opened and run individually? I am thinking something likeEXEC xp_sqlmaint 'or EXEC Master..xp_cmdshell but I can not figure out the right syntax or else these are the wrong direction. What do you suggest?Thanks,Swoozie |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-26 : 15:22:49
|
| Just call them using osql or sqlcmd from the command line. sqlcmd -Sserver1 -E -iC:\Script1.sqlsqlcmd -Sserver1 -E -iC:\Script2.sqlsqlcmd -Sserver1 -E -iC:\Script3.sqlThen save these commands into a cmd file and now you have a batch file that you can just double click to execute.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
swoozie
Starting Member
25 Posts |
Posted - 2007-10-26 : 16:05:26
|
| I guess I should have added one more statement. The 'others' wish this to be added with a procedure that will run all at once doing a bunch of stuff to the database, This is only a small part that I was given to write. Can those statements like that be inside a stored procedure? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-26 : 16:08:50
|
| Yes as you can run command line commands from xp_cmdshell. I wouldn't do it this way though as they'd need sysadmin access this way. A batch file should be sufficient for their needs, so just explain to them the process and why it hasn't been wrapped into a stored procedure.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
swoozie
Starting Member
25 Posts |
Posted - 2007-10-30 : 14:57:52
|
| Okay, well that didnt seem to work, I guess I will just paste all of the individual pieces into one big piece to run. Thanks for your help |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-30 : 14:59:31
|
| Well it would work if you set it up properly.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
|
|
|