Хорошим правилом является добавление в БД служебной таблицы, в одном из полей которой указывается версия БД (структуры БД).
А при запуске следует проверять версию структуры БД и, при необходимости, выполнять соответствующий SQL-скрипт на обновление структуры.
Тогда не будет повода пугать пользователей.
У меня, например, используется что-то типа этого:
- Код: Выделить всё
IF NOT EXISTS (SELECT * FROM [sysobjects] WITH(NOLOCK) WHERE [type] = 'U')
GOTO CreateDatabase
IF NOT EXISTS (SELECT * FROM [sysobjects] WITH(NOLOCK) WHERE [type] = 'U' AND [name] = 'options')
GOTO CreateDatabase
DECLARE @DBVersion nvarchar(80)
SELECT @DBVersion = CAST([value] AS nvarchar)
FROM [options] WITH(NOLOCK) WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_version'
IF @DBVersion = '01.04.0004'
GOTO Ver01040004
ELSE IF @DBVersion = '01.03.0003'
GOTO Ver01030003
ELSE IF @DBVersion = '01.02.0002'
GOTO Ver01020002
ELSE IF @DBVersion = '01.01.0001'
GOTO Ver01000001
ELSE IF @DBVersion = '1.0.0'
GOTO Ver01000000
ELSE
GOTO VerUnknown
VerUnknown:
PRINT 'Unknown version!'
PRINT 'Update database manually.'
GOTO FinishProcessing
Ver01040004:
PRINT 'Current version: 01.04.0004 (date 2009-01-29)'
PRINT 'Update process finished.'
GOTO FinishProcessing
Ver01030003:
PRINT 'Current version: 01.03.0003 (date 2008-07-11); Update to: 01.04.0004'
...
UPDATE [options] SET [value] = '20090129' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_date'
UPDATE [options] SET [value] = '01.04.0004' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_version'
GOTO Ver01040004
Ver01020002:
PRINT 'Current version: 01.02.0002 (date 2008-07-08); Update to: 01.03.0003'
...
UPDATE [options] SET [value] = '20080711' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_date'
UPDATE [options] SET [value] = '01.03.0003' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_version'
GOTO Ver01030003
Ver01000001:
PRINT 'Current version: 01.01.0001 (date 2008-07-08); Update to: 01.02.0002'
...
UPDATE [options] SET [value] = '20080711' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_date'
UPDATE [options] SET [value] = '01.02.0002' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_version'
GOTO Ver01020002
Ver01000000:
PRINT 'Current version: 1.0.0 (date 2007-02-21); Update to: 01.01.0001'
...
UPDATE [options] SET [value] = '20080708' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_date'
UPDATE [options] SET [value] = '01.01.0001' WHERE [user_id] IS NULL AND [section] = 'system' AND [name] = 'db_version'
GOTO Ver01000001
CreateDatabase:
...
FinishProcessing:
...
Lasciate ogni speranza, voi ch'entrate.