Computed Column Alias — A First Look
Imagine you are maintaining a library register. For each book, you note down the date it was borrowed and the date it was returned. Now, if someone asks you, "How many days was this book out?", you would not find that number written anywhere in the register. You would have to calculate it on the spot: subtract the borrow date from the return date. That calculated number — the number of days — is not a column you originally wrote, but it is a piece of information you can derive from the columns you have.
In database terms, that derived piece of information is called a computed column. And when you give it a name — say, DaysBorrowed — that name is the alias.
The Precise Meaning
A computed column alias is a temporary, user-given name for a column that is created by performing an operation (calculation, concatenation, or any expression) on one or more existing columns in a table. The alias does not create a new permanent column in the table; it exists only for the duration of the query you are running. It is like writing a label on a sticky note and attaching it to a result — the label helps you refer to that result clearly, but it does not change the original data.
The NCERT textbook (Class 11, Informatics Practices, Chapter on "Database Query using SQL") introduces computed columns and aliases in the context of the SELECT statement. It states that an alias is used to give a temporary name to a column or an expression in the result of a query. The alias is written using the AS keyword, though AS is optional in many SQL implementations.
Why It Matters
-
Clarity: Instead of seeing a raw expression like (ReturnDate - BorrowDate) as a column heading in your output, you see a meaningful name like DaysBorrowed. This makes the result readable for anyone — including a teacher, a manager, or a client.
-
No Permanent Change: You do not clutter the original table with extra columns that may only be needed for one specific report. The alias vanishes after the query ends, keeping the database clean.
-
Flexibility: You can create aliases for any expression — not just arithmetic. For example, you could combine a first name and last name column into a single column called FullName using concatenation, and give that combined column an alias.
A Simple Example (Without Numbers) …