Archive: writing database scripts (SQLServer)


writing database scripts (SQLServer)
got an email from someone reading the boards ...

I need to create an installer which deploys a web application and then runs a couple scripts on an SQL server 2000 database.

I’ve got the first part covered, but I really am no too sure how to run a script on the SQL server 2000 database.

Can you provide any assistance?


i've done this in my installer. i've set up a SQLServer database, logins, scheduled jobs, linked servers, created tables, stored procedures, etc. the best way to do this (IMHO) is to use the nsExec plugin.

after you've checked to make sure SQLServer and the SQLServer tools are installed on the destination server (see the archives for how to do this), you can use the <b>osql.exe</b> command to run scripts. here's an example:

nsExec::Exec/TIMEOUT=20000'"$SQLTOOLS_PATH\osql.exe"-Usa

-P$SA_PWD-i"$INSTDIR\db\CREATE_DB.sql"-o"$INSTDIR\db\CREATE_DB.log"'
... will allow you to execute a T-SQL script from the command line, using nsExec, all silently with output going to the details window.

for one-off SQL statements, try:

nsExec::ExecToLog/TIMEOUT=20000`"$SQLTOOLS_PATH\osql.exe"-Usa

-P$SA_PWD-d"master"-Q
"IFEXISTS(SELECTsrvnameFROMmaster.dbo.sysservers
WHEREsrvname=N'MYREMOTESERVER'ANDisremote=1)
EXECsp_dropserver@server='MYREMOTESERVER',@droplogins='droplogins'"
`
please ignore the line breaks in the above examples. hope this helps ... and please post questions here, don't email me personally. :)

You said :

i've done this in my installer. i've set up a SQLServer database, logins, scheduled jobs, linked servers, created tables, stored procedures, etc. the best way to do this (IMHO) is to use the nsExec plugin.
Where can I find your installer.?

i haven't posted it; just posted the examples, and referred to my installer to show that i'm using said code. :)

also, i don't think the backslashes are showing up in the code; need to check that.

-m-


You should not use PHP but CODE to display backslashes.

Why not create a NSIS Archive page with your examples?