`

Renaming Columns And Constraints

SQL 
阅读更多
n addition to renaming tables and indexes Oracle9i Release 2 allows the renaming of columns and constraints on tables. In this example once the the TEST1 table is created it is renamed along with it's columns, primary key constraint and the index that supports the primary key:

    SQL> CREATE TABLE test1 (
      2    col1  NUMBER(10) NOT NULL,
      3    col2  VARCHAR2(50) NOT NULL);

    Table created.

    SQL> ALTER TABLE test1 ADD (
      2    CONSTRAINT test1_pk PRIMARY KEY (col1));

    Table altered.

    SQL> DESC test1
     Name                 Null?    Type
     -------------------- -------- --------------------
     COL1                 NOT NULL NUMBER(10)
     COL2                 NOT NULL VARCHAR2(50)

    SQL> SELECT constraint_name
      2  FROM   user_constraints
      3  WHERE  table_name      = 'TEST1'
      4  AND    constraint_type = 'P';

    CONSTRAINT_NAME
    ------------------------------
    TEST1_PK

    1 row selected.

    SQL> SELECT index_name, column_name
      2  FROM   user_ind_columns
      3  WHERE  table_name = 'TEST1';

    INDEX_NAME            COLUMN_NAME
    --------------------  --------------------
    TEST1_PK              COL1

    1 row selected.

    SQL> -- Rename the table, columns, primary key
    SQL> -- and supporting index.
    SQL> ALTER TABLE test1 RENAME TO test;

    Table altered.

    SQL> ALTER TABLE test RENAME COLUMN col1 TO id;

    Table altered.

    SQL> ALTER TABLE test RENAME COLUMN col2 TO description;

    Table altered.

    SQL> ALTER TABLE test RENAME CONSTRAINT test1_pk TO test_pk;

    Table altered.

    SQL> ALTER INDEX test1_pk RENAME TO test_pk;

    Index altered.

    SQL> DESC test
     Name                 Null?    Type
     -------------------- -------- --------------------
     ID                   NOT NULL NUMBER(10)
     DESCRIPTION          NOT NULL VARCHAR2(50)

    SQL> SELECT constraint_name
      2  FROM   user_constraints
      3  WHERE  table_name      = 'TEST'
      4  AND    constraint_type = 'P';

    CONSTRAINT_NAME
    --------------------
    TEST_PK

    1 row selected.

    SQL> SELECT index_name, column_name
      2  FROM   user_ind_columns
      3  WHERE  table_name = 'TEST';

    INDEX_NAME            COLUMN_NAME
    --------------------  --------------------
    TEST_PK               ID

    1 row selected.
分享到:
评论

相关推荐

    Renaming_a_workspace-_dsp_and_dsw.rar_dsw_renaming workspace_vc6

    Renaming a workspace - _dsp and _dsw 对VC6工程文件重命名

    Spectral Core Full Convert Enterprise v6.11.0.1683

    Best fit columns and Auto-height rows In-place image and BLOB viewing Selected rows deletion Jump to specific record Built-in table Print Preview and Print Table Customization Table customization ...

    NodeJS---Renaming-and-Removing-Directories

    NodeJS-重命名和删除目录

    MP3 Book Helper

    This program provides rapid Mp3 (ID3v1, ID3v2) and Ogg Vorbis tags editing and file renaming functions. Mass Tag editing is done using special variables and Regular Expressions. Undo and preview for ...

    SQL Assistant v5.0

    New Code Analysis and Refactoring Functions - smart object, column, and parameter renaming methods; smart code extraction methods; advanced code dependencies analysis Graphical analysis of ...

    Core中的RENAMING解析1

    并且RRAT的写端口数量和提交宽度相同RENAMING的构造函数初始化参数,创建对象,计算各个对象的面积,并且得到整体的面积参数RENAMINGU::RENAM

    Linux Shell Scripting Cookbook

    Renaming and moving files in bulk 86 Spell checking and dictionary manipulation 89 Automating interactive input 90 Chapter 3: File In, File Out 95 Introduction 96 Generating files of any size 96 ...

    Professional.Git.epub

    Connected Lab 7: Deleting, Renaming, and Stashing Chapter 12: Understanding Remotes—Branches and Operations Connected Lab 8: Setting Up a GitHub Account and Cloning a Repository Chapter 13: ...

    Rename Master v3.12 - 文件批量重命名工具

    This utility will add, remove, or replace parts of the filename with ease and also supports renaming via file properties, MP3 tags, JPEG JFIF and EXIF tags, Video tags, and text files. Batch renaming ...

    XnView免安装版

    It comes with built-in hex inspection, batch renaming and screen capture tools. It is licensed as freeware for private, educational and non-profit uses. For other uses, it is licensed as commercial ...

    ObfuscatorProv3.3.zip

    Your source code gets so entangled through renaming, random code and string obfuscation, that no one can get your original code. Obfuscator Pro is the only Unity3d Obfuscator that considers ...

    Pandas Cookbook 2017 pdf 2分

    Renaming row and column names Getting ready How to do it... How it works... There's more... Creating and deleting columns Getting ready How to do it... How it works... There's more... See also 2. ...

    水印制作工具 专业版 破解

    PhotoWatermark Professional supports a combination of batch watermarking, cropping, converting, resizing, renaming and framing. Integrated how-to tips encourages you to start watermarking in no time!

    Linux for Beginners: An Introduction to the Linux Operating System

    Creating, renaming, moving, and deleting directories. Listing, reading, creating, editing, copying, and deleting files. Exactly how permissions work and how to decipher the most cryptic Linux ...

    unity Obfuscator Pro 3.3.zip

    Obfuscator Pro features reachs from simple renaming: – Namespaces – Classes (also MonoBehaviour and NetworkBehaviour) – Fields – Propertys – Events – Methods Up to Method content obfuscation ...

    simple_renaming_panel:Blender的简单重命名插件

    文档: : 介绍 “简单重命名面板”是一种小型但功能强大的工具,可一次重命名更多对象。 该工具包括添加后缀,前缀,搜索和替换,根据对象类型添加后缀等基本功能。 随着时间的流逝,添加了诸如变量系统之类的更高级...

    SQLMemTable for Delphi / C++ Builder

    comprehensive help and demos.SQLMemTable provides the following services: - SQL support - Master / detail relationship - Creating, renaming, emptying, deleting and restructuring tables - Creating, ...

    oracle views 10g

    The V$ views that have been changed in Oracle Database 10g are identified by the symbol “(*)” after the name of each view (a change is the addition, renaming or deletion of columns). Also, there is...

    Active Directory Cookbook, 3rd Edition.pdf

    Covers all aspects of managing user objects, including creating, renaming, moving, resetting passwords, unlocking, modifying the profile attributes, and locating users that have certain criteria (e.g....

Global site tag (gtag.js) - Google Analytics