In my database, I have constant rows being created for my own purposes. Some of these rows are trash, unneeded spam that I'd like to blacklist from being created. Is there an SQL statement that I can send to blacklist a row from being created if it has a specific field name? For example, creation of any rows WHERE column = 1 will be completely disallowed and the rows will just be denied creation.
Asked
Active
Viewed 143 times
1 Answers
1
One way is a check constraint. other, is a BEFORE INSERT trigger

murison
- 3,640
- 2
- 23
- 36
-
what specifically do I type for BEFORE INSERT trigger? I'm in the PHPMyAdmin Trigger section for my database, I have my table selected, idk what to type in the "definition" portion. I need to do something like IF column_name = custom_value THEN DO NOT INSERT ROW. That line is completely wrong, but it spells out what needs to happen. – Aris Mar 30 '15 at 01:21
-
Well - just raise an error ;) to be honest - I don't know how to doit in MySQL. in PostgreSQL you just do `RAISE [EXCEPTION] 'your exception text'` and you're done. I think you need to go with `SIGNAL` keyword (http://dev.mysql.com/doc/refman/5.5/en/signal.html), but it's not as "out-of-the-box" as in Postgres. there are some threads on SO about this (like this one: http://stackoverflow.com/questions/4862911/how-to-throw-an-error-in-mysql-procedure), so you'll figure it out. Why not go with the check constraint? it is much easier - especially for simple clauses... – murison Mar 30 '15 at 07:11