Creating sequences for all tables in the database at a time

Hi ,
I need to create sequences for all the tables in my database.
i can create individually ,using toad and sqlplus.
Can any one give me a code for creating the sequences dynamically at a time for all the tables.
it is urgent ..
Regards.

I need to create sequences for majority of the tables that are having ID column
which is sequences."The majority" is not the same as all. So you probably want to drive your generation script off the ALL_TAB_COLUMNS view...
where column_name = 'ID'You need to think about this carefully. You might want different CACHE sizes or different INCREMENT BY clauses for certain tables. You might even (whisper it) want a sequence to be shared by more than one table.
Code generation is a useful technique, but it is a rare application where one case fits all.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/

Similar Messages

  • How do I run sp_spaceused for all tables in a database?

    Hi,
    I am struggling to understand how to run the sp_spaceused sproc for all tables in a database.
    I know how to use it for one table but how would I replicate it automatically for each table in a given database?
    Regards,
    Ian.

    I just managed to alter the code of VidyaSagar and have pulled out all the information including Schema name. Below is what it looks like:
    set
    nocount
    on
    select
    'Database Name: ',
    db_name
    if
    exists(select
    name from tempdb..sysobjects
    where name='##tmp'
    drop
    table ##tmp
    create
    table ##tmp(TABLE_SCHEMA
    nvarchar(256),TABLE_NAME
    nvarchar(256),
    num_rows int,
    reserved_KB varchar(15),data_KB
    varchar(15),index_KB
    varchar(15),unsed_KB
    varchar(15
    go
    declare
    @tbl_schema nvarchar(256
    declare
    @tbl_name nvarchar(256
    declare
    @schema_tbl_name nvarchar(256
    declare
    tblname CURSOR
    for
    select
    TABLE_SCHEMA
    TABLE_NAME
    from
    INFORMATION_SCHEMA.TABLES
    where TABLE_TYPE='BASE
    TABLE' 
    open
    tblname
    Fetch
    next
    from tblname
    INTO @tbl_schema,@tbl_name
    WHILE
    @@FETCH_STATUS
    = 0
    BEGIN
    set @schema_tbl_name=@tbl_schema+'.'+@tbl_name
    insert
    into ##tmp(TABLE_NAME
    , num_rows
    , reserved_KB
    ,data_KB
    ,index_KB
    ,unsed_KB
    exec
    sp_spaceused
    @schema_tbl_name
    update ##tmp
    set TABLE_SCHEMA
    =@tbl_schema
    where TABLE_SCHEMA
    is
    NULL
    and TABLE_NAME=@tbl_name
    FETCH
    NEXT
    FROM tblname
    INTO @tbl_schema,@tbl_name 
    END
    CLOSE
    tblname
    deallocate
    tblname
    go
    select
    from
    ##tmp
    drop
    table ##tmp
    Warm Regards, Ajay

  • Newbie ques : How to get the list of all tables in the database

    Hi,
    I'm very new to Oracle (using Oracle8i currently). I wanted to know if there is a way to get the list of all tables in the database. Like in mySQL you can use the command " show tables" to get the list of all the tables.
    Any help will e greatly appreciated. Please "cc" any reply to [email protected] also.
    thanks
    Deven

    Hi
    Select table_name, owner from all_tables;
    will give u all the tables in the database.
    all_tables, dba_tables, user_tables
    all_objects, dba_objects, dba_objects
    there are many, more tables. login as system and query the tab and try to describe the tables.
    Thanks
    Malar

  • Creating synonys for all table

    i want to create synonyms for all atbles.the synonyn name and table name are same.instead creating one by one synonym i wnat to create all synonyms at a time.
    1)select 'CREATE PUBLIC SYNONYM'||' '||'test'||' '||'for' ||' '||'test' from dual
    2)select OBJECT_NAME from user_objects where OBJECT_TYPE ='TABLE'
    in the first query if we replace with test with 2nd query then we can get the script for that.
    i replaced that biut its not working how to do it

    Here is a generic grant script. If you review it, you will see how it works and can adapt it to your varying needs.
    BEGIN
        FOR x IN ( SELECT owner,
                          object_name,
                          DECODE(object_type, 'TABLE' ,   'select, insert, update, delete',
                                              'SEQUENCE', 'select',
                                              'VIEW',     'select',
                                                          'execute') AS privs,
                          DECODE (owner, 'SCHEMA_1', 'USER_1',
                                         'SCHEMA_2', 'ROLE_A'
                                          ) AS app_user
                     FROM dba_objects
                    WHERE object_type IN ('TABLE',    'PACKAGE', 'PROCEDURE',
                                          'FUNCTION', 'SEQUENCE', 'VIEW')
                      AND owner       IN ('SCHEMA_1', 'SCHEMA_2' ))
        LOOP
          BEGIN
            EXECUTE IMMEDIATE 'grant ' || x.privs       || ' on ' || x.owner ||
                              '.'      || x.object_name || ' to ' || x.app_user   ;
            EXECUTE IMMEDIATE 'create or replace synonym '|| x.app_user||'.'||x.object_name||
                               ' for ' ||x.owner||'.'||x.object_name ;
          EXCEPTION
            WHEN others THEN
              dbms_output.put_line('Bad owner = '||x.owner||';  Bad app_user='||x.app_user||
                                   ';  Bad object_name='||x.object_name);
          END;
        END LOOP;
    END;
    /

  • How to delete duplicate records in all tables of the database

    I would like to be able to delete all duplicate records in all the tables of the database. Many of the tables have LONG columns.
    Thanks.

    Hello
    To delete duplicates from an individual table you can use a construct like:
    DELETE FROM
        table_a del_tab
    WHERE
        del_tab.ROWID <> (SELECT
                                MAX(dups_tab.ROWID)
                          FROM
                                table_a dups_tab
                          WHERE
                                dups_tab.col1 = del_tab.col1
                          AND
                                dups_tab.col2 = del_tab.col2
                          )You can then apply this to any table you want. The only differences will be the columns that you join on in the sub query. If you want to look for duplicated data in the long columns themselves, I'm pretty sure you're going to need to do some PL/SQL coding or maybe convert them to blobs or something.
    HTH
    David

  • Creating SYNONYM for all tables who don't have one at once!

    Hello to all,
    I'm trying to create synonyms for every table who's missing one at the moment. I'm trying this code:
    declare
    cursor cur_objects is
    select obj.object_name , obj.owner
    from all_objects obj
    where owner = '&&SCHEMA_OWNER'
    AND NOT EXISTS (SELECT *
    FROM all_synonyms syn
    WHERE obj.object_name = syn.table_name)
    AND obj.object_type = 'TABLE'
    AND obj.object_name LIKE 'CI_%';
    begin
    for rec_objects in cur_objects loop
    begin
    dbms_output.put_line(rec_objects.object_name);
    execute immediate('create public synonym ' || rec_objects.object_name || ' for '
    || rec_objects.owner ||'.'||rec_objects.object_name )
    exception when others then
    null;
    end;
    end loop;
    end;
    I'm getting this error:
    ORA-06550: line 10, column 37:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
    begin function package pragma procedure subtype type use
    <een ID>
    <een scheidingsteken-ID tussen dubbele aanhalingstekens> form
    current cursor
    I'm still pretty new at PL/SQL and can't get it to work. Does anyone got any tips ?
    Thnx already

    Ok now I got this error:
    RA-06550: line 17, column 1:
    PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:
    * & = - + ; < / > at in is mod remainder not rem return
    returning <een exponent (**)> <> or != or ~= >= <= <> and or
    like LIKE2_ LIKE4_ LIKEC_ between into overlaps using ||
    multiset bulk year DAY_ member SUBMULTISET_
    The symbol ";" was substituted for "EXCEPTION" to continue.

  • Table to get the list of all tables in the database

    hi,
    please let me knwo the table where i can get the list of all tables in the database

    hi,
    please let me knwo the table where i can get the list
    of all tables in the databaseHi Michael,
    Will you EVER start reading some documentation?
    I guess it's not far that many regulars won't reply to those kind of questions.
    Believe me, reading doesn't hurt (well, at least, most of the times).
    Rgds,
    Guido

  • How get all table name from database

    hi master
    sir
    how get all table name from database

    The big question is 'why'.
    Selecting from view 'dba_tables' will indeed give the list of all tables in the database, but that includes the dictionary tables and the internal tables, and many others that are probably not of interet to a person who needs to ask this question. Besides, the dba_tables view requires access to a DBA account.
    There are several other views: "user_tables" will list all the tables in this user's schema; and "all_tables" will list all the tables this user can access in some way.
    The above do not, of course, include any information about synonyms, sequences, views, indexes and so on.
    The correct answer and the meaningful answer may be two different things.

  • Create LOV's for all columns at the time of folder creation

    Hi,
    I know we can automatically create the LOV's for all the columns of a database table when creating the folder in the EUL. Is this a good practice or should I create LOV's on demand? What is the disadvantage of creating more LOV's than needs to be used other than the disk storage? I also know it is not a good idea to have an LOV on a field that has a lot of values. I am tempted not to create the LOV's in the beginning, but then it becomes a high maintenance issue if I have to come back and create many LOV's later. Thank you for your input.

    Yes, it is not a good idea to create LOVs for all the columns. LOVS should be created only for the columns where parameters will be used. More the number of LOVs, slower the response in opening up your Discoverer reports and if you are using Disco Viewer, the page might take a long time to open up and frustrate the users.
    Also it is a good practise to have LOVs defined on the lookup tables or where there are distinct values in the table and not from where these values are used in the table.
    regards
    http://www.infocaptor.com <--- Free Discoverer Monitoring Dashboards

  • How to search all columns of all tables in a database for a keyword?

    Dear Team,
    i have an requirement that : i want to search all the columns of all the tables in the particular database based on the specific key word or an free text.
    example :
    table 1: columns data
    empname sam
    empid 01
    table 2 columns data
    deptname sam
    departmentid 10
    table 3 columns data
    organization name sam
    organization id 1
    when i search for text " SAM"
    it should search me from the entire database, all tables and columns of it and display the result
    output : tablename cloumn value
    table1 empname sam
    table2 deptname sam
    table3 organizationame sam
    the example is just an sample not the real data .
    please help me with sample code or any link related to it .
    thanks in advance

    Hi justin , thanx for the reply
    the basic requirement that we required is ,
    the user will just type the keyword( value in the coumn) he required and it should search all the tables and columns of the table in the database and i have to show this in the front ent in the table format. here the user will analyse the information based on the search .
    it is just like the google search we does( type the keyword in free text) it will display the result.
    so for that i have to search entire table and columns in the whole database.
    please if any one provides me the solution it will be help full for me.
    thanx in advance

  • How can I resize and reposition the Date Created window for All windows?

    When setting view options for a finder window set to list view, I cannot get column resizing or positioning to hold. When making those changes, the option for "All Windows" automatically shifts to "This window only" and it then does not hold.
    How can I resize and reposition the Date Created column for All WIndows?

    Hi Harmz,
    Try dragging this file to the Îesktop & reboot...
    /Users/YourUserName/Library/Preferences/com.apple.finder.plist

  • Creating an shortcut for all users on the desktop

    I want to create a shortcut for all users on the desktop that will appear for all users that login to the computer.  How is this done in Windows 7?  In Widows XP this was done at the "All Users" profile, but I cannot find such a profile  in Windows 7. 

    the users have windows vista , 7 or 8 have a chortcut i created and the users have windows xp isn't created on them desktop
    Do you have a question? If so then your best bet is to create a new post (this one is 5 years old and marked as "answered"!) and spell it out there.

  • How to CREATE SEQUENCE in one table

    dear all
    the one thing i want to know when i use CREATE SEQUENCE in one table like this and then at that table
    CREATE SEQUENCE oproduct_sequence
    START WITH 1  INCREMENT BY 1 
    nocache
    create table oproduct(
    tname varchar2(20) not null,
    tid int default  oproduct_sequence.nextval
    the system indicat that i cannot use this way to create table , so i really want to know how can i achieve this method
    becuase when i want to insert inot table oproduct only use
    insert into oproduct  valuse('aaaa');
    and the result like
    aaaaa 1
    bbbb   2

    Actual name is before insert trigger. Some examples are listed below:
    Example Number 1 ...
    create sequence product_seq start with 1 increment 1
    create or replace trigger product_insert before insert for each row begin
    select productseq.nextval
    into :new.product_id
    from dual;
    end;
    Example Number 2 ...
    How to create an autoincrement field in a table with a sequence ...
    SQLWKS> create table bob(a number , b varchar2(21));
    Statement processed.
    First create a sequence
    SQLWKS> create sequence x ;
    Statement processed.
    Then create the trigger.
    create trigger y before insert on bob
    for each row
    when (new.a is null)
    begin
    select x.nextval into :new.a from dual;
    end;
    Example Number 3 ...
    First create a sequence:
    create sequence emp_no_seq;By default it increments by 1 starting at 0.
    Use its values when inserting data into the table:
    insert into t_emp values (emp_no_seq.nexval, 'Joe Black');~ Madrid.

  • Datapump skipping partitioned tables in the database

    I have run expdp on Oracle 10.2.0.4.0 on AIX 5.6 Platform, the export runs well exporting rows in the database but when it comes to partitioned tables in the database it export no rows for all the partitioned tables. When I run a normal exp/imp the partitioned tables are exported with all their rows.
    I used the following commands:
    expdp system/****** dumpfile=export_data.dmp directory=DATA_PUMP_DIR full=y logfile=export_dump.log
    Output for expdp on partitioned table:
    . . exported "SCOTT"."DEPT":"DEPT_2003_P1" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P10" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P11" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P12" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P2" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P3" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P4" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P5" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P6" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P7" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P8" 0 KB 0 rows
    . . exported "SCOTT"."DEPT":"DEPT_2003_P9" 0 KB 0 rows
    And for exp:
    exp system/****** file=export_dump.dmp full=y log=export_log1.log
    Result from the export log for partitioned tables:
    . . exporting partition DEPT_2005_P1 881080 rows exported
    . . exporting partition DEPT_2005_P2 1347780 rows exported
    . . exporting partition DEPT_2005_P3 2002962 rows exported
    . . exporting partition DEPT_2005_P4 2318227 rows exported
    . . exporting partition DEPT_2005_P5 3122371 rows exported
    . . exporting partition DEPT_2005_P6 3916020 rows exported
    . . exporting partition DEPT_2005_P7 4217100 rows exported
    . . exporting partition DEPT_2005_P8 4125915 rows exported
    . . exporting partition DEPT_2005_P9 1913970 rows exported
    . . exporting partition DEPT_2005_P10 1100156 rows exported
    . . exporting partition DEPT_2005_P11 786516 rows exported
    . . exporting partition DEPT_2005_P12 822976 rows exported
    I am not sure about this behavour from datapump, my database is more than 800GB and we want to migrate the database from AIX to LINUX.
    Thanks

    Sorry I just copied and pasted some extracts from my exp and expdp logs:
    For testing purposes I tried to run a datapump export of only 1 partitioned table in the database and its going through, but when I do the same on a full datapump export these partitioned tables are being exported with no rows.
    Export: Release 10.2.0.4.0 - 64bit Production on Tuesday, 02 August, 2011 12:18:47
    Copyright (c) 2003, 2007, Oracle. All rights reserved.
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "SYSTEM"."SYS_EXPORT_TABLE_01": system/******** dumpfile=DEPT.dmp tables=scott.dept logfile=dept1.log
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 48.50 GB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/COMMENT
    Processing object type TABLE_EXPORT/TABLE/RLS_POLICY
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
    Processing object type TABLE_EXPORT/TABLE/TRIGGER
    Processing object type TABLE_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    . . exported "SCOTT"."DEPT":"DEPT_2009_P6" 1.452 GB 7377736 rows
    . . exported "SCOTT"."DEPT":"DEPT_2009_P7" 1.363 GB 6935687 rows
    . . exported "SCOTT"."DEPT":"DEPT_2008_P6" 1.304 GB 6656096 rows
    . . exported "SCOTT"."DEPT":"DEPT_2010_P7" 1.410 GB 7300618 rows
    . . exported "SCOTT"."DEPT":"DEPT_2008_P7" 1.296 GB 6641073 rows
    . . exported "SCOTT"."DEPT":"DEPT_2010_P6" 1.328 GB 6863885 rows
    . . exported "SCOTT"."DEPT":"DEPT_2007_P6" 1.158 GB 6568075 rows
    . . exported "SCOTT"."DEPT":"DEPT_2009_P5" 1.141 GB 5801822 rows
    . . exported "SCOTT"."DEPT":"DEPT_2011_P5" 1.162 GB 6027466 rows
    . . exported "SCOTT"."DEPT":"DEPT_2007_P7" 1.100 GB 6214680 rows
    . . exported "SCOTT"."DEPT":"DEPT_2011_P6" 1.106 GB 5762303 rows
    . . exported "SCOTT"."DEPT":"DEPT_2010_P5" 1.133 GB 5859492 rows
    . . exported "SCOTT"."DEPT":"DEPT_2007_P5" 1.001 GB 5664315 rows
    . . exported "SCOTT"."DEPT":"DEPT_2008_P5" 1.023 GB 5229356 rows
    . . exported "SCOTT"."DEPT":"DEPT_2010_P8" 1.078 GB 5549666 rows
    . . exported "SCOTT"."DEPT":"DEPT_2007_P8" 940.3 MB 5171379 rows
    . . exported "SCOTT"."DEPT":"DEPT_2008_P8" 989.0 MB 4920276 rows
    . . exported "SCOTT"."DEPT":"DEPT_2009_P8" 918.6 MB 4553523 rows
    . . exported "SCOTT"."DEPT":"DEPT_2006_P6" 821.0 MB 5220879 rows
    . . exported "SCOTT"."DEPT":"DEPT_2008_P4" 766.6 MB 3832262 rows
    . . exported "SCOTT"."DEPT":"DEPT_2006_P8" 747.9 MB 4753538 rows
    . . exported "SCOTT"."DEPT":"DEPT_2006_P7" 741.8 MB 4708242 rows
    . . exported "SCOTT"."DEPT":"DEPT_2010_P4" 734.2 MB 3713567 rows
    . . exported "SCOTT"."DEPT":"DEPT_2005_P7" 661.4 MB 4217100 rows
    . . exported "SCOTT"."DEPT":"DEPT_2005_P8" 647.1 MB 4125915 rows
    . . exported "SCOTT"."DEPT":"DEPT_2011_P4" 677.8 MB 3428887 rows
    I also tried to run a normal schema by schema export with the normal exp system/password command the and got my dump file which is about 300GB, when I run the imp system/password command and specify fromuser=<system > and touser=<schemas_in_the_dumpfile> seperated by commas, it just comes up with this message:
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Export file created by EXPORT:V10.02.01 via conventional path
    import done in WE8ISO8859P9 character set and AL16UTF16 NCHAR character set
    Import terminated successfully without warnings.
    No tables are exported.
    If I specify the parameter imp system/password file=dept_export.dmp full=y log=dept_imp.log with the same dumpfile and it imports data from the dumpfile into my database.
    I am not sure what could be wrong with my dumpfile or my imp command and its parameters.

  • Table in the Database will be changed, what is impact

    Hi, I'm new to the Forum.
    We have a multiple reports build in the multiple Business arias, One of the Tables in the Database will be changed. My question is what is the best way to use EUL5 to see what impact it will make. I will appreciate any advise.

    When you say one of the tables in the database will be changed, do you mean columns will be added, or are some columns going away, column names changing, tablename changing or what?
    If the table is just getting some new columns added, then no problem. Your existing reports will still be fine and when you perform a refresh on the business area where the folder is pointing to your table, it will just pick up the new items.
    If columns are going away, then your reports will get an error if they refer to that column name via the folder. You can do a kludge to cover this for the short term. In the folder in Admin, you can add a calculation with the exact same name as the column that's going away. Then - if it's a character - put in some kind of striking phrase like 'Russ Was Here'. Then when the existing reports are run, you'll see the phrase and know you just have to delete it from the report. Once all gone from all reports - you can delete the condition from the folder.
    Hopefully you can see the reliance on the Discoverer folder having to have a non-changing table. The easier thing to do for the future - is to create a database view that points to the table. Then if the table changes in ANY way (well, except from being deleted altogether with no replacement table), you can always fix the view to return proper data and as your Disco folder is pointing to the view, nothing changes.
    Hey this is what NoetixViews does, what BIS view do, etc. - it's IMHO the best way to go for future development.
    Russ

Maybe you are looking for