1

I'm building a small web application which contains user types of User or Admin. Within my users table, I have a boolean flag, is_admin. I'm trying to design a query such that a web application user can perform an insert into a table if is_admin is true.

Is there a clear way to write an insert query where a boolean value is true? Should I be using a procedure or is there a better way to handle this?

dataviews
  • 2,466
  • 7
  • 31
  • 64
  • 1
    Does this answer your question? [Do conditional INSERT with SQL?](https://stackoverflow.com/questions/16636698/do-conditional-insert-with-sql) – user14063792468 May 30 '22 at 02:14

1 Answers1

1

You can check first if it is is_admin from users table and then insert into another table.

IF EXISTS (SELECT * FROM users WHERE is_admin=1 ) 
    INSERT INTO Table 
Damini Suthar
  • 1,470
  • 2
  • 14
  • 43