Script to Database

  • Hi all,

        i am on to a project where i had a situation to create a database from a script file using a query. What i need is i have to write a query(or command) to the MS SQL Server  and pass the script file location as parameter, it must create a database. We are using Java and through JDBC, i have to do it otherwise reading the script file and split it in to individual queries and send one by one for execution is very time consuming. Any help in this regard will be appriciated. Thanks in advance

  • There is a way to do this:

    master..xp_cmdshell N'isqlw -S YourServer -d Master -E -i "FullPathScriptFileName" -o "FullPathOutputFileName"'

    FullPathScriptFileName is the script file. The result is in the FullPathOutputFileName.

    The drive and file path are for the server. If you want the files on local machine, you can use UNC name.

    Though it works, you need to make sure the input file exists. Otherwise the query will be hang there. The result is in the FullPathOutputFileName.

    Split the file into individual query (between GO) is not bad. You can check the error message each time. In fact this is the preferred way for a installer.

     

  • You also must take into account windows user and directory/file pasmissions that are granted to the SQL Server Service (and possible the SQL Server Agent services as well. Also, let us not foget the 'SQL Agent 'proxy stuff' too !

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply