Gene Wirchenko
2012-05-25 21:03:25 UTC
Dear SQLers:
Is there a way to get keyboard input while executing a script?
I have done a bit of looking and can not find it. I do not know
what to call it. Does it exist?
If nothing else, I would like to be able to have a warning for
some scripts, say
This script drops the CBS3 database and recreates it empty.
All existing data in the CBS3 database will be lost.
Are you quite sure that you wish to do this? _
It is useful to have a testing script to blow away a database. It
is not so useful to have it run by accident!
I could also write some useful little utilities if keyboard input
is available. (This could be much more flexible than templates.)
Failing this, what sorts of kludges are available?
One that I thought of is checking if a certain database exists
and proceeding only if it does and then deleting it. Is this safe?
Reliable? (Yes, I know the multi-user issues, but on a development
box used by only one person?)
***** Start of P-code *****
if ReallyDoIt database does not exist
begin
print 'This script drops the CBS3 database and recreates it empty.'
print 'All existing data in the CBS3 database will be lost.'
print 'If you really want to do this, create database ReallyDoIt,'
print 'and rerun this script.'
print 'Aborting script.'
set noexec on
end
drop database ReallyDoIt
if drop failed
begin
print 'drop database ReallyDoIt failed.'
print 'Aborting script.'
set noexec on
end
<script actions>
set noexec off
***** End of P-code *****
Sincerely,
Gene Wirchenko
Is there a way to get keyboard input while executing a script?
I have done a bit of looking and can not find it. I do not know
what to call it. Does it exist?
If nothing else, I would like to be able to have a warning for
some scripts, say
This script drops the CBS3 database and recreates it empty.
All existing data in the CBS3 database will be lost.
Are you quite sure that you wish to do this? _
It is useful to have a testing script to blow away a database. It
is not so useful to have it run by accident!
I could also write some useful little utilities if keyboard input
is available. (This could be much more flexible than templates.)
Failing this, what sorts of kludges are available?
One that I thought of is checking if a certain database exists
and proceeding only if it does and then deleting it. Is this safe?
Reliable? (Yes, I know the multi-user issues, but on a development
box used by only one person?)
***** Start of P-code *****
if ReallyDoIt database does not exist
begin
print 'This script drops the CBS3 database and recreates it empty.'
print 'All existing data in the CBS3 database will be lost.'
print 'If you really want to do this, create database ReallyDoIt,'
print 'and rerun this script.'
print 'Aborting script.'
set noexec on
end
drop database ReallyDoIt
if drop failed
begin
print 'drop database ReallyDoIt failed.'
print 'Aborting script.'
set noexec on
end
<script actions>
set noexec off
***** End of P-code *****
Sincerely,
Gene Wirchenko