mercredi 25 avril 2018

SQL server - Masking / changing value uniqueidentifier before inserting

So the main goal is to mask or randomly change value of uniqueidentifier before inserting.

For example: I have a table

Create table Student
(
Student_ID masked WITH (FUNCTION='default()') DEFAULT NEWID()
Student_Name varchar(100),
)

Im inserting new data:

insert into DDM_Student_Sample values ('B9BC5E61-0F3C-498F-AF2C-1AC16446A846','Stuart Little Joe')

The result is the same output as it was inserted, i.e. uniqueidentifier = 'B9BC5E61-0F3C-498F-AF2C-1AC16446A846'

I have created a user with login:

CREATE USER MAIN_USER FOR LOGIN MAIN_USER; 
EXEC sp_addrolemember 'db_owner', 'MAIN_USER';

By toturial (http://www.sqlservercentral.com/articles/Security/149689/) it says you must create user without login. Maybe thats the problem why Student_ID does not change randomly.

In the end, maybe there is another way before inserting data to table change it value randomly. Or I should just change value from front-end? And write something like :

model.StudentId = Guid.NewGuid();
model.SaveToDatabase();




Aucun commentaire:

Enregistrer un commentaire