From the course: SQL Server 2008 Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Creating computed columns

Creating computed columns - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

Creating computed columns

There is a column that you can add to your tables that comes in handy from time-to-time and really it's not a real column at all. What it is, is a calculated or computed column. So let's say for example we're working with this OrderItem table, and I've got multiple entries here. I've only got 20 or so but we could have 50,000 of them that deal with ProductIDs, Quantities and UnitPrice. Or you might find it useful to have kind of a rolling total of each order item going, particularly if you've got a lot of separate quantities. So instead of having to load this data into an application to then perform a calculation, it just might be nice if each order item entry had its own little subtotal. So we can do that of course. We could just add a regular column. I'll go into that table into Design view and I'll add a new column called Total. I'll make it a money column, save my changes, I've allowed Null so won't complain about that right now, and then I go back in and try and edit directly in…

Contents