Removing Columns After Table Creation Using SQL

In summary, it is possible to delete and remove rows in a database, but not columns. This is because rows and columns are different things in a database. However, a good database should allow you to delete a column as long as there are no constraints preventing it. This can be done with an ALTER TABLE statement, though it is not considered a good practice unless prototyping. Altering the schema of a database at runtime is not recommended. The ability to delete and remove columns is a DDL command that is specific to the language being used.
  • #1
ponjavic
225
0
Isn't possible to delete and remove columns after a table has been created?
Rows works just fine but columns don't...
 
Computer science news on Phys.org
  • #2
in MySQL, this is done with http://dev.mysql.com/doc/mysql/en/ALTER_TABLE.html
 
Last edited by a moderator:
  • #3
Note that columns and rows in a database are very different things, so the fact that you can do something to a row doesn't automatically mean you should be able to do the same thing to a column.


Still, any good database should allow you to delete a column unless you've deliberately added constraints that would prevent it. But you have to modify the table to do that, usually with an ALTER TABLE statement.
 
  • #4
You can, but its not considered a good thing to do, except possibly when prototyping. This is because you are altering your schema, which shouldn't happen. Would you want to alter the form of a data structure at runtime?
 
  • #5
so-crates said:
You can, but its not considered a good thing to do, except possibly when prototyping. This is because you are altering your schema, which shouldn't happen. Would you want to alter the form of a data structure at runtime?

If your schema is wrong, why wouldn't you change it?
 
  • #6
It is a DDL command and is language specific.
 

What is SQL?

SQL stands for Structured Query Language, and it is a programming language used for managing and manipulating data in relational databases.

What is the purpose of removing columns after table creation using SQL?

The purpose of removing columns after table creation using SQL is to modify the structure of a table by removing unnecessary columns or adding new ones. This allows for more efficient data management and storage.

How do you remove a column using SQL?

To remove a column from a table using SQL, you can use the ALTER TABLE command followed by the DROP COLUMN option and the name of the column you want to remove. For example, ALTER TABLE table_name DROP COLUMN column_name;

Can you remove multiple columns at once using SQL?

Yes, you can remove multiple columns at once using SQL by separating the column names with a comma after the DROP COLUMN option. For example, ALTER TABLE table_name DROP COLUMN column1, column2, column3;

Is it possible to undo a column removal using SQL?

No, once a column has been removed from a table using SQL, it cannot be undone. However, you can create a new column with the same name and data type if needed.

Similar threads

Replies
11
Views
1K
  • Computing and Technology
Replies
1
Views
950
  • Programming and Computer Science
2
Replies
51
Views
4K
  • STEM Academic Advising
Replies
1
Views
670
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
7
Views
399
  • Programming and Computer Science
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Computing and Technology
Replies
14
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
489
Back
Top