i know like this to insert a new record
INSERT INTO dbo.Customer_data (Customer_id, Customer_Name, Credit_card_number)
VALUES (25665, 'mssqltips4', EncryptByKey( Key_GUID('SymmetricKey1'), CONVERT(varchar,'4545-58478-1245') ) );
but i want to insert a new record with a normal insert statement which should get encrypted. ex:
INSERT INTO dbo.Customer_data (Customer_id, Customer_Name, Credit_card_number)
VALUES (25665, 'mssqltips4','4545-58478-1245') ) );
Few months ago I had similar situation. A table containing personal data need to have some of the columns encrypted, but the table is used in legacy application and have many references.
So, I you can create a separate table to hold the encrypted data:
Then create a
INSTEAD OF INSERT UPDATE DELETEtrigger on the original table.The logic in the trigger is simple:***or43-****-****-****)Then, perform a initial migration to move the data from the original table to the new one and then mask it.
Performing the steps above are nice because:
EXECUTE AS OWNERin order to have access to the symmetric keys and perform changes directly in the T-SQL statement without opening the certificates or by users who have not access to themIt depends on your environment and business needs because for one of the tables I have stored the encrypted value as new column, not separate table. So, choose what is more appropriate for you.