0

Hi everyone,

I've been trying different commands that check inputs that will be entered into the tables I've got. I want to check that Amount/Ename columns can not be NULL.

What's <> do in SQL?

// first command
 ALTER TABLE Emp ADD CONSTRAINT CK_AMOUNT CHECK ( AMOUNT NOT NULL);

 // second command
 ALTER TABLE Emp ADD CONSTRAINT CK_AMOUNT CHECK ( AMOUNT != NULL);

They accept null values and the default value is 0

//first command
 ALTER TABLE Emp ADD CONSTRAINT CK_ENAME CHECK ( Ename NOT NULL);

// second command
 ALTER TABLE Emp ADD CONSTRAINT CK_ENAME CHECK ( Ename != NULL);

I also want my tables to accept specific values, for example, payment method has to be one of these options such as master card, visa or cash.

ALTER TABLE Emp ADD CONSTRAINT CK_Pay CHECK ( Pay="master card" OR "visa" OR "cash");

Thanks for the help..

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by hfx642
0

Try these out...

Alter Table Emp Modify (Amount NOT Null);
Alter Table Emp Modify (EName NOT Null);
Alter Table Emp Add Constraint CK_Pay Check (Pay in ('master card', 'visa', 'cash'));

Of course, the data in the tables have to already be valid for the constraints to work.
It is better to put your constraints on when you create the table.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.