SlideShare uma empresa Scribd logo
1 de 1
Baixar para ler offline
Renaming a Table                                                                Administration Tips




Renaming a Table

The basic command to do this is:

ALTER TABLE SCHEMA.TABLE_NAME RENAME TO SCHEMA.NEW_TABLE_NAME;


That command is guaranteed to work only in Oracle 8i and 9i -you'll have to experiment to
see if it works on 8.0 or earlier versions.

Issuing this command does not invalidate any indexes, constraints or permissions granted
on the original table.

For example, if Fred has been granted select privileges on the EMP table, and the EMP
table is then renamed to be EMPLOYEES, Fred will now be able to select from EMPLOYEES
without further grants being needed.

Whilst indexes and constraints are all still valid and useable after a table is renamed, they
retain their original names. For example, if you created a constraint called EMP_ID_PK, it
will still be called that, even though it is now a constraint on the EMPLOYEES table.
Similarly, an index called EMP_PK retains that name, regardless of the fact that the table
it is an index of has changed its name.

You might therefore want to issue the command:

ALTER INDEX SCOTT.EMP_PK RENAME TO SCOTT.EMPLOYEES_PK;


However, there is no rename command for constraints, and hence they must retain their
original names, unless you drop them and re-create them.

Finally, renaming a table means performing DDL on a table -and performing DDL to any
table renders all procedures, packages and triggers that reference the table invalid. You
can check that by looking at the STATUS column of the DBA_OBJECTS view. All invalid
packages, procedures and triggers are automatically recompiled the first time they are
called after their invalidation (subject to some provisos), but you can also manually
recompile them if you wish: ALTER TRIGGER BLAH COMPILE;, for example.

Incidentally, if you query DBA_TRIGGERS (as an example), you can see the code making up
a particular trigger (in the TRIGGER_BODY column) -and you'll discover that what was once
typed in as 'create trigger blah before update on emp' automatically gets re-jigged by
Oracle to read '...update on employees'. The rename command therefore even re-writes
your code for you, which is nice!




Copyright © Howard Rogers 2001            10/17/2001                                     Page 1 of 1

Mais conteúdo relacionado

Mais procurados

Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sqlSushil Mishra
 
Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql databaseKimera Richard
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Vidyasagar Mundroy
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 12
Oracle - Program with PL/SQL - Lession 12Oracle - Program with PL/SQL - Lession 12
Oracle - Program with PL/SQL - Lession 12Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Thuan Nguyen
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql SyntaxReka
 
Prabu's sql quries
Prabu's sql quries Prabu's sql quries
Prabu's sql quries Prabu Cse
 
Oracle - Program with PL/SQL - Lession 15
Oracle - Program with PL/SQL - Lession 15Oracle - Program with PL/SQL - Lession 15
Oracle - Program with PL/SQL - Lession 15Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 14
Oracle - Program with PL/SQL - Lession 14Oracle - Program with PL/SQL - Lession 14
Oracle - Program with PL/SQL - Lession 14Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 18
Oracle - Program with PL/SQL - Lession 18Oracle - Program with PL/SQL - Lession 18
Oracle - Program with PL/SQL - Lession 18Thuan Nguyen
 

Mais procurados (20)

Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
 
Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql database
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Oracle - Program with PL/SQL - Lession 12
Oracle - Program with PL/SQL - Lession 12Oracle - Program with PL/SQL - Lession 12
Oracle - Program with PL/SQL - Lession 12
 
Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17
 
Les13
Les13Les13
Les13
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql Syntax
 
Prabu's sql quries
Prabu's sql quries Prabu's sql quries
Prabu's sql quries
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Triggers
TriggersTriggers
Triggers
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Oracle - Program with PL/SQL - Lession 15
Oracle - Program with PL/SQL - Lession 15Oracle - Program with PL/SQL - Lession 15
Oracle - Program with PL/SQL - Lession 15
 
Lab5 sub query
Lab5   sub queryLab5   sub query
Lab5 sub query
 
Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13
 
Oracle - Program with PL/SQL - Lession 14
Oracle - Program with PL/SQL - Lession 14Oracle - Program with PL/SQL - Lession 14
Oracle - Program with PL/SQL - Lession 14
 
Oracle - Program with PL/SQL - Lession 18
Oracle - Program with PL/SQL - Lession 18Oracle - Program with PL/SQL - Lession 18
Oracle - Program with PL/SQL - Lession 18
 

Destaque (7)

Rollbackblocking
RollbackblockingRollbackblocking
Rollbackblocking
 
Userlimit
UserlimitUserlimit
Userlimit
 
Sequencereset
SequenceresetSequencereset
Sequencereset
 
Rollbacksizes
RollbacksizesRollbacksizes
Rollbacksizes
 
Rollbackshrinks
RollbackshrinksRollbackshrinks
Rollbackshrinks
 
Undo internalspresentation
Undo internalspresentationUndo internalspresentation
Undo internalspresentation
 
Usertracing
UsertracingUsertracing
Usertracing
 

Semelhante a Tablerename

Data Definition Language (DDL)
Data Definition Language (DDL) Data Definition Language (DDL)
Data Definition Language (DDL) Mohd Tousif
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functionsfarwa waqar
 
Creating a database
Creating a databaseCreating a database
Creating a databaseRahul Gupta
 
