name
The name (optionally schema-qualified) of an existing table to alter. If ONLY is specified before the table name,only that table is altered. If ONLY is not specified,the table and all its descendant tables (if any) are altered. Optionally,* can be specified after the table name to explicitly indicate that descendant tables are included.
什么是后代表?
解决方法
Postgresql implements table inheritance,which can be a useful tool
for database designers. (sql:1999 and later define a type inheritance
feature,which differs in many respects from the features described
here.)Let’s start with an example: suppose we are trying to build a data
model for cities. Each state has many cities,but only one capital. We
want to be able to quickly retrieve the capital city for any
particular state. This can be done by creating two tables,one for
state capitals and one for cities that are not capitals. However,what
happens when we want to ask for data about a city,regardless of
whether it is a capital or not? The inheritance feature can help to
resolve this problem. We define the capitals table so that it inherits
from cities:
CREATE TABLE cities ( name text,population float,altitude int -- in feet ); CREATE TABLE capitals ( state char(2) ) INHERITS (cities);
In this case,the capitals table inherits all the columns of its
parent table,cities. State capitals also have an extra column,state,
that shows their state.In Postgresql,a table can inherit from zero or more other tables,and
a query can reference either all rows of a table or all rows of a
table plus all of its descendant tables. The latter behavior is the
default.
资料来源:https://www.postgresql.org/docs/8.4/static/ddl-inherit.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。