Click to See Complete Forum and Search --> : Primary Keys Issue on Remote Tables


shsh_shah
03-24-2006, 11:09 AM
have this query where i can check what are the primary keys on remote table.

select column_name from all_cons_columns where table_name='EMPLOYEES' and owner='BRENDAN';
COLUMNS_NAME
*************************
EMPLOYEE_ID

Now Question is

1. When we do copy tables does that also copy Primary keys because when i run the same query after copying tables it does not show any rows e,g,

select column_name from all_cons_columns where table_name='EMPLOYEES_COPY' and owner='TEST'

2. When we do copy does that also copy constraints?

Any help will be really appreciated.

slimdave
03-24-2006, 11:33 AM
It woulddepend how you "copy". Export/Import will be default, though it has options not to. So how did you do the copy?

shsh_shah
03-24-2006, 12:21 PM
By doing
Create Table <newTableName> as select * from
<oldTableName> [where 1 = 2 -- optional]
Now need to copy constraints but i cannot edit remote tables or i cannot apply Triggers or views on those tables. So any other way around

slimdave
03-24-2006, 02:45 PM
You can create a table, but you can't create triggers or constraints on it, or create views?

shsh_shah
03-24-2006, 03:56 PM
Sorry look like u took me wrong...
I can only view the contents of that schema and can make copies of his schema structure thats all.

WilliamR
03-24-2006, 07:46 PM
Now Question is

1. When we do copy tables does that also copy Primary keys
2. When we do copy does that also copy constraints?
No, and no.

shsh_shah
03-24-2006, 11:28 PM
hmmm....William you just said no and no...But can you give me idea how to do it..Help from any bosy will be really appreciated

WilliamR
03-25-2006, 11:37 AM
Try

DBMS_METADATA.GET_DDL (http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1019414)@remotedb(objecttype, name);

e.g.

DBMS_METADATA.GET_DDL@remotedb('TABLE','EMPLOYEES');

This is a function that you can use in either a plain SQL query or in PL/SQL. It will return the SQL to create the table, including constraints.