Ajarn Mark Caldwell Blog

Bringing Business Sense to the IT World…

SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!

If you use Enterprise Manager (EM) to create or edit table structures, data, stored procedures, or much of anything else, you are a rookie.  Now, each one of us was a rookie at some point, and you do have to start somewhere, but if you want to be considered a professional, you HAVE TO learn the SQL syntax and get comfortable living in Query Analyzer (QA).  Period.

First, a little secret about EM...it doesn't do anything magical.  It just has been programmed how to translate certain actions the user does in the GUI into proper SQL commands and then executes them.  Don't believe me?  Check it out for yourself.  Often in EM there is an option to “Script Changes”.  When you choose this, EM will write the SQL commands out to a file which you could then open in QA and execute.  If you're new to the idea of using QA and the SQL commands, this is a good way to start, so you can see what it's doing.  Start out with simple changes, like adding a new field to an existing table, so there is not too much information to wade through.  This list of SQL commands is also called a script.

It is a good practice to script ALL of your changes (yes, all, as in every one, no matter how simple you think it is, make it a habit and never waver from it).  There are several benefits to using scripts:

  • You can (and should) save your script files (usually ending with a .sql extension) into some form of source control (Visual Source Safe, Concurrent Versioning System, etc.).  This allows you to know exactly what changes have been made, and if you ever need to “roll back“ you have a history of changes.
  • It is easy to try, validate, edit and re-try your script to get it juuuust riiiight.
  • After you have the script working just right on your development server (You DO have a separate development server don't you?  Or at least a separate development database?) it is easy to just execute the same script on your QA and later your production servers and not worry about whether you remembered how to do it, because it's saved right there in your script file.
  • As your system gets more complex, you will need to make more changes at the same time, and oftentimes, the order of changes is critical.  Once you get the script all working properly on your development server, you don't have to try to remember all the little details and proper sequencing, because it's all in your script(s).
  • EM hides some information.  This is most apparent when someone is looking at data within a table.  EM will hide some of the data in long fields in order to get it to fit within the display window.  This has caused more than one person to think their data was messed up.
  • Personal Development:  As you get comfortable working with EM-generated scripts, and familiar with the SQL language and syntax, it opens a whole new world of development and management tools, tips, and tricks available to you.  At this point, your career is really about to take off.

Remember, all the database development and management actions you can take within EM can be done in scripts in QA.  And if you follow my advice, you'll thank me for this later.  Now get out there and SCRIPT!

Legacy Comments


Travis Laborde
2003-10-22
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
I agree wholeheartedly. About the only thing I still do in EM is create tables. The initial GUI for doing that, along with adding the indexes and relationships right there really does save me some time. I keep telling myself to "just do it" in QA. Your post is just another prod in the right direction. Thanks.

brenth
2003-10-25
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
Query Analyzer? Pansies! Real DBAs use command-line OSQL! :)

Just kidding -- good points, Mark!

Peg
2003-11-19
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
Hi. My name is Peg and I am a SQL Rookie! *smile*

Are "scripts" just another name for a saved QA query?

AjarnMark
2003-11-19
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
Hi Peg!

Essentially yes. Scripts are saved sets of SQL statements, whether for SELECTS, INSERTS, CREATES, ALTERS, whatever. The key being that you have a saved file (or files) that contain exactly what changes you made in case you need to modify it or come back later to research "What Happened?!" issues.

Lisa
2004-03-19
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
Great article.
I am another "rookie". I learned SQL syntax in college but in my real life...I use EM for faster. After reading your article, I realize that I have missed so much. Thx.

Heavy D
2004-03-30
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
Your a clown! You make yourself sound so exclusive in your skills. "Oh if you use EM you are such a rookie!!! Waahhh!!!" And then you go on to say use Query Analyzer. Whoopty Doo hero. I am so impressed by the way you really go out on a limb by moving to QA. Take it easy partner, don't get too crazy!

AjarnMark
2004-03-30
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
Oh yeah, Heavy, you've got my number there. You can tell by all my smart-ass answers on SQLTeam what a goofball I really am. I'm really just a slick salesman. Let me flish-flash a couple of scripts in your face and I know you'll be impressed, which after all, is the most important thing, isn't it? I mean if you can't impress people, then why go on, right? Just flash and dash! No need to learn anything about what's really going on in SQL because everyone at the company will be more ignorant than you, right? So just baffle them with bullshit and you'll be okay. Oh yeah, that's it.

By the way, I believe the phrase you were looking for was "You're a clown". "You're" being the contraction of "you are" as opposed to "your" which is possessive. I don't own any clowns.

Have a nice day and thanks for stopping by, though.

Lisa
2004-03-31
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
Hi Mark,

Again, thanks for your posts.
I am on the process of learning SQL commands and I have 2 questions regarding to your post above.

Question 1: You stated: "Often in EM there is an option to “Script Changes”. When you choose this, EM will write the SQL commands out to a file which you could then open in QA and execute. If you're new to the idea of using QA and the SQL commands, this is a good way to start, so you can see what it's doing."

I don't see any "Scrip Changes" in the BOL when I did a search. However, I did a search in the index of BOL and I find this: "script generating". Am I closed? According to BOL, I right click on the db, All tasks, Generate SQL scripts and finally it saves all the SQL commands into a file with a default ext (.sql). GREAT. However, when I open up the sql file, I was surprised by the amount of the code that is genrated. I mean, there are about 60 lines of code!?!??!??! So far, I only created 1 db called, "TestingDB". I thought for a simple db, it should only a few line of commands...


2) You stated: "You can (and should) save your script files (usually ending with a .sql extension) into some form of source control (Visual Source Safe, Concurrent Versioning System, etc.). "

What is the benefit of saving .sql script into VSS or CVS?
Do I need a special softwares to open these files?


You also stated: "This allows you to know exactly what changes have been made, and if you ever need to “roll back“ you have a history of changes." I understand what you are saying but it is hard for me to visualize without real example. So, if I want to create an example to see all the changes have been made, where do I begin? Am I going to start create a CVS file? Then what is next???

Thank you in advance,
Lisa

Ben Attwood
2004-06-10
re: SCRIPT IT! SCRIPT IT!! SCRIPT IT!!!
I agree with the article and am an SQL rookie. Working for a degree I know that my tutor would laugh in my face if I said I created tables using EM. I do find it useful to see what sort of mess I have created after i have run my scripts!