Db2 run sql file from command line


















In the case of an alternate delimiter, the file might look like this:. There are several command line options, I used above. Here is the breakdown of these options I use most frequently:. The choice between the two depends on your personal preferences and environment. Having the database name in the file can be useful for the output to verify later that you connected to the right database when executing the script. I have started to redirect standard error before piping to tee. This is especially important when debugging the script as sometimes small syntax errors get written to the screen through standard error but do not show up in the log piped out by tee.

So I like to do. Just a little extra protection in case I or someone else messed up the script. Gives a change to find the problem. Just my personal preference is to check for errors. I went with logfile parsing in the past but this is too cumbersome for simple check whether my script was successful or not. I am looking at the error level that gets returned by db2.

Everything other than 0 might be suspicious. However in most cases 1 is ok and sometimes I am fine with 2 as well. Another pattern that I started to like is to have shell and sql scripts in conjunction.

The shell scripts make sure the db connection is set up and the sql script does the actual work. This way I can use parameters for connecting to different databases and the actual sql work still stays the same regardless of the DB name.

Nothing beats the beauty of having only one call to cater the needs of dev and production environments alike. There is one more perk of always having a shell script as a driver. Need to be able to setup a db2 luw database on the fly with creating the database, creating as many table as one wants in it with indexes, primary keys creation etc on the fly as well as loading of generated data thru SQL with commit points within as it inserts records and thus be able to create however big a database size as one wants…Do you know of any such shell script or something that has all this capabilities or a set of SQL someplace that can do this?

I know Vikram Khatri, one of amongst known names in DB2 World, used to have such scripts in his db2ude. Neuropil Histology. Mini Electric Tea Kettle.

Find Mcdonald S Play Place. Modern Calligraphy Alphabet Uppercase. Bacon Transparent. Downtown Santa Maria. Child Room Cc Sims 4. Minecraft Logo Generator. Windows Mic Auto Tune. Quotes For Your Employees. Cheesy Beef Rotel Dip. Costco Vegan Protein Powder. Chicken Chow Mein Can. Concrete Estimate Form. The simplest thing would probably be to log in as the db2 instance owner.

Once you are logged in, type "db2" at the command line. If "db2" is not found, then recheck the. To execute your sql command type the following at the command line substitute with the name of the database you want to connect to :. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 10 years, 9 months ago. Active 10 years, 9 months ago. Viewed 47k times. Improve this question.



0コメント

  • 1000 / 1000