As I said in the comments, I'd strongly recommend that you pivot your settings table and stop stingly-typing everything:
DECLARE @EncryptedPassword VARBINARY(8000) = ENCRYPTBYPASSPHRASE('ABCD','password')
DECLARE @Setting AS TABLE (
Lock char(1) not null default 'X' primary key check (Lock='X'),
SomethingBoolean bit not null,
Password varbinary(8000) not null)
INSERT INTO @Setting (SomethingBoolean, Password) VALUES
(1,@EncryptedPassword)
SELECT * FROM @Setting
Results:
Lock SomethingBoolean Password
---- ---------------- -----------------------------------------------------------------------------------------------------------
X 1 0x02000000588C2EB2C67DED10B7828C05500008DB1B1E53EFF63168EC607CA80CA2A1147B75F0A9D50F6B95C810D6DCED37AE8186
This means that settings are actually stored with the correct data type. Not only can we rely on type and null checks to ensure settings are correct, we can also apply individual CHECK
constraints if required on individual settings.
(Lock
is just there to ensure that this table contains 1 row only)