473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Creating a database from set of TSQLl files

I have written a set of sql files that make my entire database schema. I
have divided the schema into seperate files mostly for "manageability"
(for example, I can check error codes as I go along, and terminate the
process as soon as an error occurs).

I have several tsql files in a directory, and I want to be able to write
a batch script (or something similar), which allows me to:

1). Process each of the individual files (i.e. execute the commands in
the file)
2). report succes or failure for the file
3). Abort the entire process if a command in one of the files failed

The batch part I can largely figure out myself. So my question basically
can be simplified as:

How can I read and execute TSQL commands from a file - AND return an
success/error code ?
Jun 27 '08 #1
1 1440
The batch part I can largely figure out myself. So my question basically
can be simplified as:

How can I read and execute TSQL commands from a file - AND return an
success/error code ?
You can execute scripts using SQLCMD command-line utility with the -b
parameter. This will cause the utility to exit with a non-zero return code
if an error with a severity 10 is raised. For example:

SQLCMD -E -S MyServer -d MyDatabase -b -i MyScript.sql
IF NOT %errorlevel% == 0 GOTO :MyErrorLabel

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"Annonymous Coward" <me@home.comwrote in message
news:Tu*********************@bt.com...
>I have written a set of sql files that make my entire database schema. I
have divided the schema into seperate files mostly for "manageability" (for
example, I can check error codes as I go along, and terminate the process
as soon as an error occurs).

I have several tsql files in a directory, and I want to be able to write a
batch script (or something similar), which allows me to:

1). Process each of the individual files (i.e. execute the commands in the
file)
2). report succes or failure for the file
3). Abort the entire process if a command in one of the files failed

The batch part I can largely figure out myself. So my question basically
can be simplified as:

How can I read and execute TSQL commands from a file - AND return an
success/error code ?
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
6
by: Jerry Spence1 | last post by:
Why doesn't the following work in my ASP program? I have imported ADOX I am trying to create a temporary database on the user's PC. The example is taken from Microsoft. Dim cat As Catalog =...
1
by: RSH | last post by:
Im trying to create a stored procedure of the following code. I want to set it so that I have to send the first 4 variables (@DB, @BackUpFile,@TestDB,@RestoreFile). I am having trouble when i try...
1
by: MAB | last post by:
I need to create a service (or something else) to monitor the coming and goings of files (& possible folders) beneath a root folder. This service need to know the path/FileName of any new files so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.