📄 alter_table.sgml
字号:
endterm="sql-cluster-title"> or one of the forms of <command>ALTER TABLE</> that forces a table rewrite. </para> <note> <para> While <command>CREATE TABLE</> allows <literal>OIDS</> to be specified in the <literal>WITH (<replaceable class="PARAMETER">storage_parameter</>)</literal> syntax, <command>ALTER TABLE</> does not treat <literal>OIDS</> as a storage parameter. </para> </note> </listitem> </varlistentry> <varlistentry> <term><literal>RESET ( <replaceable class="PARAMETER">storage_parameter</replaceable> [, ... ] )</literal></term> <listitem> <para> This form resets one or more storage parameters to their defaults. As with <literal>SET</>, a table rewrite might be needed to update the table entirely. </para> </listitem> </varlistentry> <varlistentry> <term><literal>INHERIT <replaceable class="PARAMETER">parent_table</replaceable></literal></term> <listitem> <para> This form adds the target table as a new child of the specified parent table. Subsequently, queries against the parent will include records of the target table. To be added as a child, the target table must already contain all the same columns as the parent (it could have additional columns, too). The columns must have matching data types, and if they have <literal>NOT NULL</literal> constraints in the parent then they must also have <literal>NOT NULL</literal> constraints in the child. </para> <para> There must also be matching child-table constraints for all <literal>CHECK</literal> constraints of the parent. Currently <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and <literal>FOREIGN KEY</literal> constraints are not considered, but this might change in the future. </para> </listitem> </varlistentry> <varlistentry> <term><literal>NO INHERIT <replaceable class="PARAMETER">parent_table</replaceable></literal></term> <listitem> <para> This form removes the target table from the list of children of the specified parent table. Queries against the parent table will no longer include records drawn from the target table. </para> </listitem> </varlistentry> <varlistentry> <term><literal>OWNER</literal></term> <listitem> <para> This form changes the owner of the table, sequence, or view to the specified user. </para> </listitem> </varlistentry> <varlistentry> <term><literal>SET TABLESPACE</literal></term> <listitem> <para> This form changes the table's tablespace to the specified tablespace and moves the data file(s) associated with the table to the new tablespace. Indexes on the table, if any, are not moved; but they can be moved separately with additional <literal>SET TABLESPACE</literal> commands. See also <xref linkend="SQL-CREATETABLESPACE" endterm="sql-createtablespace-title">. </para> </listitem> </varlistentry> <varlistentry> <term><literal>RENAME</literal></term> <listitem> <para> The <literal>RENAME</literal> forms change the name of a table (or an index, sequence, or view) or the name of an individual column in a table. There is no effect on the stored data. </para> </listitem> </varlistentry> <varlistentry> <term><literal>SET SCHEMA</literal></term> <listitem> <para> This form moves the table into another schema. Associated indexes, constraints, and sequences owned by table columns are moved as well. </para> </listitem> </varlistentry> </variablelist> </para> <para> All the actions except <literal>RENAME</literal> and <literal>SET SCHEMA</> can be combined into a list of multiple alterations to apply in parallel. For example, it is possible to add several columns and/or alter the type of several columns in a single command. This is particularly useful with large tables, since only one pass over the table need be made. </para> <para> You must own the table to use <command>ALTER TABLE</>. To change the schema of a table, you must also have <literal>CREATE</literal> privilege on the new schema. To add the table as a new child of a parent table, you must own the parent table as well. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have <literal>CREATE</literal> privilege on the table's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the table. However, a superuser can alter ownership of any table anyway.) </para> </refsect1> <refsect1> <title>Parameters</title> <variablelist> <varlistentry> <term><replaceable class="PARAMETER">name</replaceable></term> <listitem> <para> The name (possibly schema-qualified) of an existing table to alter. If <literal>ONLY</> is specified, only that table is altered. If <literal>ONLY</> is not specified, the table and all its descendant tables (if any) are updated. <literal>*</> can be appended to the table name to indicate that descendant tables are to be altered, but in the current version, this is the default behavior. (In releases before 7.1, <literal>ONLY</> was the default behavior. The default can be altered by changing the configuration parameter <xref linkend="guc-sql-inheritance">.) </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">column</replaceable></term> <listitem> <para> Name of a new or existing column. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">new_column</replaceable></term> <listitem> <para> New name for an existing column. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">new_name</replaceable></term> <listitem> <para> New name for the table. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">type</replaceable></term> <listitem> <para> Data type of the new column, or new data type for an existing column. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">table_constraint</replaceable></term> <listitem> <para> New table constraint for the table. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">constraint_name</replaceable></term> <listitem> <para> Name of an existing constraint to drop. </para> </listitem> </varlistentry> <varlistentry> <term><literal>CASCADE</literal></term> <listitem> <para> Automatically drop objects that depend on the dropped column or constraint (for example, views referencing the column). </para> </listitem> </varlistentry> <varlistentry> <term><literal>RESTRICT</literal></term> <listitem> <para> Refuse to drop the column or constraint if there are any dependent objects. This is the default behavior. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">trigger_name</replaceable></term> <listitem> <para> Name of a single trigger to disable or enable. </para> </listitem> </varlistentry> <varlistentry> <term><literal>ALL</literal></term> <listitem> <para> Disable or enable all triggers belonging to the table. (This requires superuser privilege if any of the triggers are for foreign key constraints.) </para> </listitem> </varlistentry> <varlistentry> <term><literal>USER</literal></term> <listitem> <para> Disable or enable all triggers belonging to the table except for foreign key constraint triggers. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">index_name</replaceable></term> <listitem> <para> The index name on which the table should be marked for clustering. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">storage_parameter</replaceable></term> <listitem> <para> The name of a table storage parameter. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">value</replaceable></term> <listitem> <para> The new value for a table storage parameter. This might be a number or a word depending on the parameter. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="PARAMETER">parent_table</replaceable></term> <listitem>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -