In SQL insert, generally we specify the names of the columns in the SQL. Is there a way to generate that dynamically? basically if we specify the names of columns then tomorrow if a new col is added, there is a code change involved. How can i avoid this?
I am thinking of follg solution –
How about getting the names of the columns via
select column_name,* from information_schema.columns where table_name = ” order by ordinal_position;
& then create the INSERT statement with the columns? This way we do not specify the column names in the SQL…
Any thoughts?
I solved this by getting the names of the columns via
select column_name,* from information_schema.columns where table_name = ” order by ordinal_position;
& then create the INSERT statement with the columns. By this I avoided specifying the column names in the query