Discussion:
Keyboard Input in Scripts
(too old to reply)
Gene Wirchenko
2012-05-25 21:03:25 UTC
Permalink
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
Erland Sommarskog
2012-05-25 21:24:39 UTC
Permalink
Post by Gene Wirchenko
Is there a way to get keyboard input while executing a script?
As long as you write the script in a language which runs in an environment
that has access to your keyboard, it should be no problem.

If you have something that runs in a service with no desktop or keyboard,
the situation is considerably more dire, though.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
Loading...