Unique SQL Inserts

I have a Users table that has a unique restriction on the username (for obvious reasons).

I use EF 4.0 DAL to populate the database and in the process of coding the CreateUser () method.

It...

  • It is better to catch a SqlException if I try to insert a username that already exists.
  • Do I explicitly check the username before trying to insert it into the database?

If you could also indicate the reasons why it would be great!

+5
source share
4 answers

, . , , -, "" , . , ( ), .

EDIT: , . , .

+3

, . , , , . . , , , , .

+2

, , , , . , , .

- , , -. , . , , , SSMS , .

+1

, . - . ...

0

All Articles