From the course: Developing Microsoft SQL Server 2016 Databases

Unlock this course with a free trial

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

Calculate table columns

Calculate table columns

- [Instructor] When creating a data table, it's possible to have SQL Server perform some basic calculations to populate a column of data. These are called calculated or computed columns. When defining the column data type, you'll simply supply an expression that can include non-computed column names, constants, functions, and any combination of these connected by operators. Let's take a look by creating a new database called CalculatedColumns, and then switching into it. I'll execute these first four lines. Then, we'll create a new data table called Products in the dbo schema. The Products table will include a column for our product ID, which will be the primary key for the table, and it'll be an identity. We'll start at one and increment one for each of our new products. The next column will be our product name, and that'll be stored as a Unicode variable character data type, up to 100 characters. Then, we'll store the…

Contents