This is just for infromation if somebody has same problem. Thanks to @Panagiotis Kanavos for gettting me to this path.
SQL Server is supposed to be case insensitive, but as I am not sure if that is case in all installations at all times, I have used UPPER for table names. NOTE that this can make it considerably slower so if sure that it's case insensitive, don't do it like this:
private static bool GetSqlServerIndexUniqueness(DbConnection cnctn, string tableName, string indexName)
{
bool isUnique = false;
using (SqlCommand cmd = ((SqlConnection) cnctn).CreateCommand())
{
cmd.CommandText =
"SELECT is_unique FROM sys.indexes WHERE name = @IndexName AND object_id = " +
"(SELECT object_id FROM sys.tables WHERE upper(name) = @TableNameUpper)";
cmd.Parameters.AddWithValue("@IndexName", indexName);
cmd.Parameters.AddWithValue("@TableNameUpper", tableName.ToUpper());
var readValue = cmd.ExecuteScalar();
if (readValue != null)
isUnique = Convert.ToInt32(readValue) != 0;
}
return isUnique;
}
If indexName is uniquethe table / object_id subquery is not needed. This will make it a lot faster.