SQLCMD (Simple Example)

 
 
Download example HERE. (<< Right-click. "Save (Target) As" usually works best).

If I haven’t mentioned it before, thank you Microsoft for the sqlcmd.exe utility.
If you are new to sqlcmd or new to the concept of repeatability, below is a simple example.
It creates 3 databases that are exactly the same except for the database-name.
Can you say "repeatable" (as in every-single-time-repeatable-and-dependable)?
If you’re still using the GUI in Sql Server Management Studio and doing a "Right-Click"/"Add Database" for than anything for casual development, then please stop.
It is not repeatable.  It does not promote repeatability for "D-DAY" (that’s what I call deployment-day). 
 
My motto:
If you cannot deploy your code, your code and hard-work is essentially worthless.

 
The demo is simple.  A database, one table, and 2 stored procedures.  But the skeleton is there.
 
The example zip file is a demo example of creating a basic “OrganizationDB” (OrganizationDB01, OrganizationDB02, and OrganizationDB03).

Again, this is a sqlcmd.exe example of using $(Variable)’s to deploy databases….which emphasizes repeatability but with configurability as well.

Instructions:

Unzip the files……….read the README.txt file (the top portion contains setup information).

If you have ".\SqlExpress" setup as your development environment, you should be able to just click:
RebuildDatabaseMaster_AllThree.bat
and it should just work.


Look at the gif screenshot (in the zip), and compare to your database.

Then you can look at the README.txt file for explanation about what is happening.

There are also output log files you can look at (mentioned in the README.txt file) which will provide clues if anything does not work.

 

After you get it down, you’re essentially (always) one copy/paste/edit (the variable file) and a second copy/paste/edit (the .bat file) away from deploying a new database.

 

 

 ISQLW OSQL << These are the early versions of this tool, FYI.

 

Advertisements
This entry was posted in Software Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s