Advance SQL: Computed Column

365 Days of Daily Coding: Day 145

I am starting fairly early today writing this blog. For the past few days, I was working on it during the evening time and gosh! by then I am famished and my brain has very less power to concentrate. I have decided to visit the gym today which I am very happy about. In the past, I had a membership with a gym but I cancelled it right before the pandemic.

Puzzle #30: Select Star

https://advancedsqlpuzzles.com/advanced-sql-puzzles/

The solution has been taken from the git repo.

--Add the following constraint
ALTER TABLE #Products ADD ComputedColumn AS (0/0);

Computed columns:

  • Are virtual columns that are derived from an expression referencing one more columns.
  • For example: a computed column can be cost AS price*qty.
  • Are not physically stored in the tables and hence cannot be used for indexing and constraints such as NOT NULL or foreign or primary key cannot be used.

Leave a comment