-1

how to create a table with elements Login Id Password Username

I have to create a table with username which can be null after inserting values for username and password and username should be not null before inserting values for loginId and password.

Is there any way that I can do to make this condition work while I create the SQL table ?

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
Veerabala J
  • 553
  • 1
  • 5
  • 14

2 Answers2

1

A simple google research and i got an answer to your question. --> Sql Conditional Not Null Constraint

dazageek
  • 24
  • 4
0

If I understand correctly, you want a check constraint:

alter table t add constraint chk_t_fields
    check (username is not null or (loginid is not null and password is not null));

This checks that one or the other columns have values.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786