I'm a student and am trying to create a column for my table, but only if it does not exist. I did come across a solution:
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA="bd_company" AND TABLE_NAME="users" AND column_name="user_age";
If it returns 0 it means it does not exists, so i can create it. But my question is: What if i want to do this for 5 columns?
Like a for loop... Something like "For every column, do SELECT COUNT(*)... and if not exists create table"
Is this possible? Sorry if this is a silly question, i really have no idea, but want to know it anyway... I have both SQL Server Management Studio and MySQL Workbench. I can use both scenarios and solutions.
Thanks in advance.