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..

Member Avatar for hfx642

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.