Easily Duplicate, Copy or Backup Tables in Oracle, PostgreSQL, DB2 and SQLite with Create Table As SQL簡単に重複し、オラクルのテーブルのバックアップコピーまたは、 PostgreSQLでテーブルを作成するとしてのDB2とSQLiteのSQL
In Oracle, PostgreSQL, DB2 and SQLite database system, there is a nice command feature called Create Table As which allows easy duplicating of a table with data from another or a few other tables. OracleでのPostgreSQL 、 SQLiteデータベースdb2およびシステム、ニースには、コマンドの機能と呼ばれるテーブルを作成これにより、テーブルにデータを簡単に複製またはごく少数の他のテーブルから別のです。 The SQL command can also be used to ‘copy and paste’ a table exactly or backup a table data before performing data manipulation query on the original table, just in case the script has error and the backup date can be used to restore to original state. Create Table As will creates a new table built from the content of dataset or result set retrieved by a Select SQL query from a table that already exists within the database. SQLコマンドに使用されることもできます。 'をコピーして貼り付け'を正確にテーブルまたはテーブルのデータをバックアップするデータの操作を実行する前にクエリを実行して元のテーブルは、念のために、スクリプトは、エラーが発生し、バックアップの日付を使用して元の状態に復元するです。 テーブルを作成する新しいテーブルを作成するに組み込まれたデータセットのコンテンツから結果セットを取得するかを選択し 、テーブルからSQLクエリを実行することが既に存在する場合に、データベースです。
The syntax of Create Table As SQL statement is:テーブルを作成するSQLステートメントの構文は:
CREATE TABLE table_name [ ( column_name [, ...] ) ]テーブルにインデックスを作成[ ( column_name [ 、 ... ] ) ]
AS select [ * !として選択し[ * ! ( column_name [, ...] ) ] FROM source_table_name ( column_name [ 、 ... ] ) ]からsource_table_name
Replace table_name with the name of the new table that will be created.インデックスの名前を置き換えると、新しいテーブルが作成されることです。 Column name is optional, where you can specify multiple columns by including their names in a comma-delimited list.カラム名は任意ですが、ここで指定することもできます自分の名前を含む複数のカラムを、カンマ区切りのリストです。 Else, the structure of the new table will be based on the column names, types and number of columns returned by the Select statement, together with the row data.ほか、新しいテーブルの構造をされるのカラム名に基づいて、種類とのカラム数を取得するには、 SELECTステートメントの行のデータと一緒にします。 If you specify the column name, note that there should be the same number of columns specified as are returned by select.カラム名を指定した場合、に注意して存在する必要がありますとして指定されるのと同じ数の列が返さを選択します。
The select statement at the end of create table as command must be valid, and has the number of targets selected matching the number of columns in the optional column list preceding the AS clause. SELECTステートメントの終わりにテーブルを作成する有効なコマンドをしなければならない、との目標には、数にマッチするのカラム数を選択し、オプションのカラムリストに先行し、として、節です。 It can be a complex select statement that retrieve data from multiple tables.それには、複雑なSELECTステートメントが複数のテーブルからデータを取得します。 If optional column list is specified within parentheses, asterisk (*) can no longer be used in the select statement.オプションのカラムリストを指定しない場合に括弧、アスタリスク( * )が使用されていることはできなくSELECTステートメントです。
For example,たとえば、
CREATE TABLE demo_backupテーブルを作成demo_backup
AS SELECT * FROM demo; *からデモとして選択;
Above SQL statement will create a exact replica backup table named demo_backup with data and structure (columns) of demo table.上記のSQLステートメントは、正確なレプリカを作成するdemo_backupという名前のテーブルにデータをバックアップと構造(カラム)のデモ表のとおりです。
Possible error if you specify the optional column list is:可能なエラーが発生列を指定する場合は、オプションのリストは:
ERROR: CREATE TABLE/AS SELECT has mismatched column countエラー:作成テーブル/としては、不適当な列数を選択
If you encounter this error message, this is due to optional list of columns in parentheses contains a different number of rows than the select statement returns.このエラーメッセージが表示さに遭遇したら、これはオプションのために列のリストを括弧内には、別の行数を戻り値よりも、 SELECTステートメントです。 Double check if the number of columns specified is the same with the results that are expected from the select resultset.ダブルチェックのカラム数を指定した場合は、同じし、その結果は、予想よりは、結果セットの選択です。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要 :これは、機械翻訳ページで提供"現状有姿"を保証します。 Machine translation may be difficult to understand.機械翻訳を理解するのは難しいかもしれません。 Please refer toを参照してください original English articleオリジナルの英語記事索引 whenever possible.いつ可能です。
Share and contribute or get technical support and help atを共有して貢献や技術サポートとヘルプを得る My Digital Life Forums 私のデジタルライフフォーラム .です。
Related Articles関連記事
- ORA-02449 Oracle Drop Table Errorエラーが発生OracleのドロップテーブルのOra - 02449
- Create New Table by Selecting Data from Other Tables with CREATE TABLE AS新しいテーブルの作成を選択し、他のテーブルからデータテーブルを作成する
- Oracle ORA-14074 Create or Add New Partition Fails ErrorオラクルのOra - 14074新しいパーティションを作成または追加に失敗するエラーが発生
- ORA-00942 Table or View Does Not Exist Oracle ErrorメールORA - 00942テーブルまたはビューが存在しない場合はOracleのエラーが発生
- Check Oracle Version Oracleのバージョンを確認
- Oracle ORA-01658 Unable to Create INITIAL Extent for Segment in Tablespace ErrorオラクルのOra - 01658の範囲の最初のセグメントを作成できない場合は、テーブルスペースのエラーが発生
- ORA-01502 Oracle Index in Unusable StateメールORA - 01502 Oracleのインデックスを使用不能な状態に
- Change Oracle Database User Password Oracleデータベースのユーザのパスワードを変更
- Insert Text Literal and Concatenation in Oracle SQLリテラルと連結のテキストを挿入オラクルのSQL
- How to Backup and Restore (Export and Import) MySQL Databases Tutorialどのようにバックアップと復元(エクスポートおよびインポート) MySQLデータベースのチュートリアル












