2012年2月16日星期四

any difference betwween these 2 statement

hi all:

who can tell me what's the difference between the following 2 statement.

The 1st one:

CREATE VIEW country_v (country_code, country_name) AS
SELECT COUNTRY.CNTRY_CD, COUNTRY.CNTRY_NM
FROM COUNTRY

The 2nd one:

CREATE VIEW country_v AS
SELECT COUNTRY.CNTRY_CD, COUNTRY.CNTRY_NM
FROM COUNTRY

Actually i didnot make sense what's usage of the parameters when creating views?

Hi,

You override the column names in the view in the first statement, in second you reuse them as they are. This is required only when a column is derived from an arithmetic expression, a function, or a constant; when two or more columns may otherwise have the same name, typically because of a join; or when a column in a view is specified a name different from that of the column from which it is derived.

Regards,

Janos

|||

It is not a parameter. It is a column aliases name. There is no big difference between these two view creation (only the column names are changed here).

Is the name to be used for a column in a view. A column name is required only when a column is derived from an arithmetic expression, a function, or a constant; when two or more columns may otherwise have the same name, typically because of a join; or when a column in a view is specified a name different from that of the column from which it is derived. Column names can also be assigned in the SELECT statement.

Note: If column is not specified, the view columns acquire the same names as the columns in the SELECT statement.

The following statements are identical.

Code Snippet

CREATE VIEW country_v (country_code, country_name)AS

SELECT COUNTRY.CNTRY_CD, COUNTRY.CNTRY_NM

FROM COUNTRY

--Or

CREATE VIEW country_vAS

SELECT COUNTRY.CNTRY_CD as country_code, COUNTRY.CNTRY_NM as country_name

FROM COUNTRY

Code Snippet

CREATE VIEW country_vAS

SELECT COUNTRY.CNTRY_CD, COUNTRY.CNTRY_NM

FROM COUNTRY

-- OR

CREATE VIEW country_v(CNTRY_CD,CNTRY_NM)AS

SELECT COUNTRY.CNTRY_CD, COUNTRY.CNTRY_NM

FROM COUNTRY

|||

Got it

Thanks to both

没有评论:

发表评论