PDA

View Full Version : Run sql scripts as a part of installation



NewsArchive
08-02-2010, 01:56 PM
Its so, that I want to run some sql scripts under the installation.
DB is an MSSQL 2005 express
Could be so, that this is more a general MSSQL question than a SB, but
anyway.
I have a table called LL_Reparea.
I have made a script, which drops the table, recreates it and adds app. 100
records.
If i run this script in the MSSQL manager, it does what it is expected to
do.
Now i want to run this script directly from SB 7
I know the usual 4 parameters, ie, server, database, user and password.

Should this info be a part of the sql script (how?) or a part of the
parameters for running the script?

Any who knows 'How to'?

Best regards

Edvard Korsbæk

NewsArchive
08-02-2010, 01:57 PM
Save the script to a temp location on the server..

Then use SB to run sqlcmd with parameters... note the /i param here...

Sqlcmd [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend] [-L[c] list servers[clean output]]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile] [-z new password]
[-f | i:[,o:]] [-Z new password and exit]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-b On error batch abort]
[-v var = "value"...] [-A dedicated admin connection]
[-X[1] disable commands, startup script, enviroment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]

That should get you done.

John Griffiths

NewsArchive
08-02-2010, 01:57 PM
Thanks!

You are my MSSQL consultant at the time beeing.
I have just succeded in making MSSQL 2005 express installations with a SA
password - Thanks for that too!

Edvard Korsbæk

NewsArchive
08-02-2010, 01:58 PM
Great.
Glad to help

John Griffiths