Getting accurate table layouts
OSQLRf1 isn't very "smart" about how it computes the lengths
of fields: it simply looks at the column headers that OSQL supplies.
For that reason, if the name of the field is longer than the
field value, the former will be used in the layout file produced
by OSQLRf2.
If you need more precise layouts, you can use
the built-in stored procedure sp_help.
Here's an example of how to do this:
osql -U sa -P -Q "sp_help users" -d WebBoard -s # | OSQLRF1 -Q >Out.Txt
That example will dump out the users table into Out.Txt.
The format isn't very pretty, but at least you'll know the exact
field types and lengths.
You can also use sp_help on any triggers, constraints, etc.
which you'll see listed.
As in the previous examples, I assume that your DB owner is
"sa" (follows
the -U command-line argument),
and that your password
(follows
the -P command-line argument) is
the default of blank.
If you want better formatting, you can use the batch file
OSQLTab.Bat
You simply execute it from the command line with the name of
the database and the name of the table, e.g.:
OSQLTab WebBoard User
This example will print out the user table in the DB called
WebBoard.
Output will be appended to the file OSQLTab.Txt, which
will be created as new if it doesn't exist.
Two additional programs, Repl.Exe and OSQLRf3.Exe,
are invoked in this batch file.
Here's what the batch file OSQLTab.Bat does in order to
produce a table layout, in case you want to use this strategy in
your own processes:
OSql -U %DBO% -P %PWD% -Q "sp_help %2" -d %DBNAME% -s # | OSQLRF1 -q >T1.Dat
OSQLRF3 -q < T1.Dat > T2.Dat
DBCvt T2.Dat LayOut.Txt -q -noquotes -varnoflds
After executing this example, LayOut.Txt will contain a
fairly readable layout. The DOS batch file variable
%DBNAME% is the database name, the variable %2 is
the table name, the variable %DBO% is the DB owner, and
the variable %PWD% is the password.
The -q parm to OSQLRf1 suppresses the standard
program "help" printout.
Note that this works for base tables only: not views.
Return
to table of contents