Renaming columns - sql, PL-SQL Programming

Renaming Columns - SQL

SQL has no direct counterpart of RENAME. To derive the table on the right in Figure 4.4 from the table on the left, Tutorial D has IS_CALLED RENAME ( StudentId AS Sid ).

1010_Renaming Columns - SQL.png

                                                    Figure: Tables differing only in a column name

It shows how the same effect can be achieved in SQL. Note that the SELECT clause has to include all the columns that are not subject to renaming, as well as those that are.

Example: Renaming a column

SELECT StudentId AS Sid, Name

FROM IS_CALLED

Explanation

  • Each element of a SELECT clause is an expression of arbitrary complexity that can reference one or more columns of the SELECT clause's input table. Note that the expression is not required to reference any columns: it might be just a literal, for example.
  • If the expression consists of just a column reference, then the name of the referenced column is the name of the corresponding column in the result.
  • If the expression is followed by the key word AS, then the resulting column has the column name given after that key word.

SQL allows the result to have two or more columns of the same name. For example, if we replace Sid by Name in Example, we still have a valid SQL SELECT expression.

Posted Date: 1/18/2013 5:07:25 AM | Location : United States







Related Discussions:- Renaming columns - sql, Assignment Help, Ask Question on Renaming columns - sql, Get Answer, Expert's Help, Renaming columns - sql Discussions

Write discussion on Renaming columns - sql
Your posts are moderated
Related Questions
IN OUT Mode An IN OUT parameter passes initial values to the subprogram being called and return efficient values to the caller. Within the subprogram, an IN OUT parameter acts

Effects of NULL The numeric variable X, perhaps of type INTEGER, might be assigned NULL. In that case the result of evaluating X + 1 is NULL, and so SET Y = X + 1 assigns NULL

Bulk Fetching The illustration below shows that you can bulk-fetch from a cursor into one or more collections: DECLARE TYPE NameTab IS TABLE OF emp.ename%TYPE; TYPE S

Literals A literal is an explicit numeric, string, character, or Boolean value not represented by an identifier. Numeric literal 147 and the Boolean literal FALSE are some of

Manipulating Objects: You can use an object type in the CREATE TABLE statement to indicate the datatype of a column. When the table is created once, you can use the SQL statem

Example of Alternative formulation as a table constraint Example: Alternative formulation as a table constraint ALTER TABLE EXAM_MARK ADD CONSTRAINT Must_be_enrolled_to_

COMMIT Statement The COMMIT statement explicitly makes everlasting changes to the database during the present transaction. The Changes made to the database are not considered e

Grouping and Ungrouping in SQL Example specifying EXAM_MARK in place of COURSE in the main FROM clause. Example: Obtaining C_ER2 from EXAM_MARK SELECT CourseId, CAST

Fetching from a Cursor Variable The FETCH statement retrieve rows one at a time from the product set of a multi-row query. The syntax for the same is as shown: FETCH {curso

Initializing Objects: Till you initialize an object by calling the constructor for its object type, the object is automatically null. That is, the object itself is null, not me