Copy table including constraints.. Same DB..

Looking to find a way to copy a table, and to include all constraints over to the new table..
right now I use..
create table cust as select * from customers
How can I amend that statement to include constraints..
Thanks...

To answer your question as far as I know it is not possible using CTAS but if you want to create a table only along with the constraints and other information
search for dbms_metadata package in the oracle reference manual.
Hope this helps.
Regards
Raj
Edited by: R.Subramanian on Oct 30, 2008 9:26 AM

Similar Messages

  • Create table from another table including constraints

    Hi,
    Is there a way to create a table from another table including constraints.
    CREATE TABLE COPY_EMP
    as
    SELECT *
    FROM EMP
    WHERE 1 =2 ;
    This creates the table, but the constraints are not copied over.
    I was reading about DBMS_REDEFINITION - can that be used for this scenario ?
    Thanks!
    Anand

    >
    I tried that, but the constraint names are posing a problem. And unfortunately our constraints are not named in a standard, so am finding it difficult to replace them.
    Was just wondering if there were any simpler approach to this.
    >
    No - there isn't.
    You will have to use new names for the constraints. That usually means extracting the DDL and manually changing the constraint names.

  • How do I duplicate or copy a table onto the same page?

    In Pages, how do I duplicate or copy a table onto the same page?

    option drag duplicates anything or copy and paste
    Peter

  • SQL error msg - The DELETE statement conflicted with the SAME TABLE REFERENCE constraint

    Executed as user: ****. The DELETE statement
    conflicted with the SAME TABLE REFERENCE constraint "FK_PARENT_TASK_REF".
    The conflict occurred in database "****", table "****", column
    'PARENT_TASK_ID'. [SQLSTATE 23000] (Error 547) The statement has been
    terminated. [SQLSTATE 01000] (Error 3621). The step failed.
    Does this error msg indicate the whole script failed to execute or was it just a single step/task that failed ?
    What does error msg mean ?
    Anyway to prevent this error msg and ensure script runs successfully

    Hi mdavidh,
    This error occurs because the record  'PARENT_TASK_ID' was referenced by 'FK_PARENT_TASK_REF'.
    Please refer below codes:
    CREATE TABLE MyTable (
    ID INT, primary key(ID), -- primary key
    ID_Parent INT foreign key(ID_Parent) references MyTable(ID), -- foreign key reference the same table
    insert into MyTable(ID,ID_Parent)
    values(0,0);
    insert into MyTable(ID,ID_Parent)
    values(1,0);
    insert into MyTable(ID,ID_Parent)
    values(2,0);
    insert into MyTable(ID,ID_Parent)
    values(3,1);
    insert into MyTable(ID,ID_Parent)
    values(4,3);
    insert into MyTable(ID,ID_Parent)
    values(5,4);
    CREATE TRIGGER MyTrigger
    on MyTable
    instead of delete
    as
    set nocount on
    update MyTable set ID_Parent = null where ID_Parent in (select ID from deleted)
    delete from MyTable where ID in (select ID from deleted)
    Now we could delete records.
    delete from MyTable where ID_Parent=0
    Thanks,
    Candy Zhou

  • Copy tables between two different computer?

    Hi experts,
    I don't know if is this the correct place to make this question, but I need help with independent tables. Is it possible to copy independent tables to one 6.0 computer to other computer with the same version 6.0?
    Thanks in advance for your answers,
    Best Regards,
    Rebeca

    > We want to copy independent tables from one system in 6.0 to another system in 6.0. We have system A (that was in 4.7 and now is in 6.0) with data relative to Spain and another system, system 2,  that is also in 6.0 with data from other countries. In system B we have a particular mandant for Spain and the problem is that we want to include all the independent tables information from system A to system B and we don't know how to do that... is there anyway that we can do this?
    There is no standard way of putting data of two systems to one system together. It's not just copying tables around (many HR tables are cluster tables and can't be read through SQL without a logic on top) but also speaking of dependent things.
    The only supported way of doing such things is booking an SLO service and let SAP assist you in doing it. Only then you can be sure that it works as expected. But don't underestimate the whole thing. Check
    http://service.sap.com/slo
    --> Consolidate and unite system landscapes
    --> Optimization for HCM
    SAP has the tools and the knowledge to do such things and you can be sure it works. I would not do it on my own by copying tables (most HR tables are client dependent, you'd have to map client numbers, plants, adapt T512W and all that stuff manually).
    Markus

  • Copy table xmltype column

    A collegue just asked me the following:
    He wants to copy data from one database table to the same table on another database. The table has a XMLTYPE column. Is there a way other than export/import to copy the table to a file including XML-Values and Insert from the file to the target table?
    Export/Import seems the correct approach to me, however he doesn't have neccessary rights to do so. Do you know any easy other way?

    Why not use a DB link?
    XMLTypes can be copied through DB links:
    SQL> create table t as select * from t@dev1;
    Table created.
    SQL> select table_name, column_name, data_type from user_tab_cols where table_name = 'T';
    TABLE_NAME                     COLUMN_NAME                    DATA_TYPE
    T                              X                              XMLTYPE
    T                              SYS_NC00002$                   CLOB

  • Copying tables between schema owners

    In Timesten, can you copy tables across schemas/owners?
    i.e. OWNER_A.TABLE_Y to OWNER_B.TABLE_Y
    Where TABLE_Y has the same definition? Basically, I'd like to be able to backup one datastore and restore it in another datastore that has the same table definitions, but may have a different owner name.
    Thanks,
    Larry

    I'm not completely clear on exactly what you are looking to do. On one hand you ask about copying tables between schemas. This is easily done:
    CREATE TABLE OWNER_B.TABLE_Y AS SELECT * FROM OWNER_A.TABLE_Y;
    This only works for TimesTen tables that are not part of a cache group; specifically the source table can be part of a cache group but the target table cannot. if the target table is part of a cache group then you need to:
    1. Create the cache group containing the target (cached) table.
    2. INSERT INTO OWNER_B.TABLE_Y SELECT * FROM OWNER_A.TABLE_Y;
    But then you mention backup and restore. Since TimesTen backup/retore (ttBackup/ttRestore) works at a physical level you cannot rename/copy tables as part of that. You might be able to use ttMigrate with the -rename oldOwner:newOwner option but there are some constraints around this (one being that PL/SQL cannot be enabled in the database).
    Chris

  • Adding formula to a cell that is in another table in the same document

    Hi there.
    I am new to iwork and i have a question.
    I created a document in pages and i added diffent tables in the same document.
    The question is how can add a formula to a cell include cells that are on different tables?
    Thanks

    Not possible in Pages, only in Numbers.
    You will need to have just one table and have the references internal.
    You can make it look like separate tables by hiding cell borders etc inbetween, if that is necessary.
    Peter

  • Word 2010 table sytles / copying tables

    When I copy a table from one document to another the formatting does not stay the same.
    I think the problem is that the copied table adopts the paragraph style being used in the destination document. I have tried to create a table style within the destination document but when I apply the style to the table it does not change the formatting.
    The only workaround that I can think of is to create a paragraph style for the table cells and apply this to the table after it has been pasted in.
    Are there any other suggestions?
    Thanks!

    Hi nivlektech,
    Based on my understanding, you want to keep the format of table when copied to another document.
    To resolve this issue, you can choose Paste Special from Home > Clipboard > Paste Option > Keep source formatting. It preserves all original formatting of the pasted selection.
    There is an article about Paste option, hope it’s helpful.
    http://support.microsoft.com/kb/291358
    If there is anything I can do for you regarding this issue, feel free to post back.
    Best regards,
    Greta Ge
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • How can I copy tables from Numbers to Pages without formula?

    hi everyone
    i need help
    How can I copy tables from Numbers to Pages without formula in the cells?

    Ok... I see your problem... when pasting into Pages, the formulas from Numbers are included. Perhaps this is really more of a Pages question (in which case I'm far from expert). A couple of ideas:
    • In Pages, try "Edit"/"Paste and Match Style", which may insert tab delimited cell values (no formulas). Then, if you want the table format back, select these newly pasted tabbed values and use Page's "Format"/"Table"/"Convert Text to Table"/
    • In Numbers, before copying, make a temporary table of the plain values first, then copy and paste that into Pages. To do this, select the range of cells you desire in the Numbers and "Edit"/"Copy". Then "Edit"/"Deselect All" and "Edit"/"Paste Values" and "Edit"/"Cut". Now just a table of values is on the clipboard and you can head over to Pages to paste.

  • Copy table from one database to another database

    Hi,
    I am new to SQL and I have a question on copying a table.
    QUE: copy one table with huge data(around 60millions of rows) from one database to another database(have to create a new table) in the same server. 

    Hi ,
    By mistake ,I understood you want to copy on different server .
    I have rectify above.On same server we can copy Table in many way ;
    As I mentioned Above you can use ;
    select * into [Destination Database].[dbo].[NewTableName] from [SourceDatabase].[dbo].[Category]
    Second;
    select * into [Destination Database].[dbo].[NewTableName] from [SourceDatabase].[dbo].[Category] Where 1=2
    Insert into [Destination Database].[dbo].[NewTableName]
    select * from [SourceDatabase].[dbo].[Category]
    Thanks

  • ODP OracleCommandBuilder. Updating a table including DATE columns.

    Hi
    I have a problem with the OracleCommandBuilder not creating the correct update commands when I have DATE type columns in the table.
    I have created a test table (called DATETEST) with three columns:
    STRINGCOLUMN     VARCHAR2 10
    DATECOLUMN DATE
    NUMBERCOLUMN     NUMBER
    The STRINGCOLUMN is the primary key.
    Then I created a typed dataset that looks like this:
    STRINGCOLUMN     string
    DATECOLUMN string
    NUMBERCOLUMN     long
    This is the XML schema for the typed dataset:
    <?xml version="1.0" encoding="utf-8" ?>
    <xs:schema id="DateDS" targetNamespace="http://tempuri.org/DateDS.xsd" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns="http://tempuri.org/DateDS.xsd" xmlns:mstns="http://tempuri.org/DateDS.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
         <xs:element name="DateDS" msdata:IsDataSet="true">
              <xs:complexType>
                   <xs:choice maxOccurs="unbounded">
                        <xs:element name="DATETEST">
                             <xs:complexType>
                                  <xs:sequence>
                                       <xs:element name="DATECOLUMN" type="xs:string" minOccurs="0" />
                                       <xs:element name="STRINGCOLUMN" type="xs:string" minOccurs="0" />
                                       <xs:element name="NUMBERCOLUMN" type="xs:long" minOccurs="0" />
                                  </xs:sequence>
                             </xs:complexType>
                        </xs:element>
                   </xs:choice>
              </xs:complexType>
         </xs:element>
    </xs:schema>
    And this is the test code:
    Dim connection As Oracle.DataAccess.Client.OracleConnection
    Dim adapter As New Oracle.DataAccess.Client.OracleDataAdapter()
    Dim dbCommand As New Oracle.DataAccess.Client.OracleCommand()
    Dim sqlstring As String
    Dim data As New DateDS() 'Typed dataset
    Const ConnectionString As String = "User Id=............."
    Try
    'Connect to database
    connection = New OracleConnection(ConnectionString)
    connection.Open()
    'Get data from table DATETEST
    dbCommand.CommandText = "SELECT STRINGCOLUMN, TO_CHAR(DATECOLUMN) AS DATECOLUMN, NUMBERCOLUMN FROM DATETEST"
    dbCommand.Connection = connection
    adapter.SelectCommand = dbCommand
    adapter.Fill(data, "DATETEST")
    'Make changes to dataset
    data.DATETEST(0).DATECOLUMN = Now()
    data.DATETEST(0).NUMBERCOLUMN = data.DATETEST(0).NUMBERCOLUMN + 1
    'Update database
    sqlstring = "SELECT * FROM DATETEST"
    adapter.SelectCommand = New OracleCommand(sqlstring, connection)
    Dim custCB As New Oracle.DataAccess.Client.OracleCommandBuilder()
    custCB.DataAdapter = adapter
    adapter.Update(data, "DATETEST")
    'Disconnect
    connection.Close()
    connection.Dispose()
    Catch exc As Exception
    MessageBox.Show(exc.Message)
    End Try
    Getting the data from the database is not a problem.
    The dataset contains the correct information.
    But updating the database is impossible.
    I get errors like:
    ORA-01861: literal does not match format string
    And if I don't specify a DATE format in the TO_CHAR statement I get this error:
    Concurrency violation: the UpdateCommand affected 0 records.
    I think I've tried everything.
    I've used the OracleGlobalization class, with the SetSessionInfo method.
    I've tried all different types of date conversions to make sure that
    the date format on the database is the same as in the dataset.
    I've tried to change the NLS parameters on the DB server and in the registry on the client.
    I've tried to change the DATECOLUMN type in the typed dataset from string to Oracle.DataAccess.Types.OracleDate
    But it still doesn't work.
    The default date format on the DB 9i server is AMERICAN,(DD-MON-RR).
    A strange thing is that when I instead of using the ODP classes use
    the System.Data.OracleClient and its OracleCommandBuilder
    the code works perfectly without any errors.
    This is the test code that works:
    Dim connection As System.Data.OracleClient.OracleConnection
    Dim adapter As New System.Data.OracleClient.OracleDataAdapter()
    Dim dbCommand As New System.Data.OracleClient.OracleCommand()
    Dim data As New DateDS()
    Dim sqlstring As String
    Const ConnectionString As String = "User Id=......."
    Try
    'Connect to database
    connection = New System.Data.OracleClient.OracleConnection(ConnectionString)
    connection.Open()
    'Get data from table DATETEST
    dbCommand.CommandText = "SELECT STRINGCOLUMN, TO_CHAR(DATECOLUMN,'YYYY-MM-DD HH24:MI:SS') AS DATECOLUMN, NUMBERCOLUMN FROM DATETEST"
    dbCommand.Connection = connection
    adapter.SelectCommand = dbCommand
    adapter.Fill(data, "DATETEST")
    'Make changes to dataset
    data.DATETEST(0).DATECOLUMN = Now()
    data.DATETEST(0).NUMBERCOLUMN = data.DATETEST(0).NUMBERCOLUMN + 1
    'Update database
    sqlstring = "SELECT * FROM DATETEST"
    adapter.SelectCommand = New System.Data.OracleClient.OracleCommand(sqlstring, connection)
    Dim custCB As New System.Data.OracleClient.OracleCommandBuilder()
    custCB.DataAdapter = adapter
    adapter.Update(data, "DATETEST")
    'Disconnect
    connection.Close()
    connection.Dispose()
    Catch exc As Exception
    MessageBox.Show(exc.Message)
    End Try
    My experience until this came up is that the ODP provider is better on everything
    than the microsoft Oracle provider so I don't want to switch unless I have to.
    Could someone that have used the ODP OracleCommandBuilder for updating a table including DATE columns with a typed dataset please give me some tips on how to make this work?
    I would be the happiest man on earth if someone had a solution :-)
    Erik

    Don't convert the dates to strings. Ever.
    The command builder uses the metadata returned from the select command to build the insert/update commands. Using to_char in the query tells ODP that that is a varchar2 column. If you omit the to_char the commandBuilder will know to bind a date parameter in that spot.
    Also in your typed dataset you should change the type from a string to a date.
    David

  • How to copy tables between diff data source ?

    if copy tables in same datasource, the problem is easy , just
    CREATE TABLE DESTDB.TABLE as select * from SOURCEDB.TABLE
    but in diff data source, such as copy access table to a non-exsit oracle table,
    need to create the target table first . my problem is how to create the target table by source table structure. though the source table structure can be read out, but parse it and make the SQL statement to create the table is a tough job.
    anyone have good idea ??
    thanks.

    You are explaining a huge topic in simple terms.
    You are trying to do Database Migration from MS-Access to Oracle. It's not all that easy. But if you are restricting to creating few tables then, do a small exercise.
    1. Use ResultSetMetaData to get the no of coluns and their data types.
    2. Construct a create statement by using above information.
    3. Then query the table1 for all the records and insert those records into created table.
    Sudha

  • Copy standard include to z include

    I have copied the include  into   LYMCB3_1I01
    Now i want to add some cl=ode here but where i have to add the code there enhancement Section already exist...
    Now when i try to add any code it gives me enhancement creation message and when i tried to create it it asks for
    : enhancement spot , text , package (Must be standard ) , request ......
    Though it doesnt allow me to create it

    That means you have not specified the parameter name to which the selected value will be returned from the search help. Take a look at the standard one and mention the same parameter name.
    Regards,
    Ravi
    Note : Please mark all the helpful answers

  • Copying table structure.

    create table temp2 as select * from temp1 where 1=2
    above SQL will create new table temp2; having structure of temp1.
    Is there any way to copy indexes, and triggers from temp1 to temp2 in similar fashion?
    Thanks in Advance,
    Shailesh

    Here is a proc I created to mirror an oracle table (staging template table) and it's indexes.
    I pass the original template table name and what I call a source_flag ( I need several copies to mirror several different sources) so I call load all the sources in parallel.
    The reason I'm copying them is that I plan to in-parallel copy data from multiple sources to a a data warehouse where the sources are identical in structure. The plan is to bulk load the data to a transient (short lived) staging table, do a partition exchange (partitioned by list on the source_flag) then drop the transient staging table.
    Remember, the table sturcture, constraints and indexes need to be identical between the staging table and the target locally indexed partitioned table.
    CREATE OR REPLACE PROCEDURE SF.MIRROR_TABLE_INDEXES_SP (TAB_NAME IN VARCHAR2, SOURCE_FLG IN VARCHAR2) AUTHID DEFINER AS
    TABLE_NM VARCHAR2(30) := TAB_NAME;
    SRC_FLG VARCHAR2(30) := SOURCE_FLG;
    SQLstr LONG;
    CURSOR CUR1 IS
    SELECT
    'CREATE INDEX '||'SF.'||SUBSTR(TABLE_NAME||SRC_FLG||'_IDX'||ROWNUM,DECODE(SIGN(29 - LENGTH(TABLE_NAME||SRC_FLG||'_IDX'||ROWNUM)),-1,-30,- LENGTH(TABLE_NAME||SRC_FLG||'_IDX'||ROWNUM)))||' ON '||TABLE_NAME||SRC_FLG||' ('||SUBSTR(SYS_CONNECT_BY_PATH(COLUMN_NAME, ','),2)||') TABLESPACE INDX' AS script
    FROM
    SELECT
    TABLE_NAME,
    INDEX_NAME,
    COLUMN_NAME,
    COLUMN_POSITION,
    COUNT(*) OVER ( PARTITION BY INDEX_NAME ) CNT,
    ROW_NUMBER () OVER ( PARTITION BY INDEX_NAME ORDER BY INDEX_NAME,COLUMN_POSITION) SEQ
    FROM
    ALL_IND_COLUMNS
    WHERE
    INDEX_OWNER = 'SF' AND TABLE_NAME = TABLE_NM)
    WHERE
    SEQ=CNT
    START WITH
    SEQ=1
    CONNECT BY PRIOR
    SEQ+1=SEQ
    AND PRIOR
    INDEX_NAME=INDEX_NAME;
    BEGIN
    SQLstr := 'CREATE TABLE '||TABLE_NM||SRC_FLG||' AS SELECT * FROM '||TABLE_NM||' WHERE 1=0';
    --DBMS_OUTPUT.PUT_LINE (SQLSTR);
    EXECUTE IMMEDIATE SQLstr;
    FOR indx_cursor in cur1
    LOOP
    SQLstr := indx_cursor.script;
    -- DBMS_OUTPUT.PUT_LINE (SQLstr);
    EXECUTE IMMEDIATE SQLstr;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE ('Table '||TABLE_NM||' created with indexes');
    END MIRROR_TABLE_INDEXES_SP;

Maybe you are looking for

  • Documentation on Project Configuration

    Hi, We are planning to do the ECC6 upgrade,we would like to use solution manager for the project management.Where can i find good documentation for this. Regards, Cs

  • Storing WDDX or XML Data

    At the moment I am storing results from form data in a wddx packet in a mediumtext field. It all works fine but i'm sure there must be a cleaner smarter solution. I have had to enable CLOBS on the datasource recently. It doesnt seem the best way of s

  • Multiple /different signatures iOS4

    I was hoping that it is now possible to use different signatures, at iOS4. WHY NOT?

  • Dashboard Settings - making one view available to all

    For the different dashboards our user wants to update the settings once and make this view available to many people in his organization.  How may I do this? Here are steps to follow to clarify what I am asking. 1)  View project dashboard. 2)  Click S

  • STARTING Adobe Audition CC

    Ok..The program is installed.  How on earth do I START the program?  I click on the Adobe Audition CC, and nothing happens.  The program doesn't start, period.  NORMALLY, when a program is installed, ALL you have to do is click on the icon, and the p