BadHorsie
BadHorsie

Reputation: 14554

Can you have an INT or DECIMAL field only accept negative numbers?

Like an unsigned field but only for negative numbers.

I'm just curious.

Upvotes: 1

Views: 949

Answers (2)

Woot4Moo
Woot4Moo

Reputation: 24316

This can be accomplished with a before-insert trigger.

CREATE DEFINER=`root`@`localhost` trigger triggerName 
BEFORE INSERT ON tableA
FOR EACH ROW BEGIN

IF(value > 0) THEN
STOP ACTION  
END IF;

Upvotes: 6

Charles Bretana
Charles Bretana

Reputation: 146499

You could just use an unsigned int and a minus sign on every insert, update and select.

Upvotes: 4

Related Questions