I've a varbinary column profile_name
in my accounts
table. Initially, I thought my users will not enter special characters and will keep it short and sweet.
But, that was my terrible mistake. They started keeping long profile names with lots of special characters, which is causing me trouble.
Now, I've limited their options to alphanumerics, underscore and hyphen and should be 3 to 10 characters. In other words this regex: [\w-]{3,10}
The task is uphill now.
I've 570 users already and I want to update their profile names to fit into the above rules.
I've some barebone code:
public NpMaintainance()
{
UTF8Encoder encode = new UTF8Encoder();
List<string> names = new List<string>();
using (con)
{
con.Open();
using (cmd)
{
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandText = "select profile_name from accounts";
using (dr = cmd.ExecuteReader())
{
names.Add((dr[0] as byte[]).ToUnicodeString(encode));
}
}
}
}
I've just the code, which I've not tried, because it is a production site. Now names
contains the profile names, which I've to reinsert into the table. And to add to my problem, profile_name
is unique, so no two names should be same.
I've provided all the details I could, and hoping to get an answer!
What should I do? Is there any other way(using only sql?), or if not please help me with the way I'm currently doing!