I have a table which have a row containing user emails and I want to add a constraint to make this row unique. The problem is that there are some (around 200) columns with empty values.
I need to generate dummy values and insert them to the empty columns.
How can I do it?
Thanks
You can use the T-SQL
function newid()
newid() Creates a unique value of type uniqueidentifier.
UPDATE MyTable set Column = newid() where Column is null
If you use SQL Server 2008 - consider unique index by email which filters out null values, smth like that:
CREATE UNIQUE INDEX [UX.Email, not null] on dbo.YourTable(email)
WHERE email is not null
OR
For versions of SQL Server prior to 2008 you can use the value of your primary key identity of row, if you have one
update yourtable set email = id where email is null
If you have no such a key, at least you can use NEWID() function instead of id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With