(8.0.22)
drop table tab22;
create table tab22(col1 int,col2 int);
create index ind22 on tab22(col2);
alter table tab22 add constraint tab22pk primary key(col1);
show create table tab22;
show create table tab22rename;
-- テーブル名の変更
alter table tab22 rename to tab22rename;
-- インデックス名の変更
alter table tab22rename rename index ind22 to ind22renae;
-- カラム名の変更
alter table tab22rename rename column col1 to col1renae;
-- 主キー制約名の変更
変更できない模様
インデックス名はテーブルに紐づく
(19c)
drop table tab22 purge;
create table tab22(col1 int,col2 int);
create index ind22 on tab22(col2);
alter table tab22 add constraint tab22pk primary key (col1) using index;
select table_name from user_tables where table_name like 'TAB22%';
select table_name,index_name from user_indexes where index_name like 'IND22%';
select table_name,column_name from user_tab_columns where table_name like 'TAB22%';
select table_name,constraint_name from user_constraints where table_name like 'TAB22%';
-- テーブル名の変更
alter table tab22 rename to tab22rename;
-- インデックス名の変更
alter index ind22 rename to ind22rename;
-- カラム名の変更
alter table tab22rename rename column col1 to col1rename;
-- 主キー制約名の変更
alter table tab22rename rename constraint tab22pk to tab22pkrename;
インデックス名はテーブルと同じ階層、主キー制約名はテーブルに紐づく
(13)
drop table tab22;
create table tab22(col1 int,col2 int);
create index ind22 on tab22(col2);
alter table tab22 add constraint tab22pk primary key(col1);
\d tab22*
-- テーブル名の変更
alter table tab22 rename to tab22rename;
-- インデックス名の変更
alter index ind22 rename to ind22rename;
-- カラム名の変更
alter table tab22rename rename column col1 to col1rename;
-- 主キー制約名の変更
alter table tab22rename rename constraint tab22pk to tab22pkrename;
インデックス名はテーブルと同じ階層、主キー制約名はテーブルに紐づく
drop table tab22;
create table tab22(col1 int not null,col2 int);
create nonclustered index ind22 on tab22 (col2);
alter table tab22 add constraint tab22pk primary key(col1);
select * from sys.tables
where name like 'tab22%';
select object_name(object_id) object_name,* from sys.indexes
where object_name(object_id) like 'tab22%';
select object_name(object_id) object_name,* from sys.columns
where object_name(object_id) like 'tab22%';
select object_name(object_id) object_name, * from sys.objects
where type in ('C','F','PK')
and object_name(object_id) like 'tab22pk%';
-- テーブル名の変更
EXEC sp_rename 'dbo.tab22', 'tab22rename', 'OBJECT';
-- インデックス名の変更
EXEC sp_rename 'dbo.tab22rename.ind22', 'ind22rename', 'INDEX';
-- カラム名の変更
EXEC sp_rename 'dbo.tab22rename.col1', 'col1rename', 'COLUMN';
-- 主キー制約名の変更
EXEC sp_rename 'dbo.tab22pk', 'tab22pkrename', 'OBJECT';
インデックス名はテーブルに紐づく、主キー制約名はテーブルと同じ階層