Daffi
Daffi

Reputation: 516

Database Default Column

just a quick question regarding the Database Structure. I have to manage several roles but there needs to be only one default role, which is User automatically is assigned to.

How would you store this default tole in the DB? Something like that?

ID     |   Name   | IsDefault
-----------------------------
1      |   Admin  | no
2      |   User   | yes

If so, how can you check that only one role is marked as default?

Thanks

Upvotes: 0

Views: 54

Answers (1)

a1ex07
a1ex07

Reputation: 37364

For Oracle you can have for instance, check constraint on IsDefault column, so it can be just yes or no. Then

CREATE UNIQUE INDEX IDXU_TABLE1_ISDEFAULT ON table1(CASE WHEN IsDefault ='yes' THEN IsDefault ELSE NULL END);

Upvotes: 1

Related Questions