I was looking at the ALTER procedure to add a column to an already-created table and a lot of the answers specified that adding columns dynamically wasn't considered good practice.
I am trying to create an extra column to monitor the attendance on a particular day so in relation to that aim, is altering the table still bad practice, because I can't really see a way around it?
Database should be created in the very begining of project and it should stay as it is. When you create your query, for example INSERT and you don't use named colummns it can crush your system.
For EXAMPLE
INSERT INTO `table` VALUES('a','b','c');
instead of
INSERT INTO `table`(column1, column2, column3,...)
VALUES ('a', 'b', 'c',...)
There are a lot of lines of code than can crash. Mostly those that are based on columns numbers instead of their names. Changing DB can create a lot of problems and if the system is pretty big they can be hard to be found.
It's better practice to create relations within tables than creating a lot of columns.
Morever you should read about Database normalization which "is the process of organizing the fields and tables of a relational database to minimize redundancy and dependency."
It's not something that should be done willy-nilly and it requires planning but if you have changing requirements or simply forgot something, by all means: add the column.
Never adding a column is simply no good advice and not realistic. You should be able to
but keep in mind that adding a column
There's too ways to understand your question,
It depends when do you want to make these changes.
If the changes happen during because of extended features of a system, they are IMHO ok.
But if the changes are done continuously while using the application, that is bad design.
In general, you make a distinction between
Data Description Language (DDL) where you make changes in the layout. These are mainly CREATE TABLE
, ALTER TABLE
and alike. These changes should not be done during the normal run of the application, only during setup.
Data Manipulation and Query Language (DML) where you operate on the data in a DB. This is what an aplication normally does: INSERT
, DELETE
, SELECT
.