create_view.7
来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· 7 代码 · 共 134 行
7
134 行
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "CREATE VIEW" "" "2008-01-03" "SQL - Language Statements" "SQL Commands".SH NAMECREATE VIEW \- define a new view.SH SYNOPSIS.sp.nfCREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW \fIname\fR [ ( \fIcolumn_name\fR [, ...] ) ] AS \fIquery\fR.sp.fi.SH "DESCRIPTION".PP\fBCREATE VIEW\fR defines a view of a query. The viewis not physically materialized. Instead, the query is run every timethe view is referenced in a query..PP\fBCREATE OR REPLACE VIEW\fR is similar, but if a viewof the same name already exists, it is replaced. You can only replacea view with a new query that generates the identical set of columns(i.e., same column names and data types)..PPIf a schema name is given (for example, CREATE VIEWmyschema.myview ...) then the view is created in the specifiedschema. Otherwise it is created in the current schema. Temporaryviews exist in a special schema, so a schema name may not be givenwhen creating a temporary view. The name of the view must bedistinct from the name of any other view, table, sequence, or indexin the same schema..SH "PARAMETERS".TP\fBTEMPORARY or TEMP\fRIf specified, the view is created as a temporary view.Temporary views are automatically dropped at the end of thecurrent session. Existingpermanent relations with the same name are not visible to thecurrent session while the temporary view exists, unless they arereferenced with schema-qualified names.If any of the tables referenced by the view are temporary,the view is created as a temporary view (whetherTEMPORARY is specified or not)..TP\fB\fIname\fB\fRThe name (optionally schema-qualified) of a view to be created..TP\fB\fIcolumn_name\fB\fRAn optional list of names to be used for columns of the view.If not given, the column names are deduced from the query..TP\fB\fIquery\fB\fRA SELECT [\fBselect\fR(7)] orVALUES [\fBvalues\fR(7)] commandwhich will provide the columns and rows of the view..SH "NOTES".PPCurrently, views are read only: the system will not allow an insert,update, or delete on a view. You can get the effect of an updatableview by creating rules that rewrite inserts, etc. on the view intoappropriate actions on other tables. For more information seeCREATE RULE [\fBcreate_rule\fR(7)]..PPUse the DROP VIEW [\fBdrop_view\fR(7)]statement to drop views..PPBe careful that the names and types of the view's columns will beassigned the way you want. For example,.sp.nfCREATE VIEW vista AS SELECT 'Hello World';.sp.fiis bad form in two ways: the column name defaults to ?column?,and the column data type defaults to \fBunknown\fR. If you want astring literal in a view's result, use something like.sp.nfCREATE VIEW vista AS SELECT text 'Hello World' AS hello;.sp.fi.PPAccess to tables referenced in the view is determined by permissions ofthe view owner. However, functions called in the view are treated thesame as if they had been called directly from the query using the view.Therefore the user of a view must have permissions to call all functionsused by the view..SH "EXAMPLES".PPCreate a view consisting of all comedy films:.sp.nfCREATE VIEW comedies AS SELECT * FROM films WHERE kind = 'Comedy';.sp.fi.SH "COMPATIBILITY".PPThe SQL standard specifies some additional capabilities for the\fBCREATE VIEW\fR statement:.sp.nfCREATE VIEW \fIname\fR [ ( \fIcolumn_name\fR [, ...] ) ] AS \fIquery\fR [ WITH [ CASCADED | LOCAL ] CHECK OPTION ].sp.fi.PPThe optional clauses for the full SQL command are:.TP\fBCHECK OPTION\fRThis option has to do with updatable views. All\fBINSERT\fR and \fBUPDATE\fR commands on the viewwill be checked to ensure data satisfy the view-definingcondition (that is, the new data would be visible through theview). If they do not, the update will be rejected..TP\fBLOCAL\fRCheck for integrity on this view..TP\fBCASCADED\fRCheck for integrity on this view and on any dependentview. CASCADED is assumed if neitherCASCADED nor LOCAL is specified..PP.PP\fBCREATE OR REPLACE VIEW\fR is aPostgreSQL language extension.So is the concept of a temporary view..SH "SEE ALSO"DROP VIEW [\fBdrop_view\fR(7)]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?