Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Modifying columns
7. What you can and cannot change
Modifying identities
Modifying sequences
Summary

Instruction

Great! You successfully extended varchar and decimal columns. How about other column modifications? Can you change a boolean field to an integer? Can you shorten a column?

The SQL standard says that you can only extend columns to accept longer text values, larger numbers, etc. What's more, you can only change column types to matching types. In other words, you can't change a varchar column to an integer column or a decimal column into a boolean column.

In practice, databases often allow more types of modifications than the SQL standard. For instance, PostgreSQL will try to convert numerical values into text if you instruct it to convert decimal into varchar. And while most databases allow you to shorten a column, it's usually a bad idea to do so – you could accidentally (and permanently) lose some data.

On the other hand, database developers rarely change column types. If anything, they extend columns in compliance with the SQL standard, just as we showed you in the previous exercises.

Exercise

Click Next exercise to continue.