From the course: SQL Server 2008 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Creating computed columns - SQL Server Tutorial
From the course: SQL Server 2008 Essential Training
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…
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
-
-
-
-
-
-
Planning your database9m 39s
-
(Locked)
Creating a SQL Server database4m 7s
-
(Locked)
Creating tables7m 50s
-
Data types in SQL Server12m 25s
-
(Locked)
Defining keys8m 9s
-
(Locked)
Creating default values4m 39s
-
(Locked)
Creating check constraints2m 25s
-
(Locked)
Creating unique constraints4m 34s
-
Introduction to relationships and foreign keys9m 51s
-
(Locked)
Creating relationships in SQL Server Management Studio8m 14s
-
(Locked)
Database normalization11m 47s
-
(Locked)
Creating computed columns3m 10s
-
-
-
-
-
-
-
-
-
-
-
-