I want to have a UNIQUE constraint on my Barcode
column which may contain null values.
How do I create the constraint that allows multiple null values?
I use a local Database.sdf
file (Microsoft SQL Server Compact 4.0 with the .NET Framework Data Provider for Microsoft SQL Server Compact 4.0).
I tried this :
SqlCeConnection con = null;
con = new SqlCeConnection(@"Data Source=|DataDirectory|\Database.sdf");
con.Open();
try
{
SqlCeCommand cmd = con.CreateCommand();
cmd.CommandText = "CREATE UNIQUE NONCLUSTERED INDEX Barcodex ON Products(Barcode) WHERE Barcode IS NOT NULL";
cmd.ExecuteReader();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
but it is not working.
The error I got :
There was an error parsing the query,[Token line number =1,Token line offset =64,Token in error = WHERE]
Any help?