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
From the course: Database Foundations: Data Structures
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Validate data with constraints3m 9s
-
(Locked)
Null constraints5m 34s
-
(Locked)
Unique constraints3m 46s
-
(Locked)
Setting default values3m 14s
-
(Locked)
Check constraints3m 8s
-
(Locked)
Challenge: Add constraints to a table46s
-
(Locked)
Solution: Add constraints to a table6m 29s
-
(Locked)
Solution: Set additional constraints on the data10m
-
(Locked)
-