Mca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementMca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementRai University
 
SQL Database Performance Tuning for Developers
SQL Database Performance Tuning for DevelopersSQL Database Performance Tuning for Developers
SQL Database Performance Tuning for DevelopersBRIJESH KUMAR
 
Mysqlppt
MysqlpptMysqlppt
MysqlpptReka
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxPetroJoe
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3Belal Arfa
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptxSiddhantBhardwaj26
 

Semelhante a Tablerename (20)

Columnrename
ColumnrenameColumnrename
Columnrename
 
Data Definition Language (DDL)
Data Definition Language (DDL) Data Definition Language (DDL)
Data Definition Language (DDL)
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Sql rename
Sql renameSql rename
Sql rename
 
Oracle
OracleOracle
Oracle
 
Creating a database
Creating a databaseCreating a database
Creating a database
 
Ijetr012023
Ijetr012023Ijetr012023
Ijetr012023
 
Mca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementMca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction management
 
unit-5 sql notes.docx
unit-5 sql notes.docxunit-5 sql notes.docx
unit-5 sql notes.docx
 
SQL
SQLSQL
SQL
 
8. sql
8. sql8. sql
8. sql
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql
SqlSql
Sql
 
SQL Database Performance Tuning for Developers
SQL Database Performance Tuning for DevelopersSQL Database Performance Tuning for Developers
SQL Database Performance Tuning for Developers
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptx
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 

Mais de oracle documents (20)

Applyinga blockcentricapproachtotuning
Applyinga blockcentricapproachtotuningApplyinga blockcentricapproachtotuning
Applyinga blockcentricapproachtotuning
 
Windowsosauthent
WindowsosauthentWindowsosauthent
Windowsosauthent
 
Whatistnsnames
WhatistnsnamesWhatistnsnames
Whatistnsnames
 
Whatisadatabaselink
WhatisadatabaselinkWhatisadatabaselink
Whatisadatabaselink
 
Varraysandnestedtables
VarraysandnestedtablesVarraysandnestedtables
Varraysandnestedtables
 
Userpasswrd
UserpasswrdUserpasswrd
Userpasswrd
 
Undo internals paper
Undo internals paperUndo internals paper
Undo internals paper
 
Tablespacelmt
TablespacelmtTablespacelmt
Tablespacelmt
 
Sql scripting sorcerypresentation
Sql scripting sorcerypresentationSql scripting sorcerypresentation
Sql scripting sorcerypresentation
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
Sql for dbaspresentation
Sql for dbaspresentationSql for dbaspresentation
Sql for dbaspresentation
 
Rollbacklmt
RollbacklmtRollbacklmt
Rollbacklmt
 
Rollback1555s
Rollback1555sRollback1555s
Rollback1555s
 
Redosize
RedosizeRedosize
Redosize
 
Real liferecoverypresentation
Real liferecoverypresentationReal liferecoverypresentation
Real liferecoverypresentation
 
Real liferecoverypaper
Real liferecoverypaperReal liferecoverypaper
Real liferecoverypaper
 
Perfstats
PerfstatsPerfstats
Perfstats
 
Oracledates
OracledatesOracledates
Oracledates
 
Ora12154
Ora12154Ora12154
Ora12154
 
Nologging
NologgingNologging
Nologging
 

Tablerename

  • 1. Renaming a Table Administration Tips Renaming a Table The basic command to do this is: ALTER TABLE SCHEMA.TABLE_NAME RENAME TO SCHEMA.NEW_TABLE_NAME; That command is guaranteed to work only in Oracle 8i and 9i -you'll have to experiment to see if it works on 8.0 or earlier versions. Issuing this command does not invalidate any indexes, constraints or permissions granted on the original table. For example, if Fred has been granted select privileges on the EMP table, and the EMP table is then renamed to be EMPLOYEES, Fred will now be able to select from EMPLOYEES without further grants being needed. Whilst indexes and constraints are all still valid and useable after a table is renamed, they retain their original names. For example, if you created a constraint called EMP_ID_PK, it will still be called that, even though it is now a constraint on the EMPLOYEES table. Similarly, an index called EMP_PK retains that name, regardless of the fact that the table it is an index of has changed its name. You might therefore want to issue the command: ALTER INDEX SCOTT.EMP_PK RENAME TO SCOTT.EMPLOYEES_PK; However, there is no rename command for constraints, and hence they must retain their original names, unless you drop them and re-create them. Finally, renaming a table means performing DDL on a table -and performing DDL to any table renders all procedures, packages and triggers that reference the table invalid. You can check that by looking at the STATUS column of the DBA_OBJECTS view. All invalid packages, procedures and triggers are automatically recompiled the first time they are called after their invalidation (subject to some provisos), but you can also manually recompile them if you wish: ALTER TRIGGER BLAH COMPILE;, for example. Incidentally, if you query DBA_TRIGGERS (as an example), you can see the code making up a particular trigger (in the TRIGGER_BODY column) -and you'll discover that what was once typed in as 'create trigger blah before update on emp' automatically gets re-jigged by Oracle to read '...update on employees'. The rename command therefore even re-writes your code for you, which is nice! Copyright © Howard Rogers 2001 10/17/2001 Page 1 of 1