From the course: Database Foundations: Data Structures

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Setting default values

Setting default values

- [Instructor] A default value can be automatically saved into a column when one isn't supplied during a row insert. If we take a look at the customers table inside of the SQL Server version of the two trees database, we'll see that we have a couple of columns that we can use to store some address information. Let's suppose that most of our customers come from the state of California, we can have the RDBMS, automatically fill in the appropriate two letter state abbreviation for every new row. SQL Server and PostgreSQL take two different approaches to this when you're adding in the constraint to an existing column. In SQL Server, we need to alter the table customers, ADD CONSTRAINT, then we can name the constraint, followed by the default keyword, the value that we want inserted, and the two letter state abbreviation for California is CA, then the keyword, FOR, and finally, the column name that we want to apply the…

Contents