Script to rename all views in a database

Hi guys,
Does anyone has a script in handy to rename all the existing views  in a database .
Thanks in advance

You can use this script to the the "sp_rename" statements for all views:
SELECT N'EXECUTE sp_rename ' + QUOTENAME(name, '''') + N', ' + QUOTENAME(name + '_new', '''') + N';'
FROM sys.views
Olaf Helper
[ Blog] [ Xing] [ MVP]

Similar Messages

  • Script to fetch the script of a existing view from the Database

    Hi,
    How to fetch a existing view's information (SCRIPT) dynamically from the database.
    Thanks in advance
    Regards,
    Mr.R

    I did not post to ask this question.
    I try on the command line on SQL it prompts the first line of the script. How is the rest of the script?
    QL> select dbms_metadata.get_ddl('VIEW','MY_VIEW') from dual;
    BMS_METADATA.GET_DDL('VIEW','MY_VIEW')
    CREATE OR REPLACE FORCE VIEW "MY_USER"."MY_VIEW" ("USER_ID *<== How to fetch the rest of the script.*

  • Script to rename tv show with season and episode number

    Hi all,
    I am working on a script to rename all the files of a tv show contain into a single folder - keeping season & episodes numbers.
    I am using zenity to get the correct name of the tv show (mainly to add capital letters, and remove the dots - and also to be able to use the script for different tv show)
    then again using zenity to select which folder contain the files, and then I want zenity to display how the rename will do as a verification and if happy then process.
    The script work great but I can get zenity to display the output of the command and ask the question.
    Any suggestion?
    Many thanks,
    Regards,
    #!/bin/bash
    #Use Zenity to capture the title of the TV Show
    tv_show_name=$(zenity --entry)
    #Select folder where the files to be rename are
    sourcefolder=$(zenity --file-selection --directory --title "Please select the folder containing those Files")
    #Move into the folder
    cd $sourcefolder
    #Now we execute the script to keep season and episode numbers
    if [ $? == 1 ]; then exit; fi
    for filename in *; do
    if [[ "$filename" =~(\**).*(.*[0-9][0-9]).*([0-9][0-9]).*(\....)$ ]]; then
    result=$(`echo mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}"`)
    zenity --question --title="Are those title correct?" \
    --text=$result \
    if [[ $? -eq 0 ]] ; then exit; fi
    else
    mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}")
    fi
    done
    exit

    Right,
    I finally got it!
    Now the script work (tested with multiple files, different names) and the verification is to a singles files just to be sure not the mess up those episodes number.
    #!/bin/bash
    #Use Zenity to capture the title of the TV Show
    tv_show_name=$(zenity --entry)
    #Select folder where the files to be rename are
    sourcefolder=$(zenity --file-selection --directory --title "Please select the folder containing those Files")
    #Move into the folder
    cd "$sourcefolder"
    #Now we execute the script to keep season and episode numbers
    if [ $? == 1 ]; then
    exit
    fi
    for filename in *; do
    if [[ "$filename" =~(\**).*(.*[0-9][0-9]).*([0-9][0-9]).*(\....)$ ]]; then
    result=$(echo mv \"$filename\" \"$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}\")
    zenity --question --title="Are those title correct?" \
    --text="$result" \
    if [[ $? == 0 ]] ; then
    mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}"
    fi
    fi
    done
    exit

  • How to view all my views in a Database?

    Hi there,
    could any one tell me what's the command to display each of the following:
    1. all views (SYstem and the user define ones)
    2. all triggers (SYstem and the user define ones)
    3. all procedures, (SYstem and the user define ones)
    in the database?
    TY

    If you just want a listing, you can do this:
    select owner, object_type, object_name
    from   dba_objects
    where  object_type in ('VIEW','TRIGGER','PROCEDURE');(you don't want to see functions or packages?)
    If you want to see the code for these types, an easy way is to use the package dbms_metadata to display them:
    SQL> select dbms_metadata.get_ddl('TRIGGER','ORDERS_TRG','OE') from dual;
    DBMS_METADATA.GET_DDL('TRIGGER','ORDERS_TRG','OE')
      CREATE OR REPLACE TRIGGER "OE"."ORDERS_TRG" INSTEAD OF INSERT
    ON oc_orders FOR EACH ROW
    BEGIN
       INSERT INTO ORDERS (order_id, order_mode, order_total,
                           sales_rep_id, order_status)
                   VALUES (:NEW.order_id, :NEW.order_mode,
                           :NEW.order_total, :NEW.sales_rep_id,
                           :NEW.order_status);
    END;
    ALTER TRIGGER "OE"."ORDERS_TRG" ENABLE

  • How to view all table of a database

    How to view all table of a database created on a oracle 9.2/10g database management system.
    How to view available tables of oracle dbms which comes by default with package.
    Thank you so much in advance!
    With Regards,
    Niks

    You posted the same question twice.
    How to view all table of a database

  • 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/

  • How to search all columns of all tables in a database

    i need to search all columns of all tables in a database , i already write the code below , but i've got the error message below when run this script
    DECLARE
    cnt number;
    v_data VARCHAR2(20);
    BEGIN
    v_data :='5C4CA98EAC4C';
    FOR t1 IN (SELECT table_name, column_name FROM all_tab_cols where owner='admin' and DATA_TYPE='VARCHAR2') LOOP
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' ||t1.table_name|| ' WHERE ' ||t1.column_name || ' = :1' INTO cnt USING v_data;
    IF cnt > 0 THEN
    dbms_output.put_line( t1.table_name ||' '||t1.column_name||' '||cnt );
    END IF;
    END LOOP;
    END;
    Error report:
    ORA-00933: SQL command not properly ended
    ORA-06512: at line 7
    00933. 00000 - "SQL command not properly ended"
    *Cause:   
    *Action:
    Any help please

    SQL solutions by Michaels
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    11g upwards
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('EMP', 'DEPT')),
           xmltable (str columns result varchar2(10) path '.')
    TABLE_NAME                     COLUMN_NAME                    SEARCH_STRING                    RESULT   
    DEPT                           DNAME                          es                               RESEARCH 
    EMP                            ENAME                          es                               JAMES    
    EMP                            JOB                            es                               SALESMAN 
    EMP                            JOB                            es                               SALESMAN 
    4 rows selected.

  • UNION on two views in Different databases

    Hi All,
    Could you please help me in sorting out this requirement.
    We have two views in one database and two more views in another database. Now I want to create one view which should give the union of all these four views. We have DB links. Is it possible? If yes please send me the script.
    Thanks in advance to all.
    Thanks & Regards
    Rajesh Amathi

    Hi and welcome to OTN.
    please refer to Oracle books, your question is simple and also a few hard explained.
    You can use union, union all, intersec and of course many join methods. Which one is for you, you should decide it, or let us know what exactly do you need.
    If objects separated different databases, of course db link is necessary.
    example of creation view:
    CREATE VIEW sample_view AS
    SELECT e1.Ename, e2.Empno, e1.Deptno
    FROM table1 t1, table2 t2, table3@remotedb t3, table4@remotedb t4
    WHERE t1.id = t2.id and t3.id=t4.id; --you can join all tables as you want
    to overview of view please refer to : http://www.dba-oracle.com/concepts/views.htm
    Edited by: Ulfet Tanriverdiyev on Aug 3, 2010 2:56 AM

  • Generate a script to recreate all grants

    Hi anybody has a script to generate the grants for all database? grants ike this example :
    ..........ablespace Quotas for CANTOR
    ALTER USER CANTOR QUOTA UNLIMITED ON CV_TEMP;
    ALTER USER CANTOR QUOTA UNLIMITED ON CV_DATA;
    -- 166 Object Privileges for CANTOR
    GRANT EXECUTE ON FRSQ.FFFR TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRAVI_INT TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRBOBF2 TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRBOBMPST TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRBOCBCJ TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRBOCN TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRBOTERM TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRDIRBF TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRDIRCBCJ TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRDIRCN TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRDIRTERM TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRLET_INT TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRLST TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRSUBFA TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRSUBFF TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRSUBPFIZ TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRSUBPR TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRSUBRITS TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRSUBTERM TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFFRVAL TO CANTOR;
    GRANT EXECUTE ON FRSQ.FFUTIL TO CANTOR;
    GRANT SELECT ON FRSQ.INFO_DEMANDE TO CANTOR;
    GRANT SELECT ON FRSQ.INFO_PROGRAMME TO CANTOR;
    GRANT DELETE, INSERT, SELECT, UPDATE ON GDEM.ACCES_DOSSIER TO CANTOR;
    GRANT SELECT ON GDEM.ACCES_NON_AUTORISE TO CANTOR;
    GRANT EXECUTE ON GDEM.ACCES_UDA TO CANTOR;
    GRANT SELECT ON GDEM.AUDIT_ACCES TO CANTOR;
    GRANT EXECUTE ON GDEM.COMPOSITION_EQUIPE TO CANTOR;
    GRANT EXECUTE ON GDEM.COMPOSITION_EQUIPE_LI TO CANTOR;
    GRANT SELECT ON GDEM.COMPOSITION_LI TO CANTOR;
    GRANT SELECT, UPDATE ON GDEM.COMPOSITION_SUBV TO CANTOR;
    GRANT SELECT, UPDATE ON GDEM.COMPO_TEMP TO CANTOR;
    GRANT SELECT ON GDEM.COURRIEL_SEQ TO CANTOR;
    GRANT SELECT ON GDEM.DATE_LIMITE TO CANTOR;
    GRANT SELECT ON GDEM.DATE_LIMITE TO CANTOR;
    GRANT SELECT ON GDEM.DATE_LIMITE_BR TO CANTOR;
    GRANT REFERENCES, SELECT ON GDEM.DEMANDE TO CANTOR;
    GRANT REFERENCES, SELECT ON GDEM.DEM_LI TO CANTOR;
    GRANT SELECT ON GDEM.DOCUMENT_FCAR TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFR TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFRACB3 TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFRACBO TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFRACDE TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFRACDEL TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFRACDELSC TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFRACDESC TO CANTOR;
    GRANT EXECUTE ON GDEM.FAFRACNP TO CANTOR;
    Edited by: Jpmill on Aug 7, 2009 11:05 AM

    Hi.
    Then use all these below views to get the grants:-
    ALL_TAB_PRIVS          All object grants where the user or public is grantee
    ALL_TAB_PRIVS_MADE     All object grants made by user or on user owned objects
    ALL_TAB_PRIVS_RECD     All object grants to user or public
    DBA_SYS_PRIVS          System privileges granted to users and roles
    DBA_ROLES          List of all roles in the database
    DBA_ROLE_PRIVS          Roles granted to users and to other roles
    ROLE_ROLE_PRIVS          Roles granted to other roles
    ROLE_SYS_PRIVS          System privileges granted to roles
    ROLE_TAB_PRIVS          Table privileges granted to roles
    SESSION_PRIVS          All privileges currently available to user
    SESSION_ROLES          All roles currently available to user
    USER_SYS_PRIVS          System privileges granted to current user
    USER_TAB_PRIV          Grants on objects where current user is grantee, grantor, or ownerAnand

  • How to get all INDEXes from a database

    How to get all INDEXes in a database? I need to store them in script file (.SQL). My database version is 10.2.0.3.0.
    Edited by: Iniyavan on Sep 18, 2009 1:39 PM

    --Thanks, Koppelaars. The second query works. But I'm unable to store in spool file. May be it's due to CLOBs in the output. I did the following:
    set head off
    set feedback off
    set linesize 32727
    set pagesize 50000
    spool c:\indexes.sql
    select dbms_metadata.get_ddl('INDEX',INDEX_NAME,'MYSCHEMA')
    from user_indexes;
    spool off
    --In the spool file, I find only this
    CREATE UNIQUE INDEX "MYSCHEMA"."A" ON "MYSCHEMA"."BNK_DEALID" ("DEAL_ID")
    PCTF
    CREATE INDEX "MYSCHEMA"."ACCENT_RAC_REPORT" ON "MYSCHEMA"."ACCENT" ("SCHEME", "VAL
    CREATE INDEX "MYSCHEMA"."ACCENT_REPORT" ON "MYSCHEMA"."ACCENT" ("SCHEME", "APP_REF
    CREATE UNIQUE INDEX "MYSCHEMA"."ACCENT_X" ON "MYSCHEMA"."ACCENT" ("DEAL_ID")
    P
    CREATE UNIQUE INDEX "MYSCHEMA"."ACCNAV_X" ON "MYSCHEMA"."ACCNAV" ("SCHEME", "ACCNA
    --How to get all the DMLs in one SQL file?
    --Nagappan, I'm using WIN.

  • 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.

  • Need to find total no fo  tables/index/m.views in my database

    Hello Everyone ;
    How can i find total no fo  tables/index/m.views in my database ?
    when i  google  i have seen  following  command ;
    SQL> Select count(1) from user_tables where table_name not like '%$%' /
      COUNT(1)
             but i dont understand  what  '%$%'  indicates ?
    Thanks all ;

    Hello Everyone ;
    How can i find total no fo  tables/index/m.views in my database ?
    when i  google  i have seen  following  command ;
    SQL> Select count(1) from user_tables where table_name not like '%$%' /
      COUNT(1)
             but i dont understand  what  '%$%'  indicates ?
    Thanks all ;
    consider to simply Read The Fine Manual YOURSELF!
    Oracle Database Search Results: like

  • Is there a way to rename all photos in a folder?

    Is there a fast way to rename all the photos in one folder e.g. I have diffreent folders say "wedding" and "birthday" with alot of photos in each. Is there a way to rename all photos in the folder to the same name like all called wedding?
    Also when i open photos they automatically open with preview, do I need to impost them into iPhoto or should they just automatically save there?
    Tracy

    Tracy
    Are these photos in iPhoto? If so, then use the Photos -> Batch Change command.
    IF not then you can use a batch file renamer such as Name Mangler
    iPhoto is a database and can only show pics that have been imported to the DB.
    Regards
    TD

  • Include or create a view in the database and use this view?

    Well, I need to get related data of the main table from another related tables, so one way to do that is to use the Include method in Entity Framework to get this related data.
    However, I am thinking in another option, create a view in the database and use this view in entity framework. In this way, I avoid the needed of the include, because I think that is expensive in resources. But I am no very sure about that.
    I would like to know if the use of views on entity framework is a good idea to improve the performace or is better to use the include.
    For example, if I use the include I have the advantage that I get only one the main record and all the related data I have in the navigation properties, so the info is more shorted.
    Which is the advanteges and disadvantages of both methods to get related data in entity framework?
    Thank so much.

    Hello ComptonAlvaro,
    >>I would like to know if the use of views on entity framework is a good idea to improve the performace or is better to use the include.
    If your view would use a Join syntax to query master-child relationship tables, it actually is similar with the Include() method which actually results a duplicate records from master table, you could check this
    link for detail description.
    >>Which is the advanteges and disadvantages of both methods to get related data in entity framework?
    One visible difference is that records from Views are not editable by default(if you want edit them, you could refer to this
    blog).
    In your case, my suggestion that you could use the lazying load which will load the matter table once and disable the trace if you only need to display data.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Script to calculate space usage at the database level.

    Hi,
    Can someone provide me a script to calculate the Total space, Used space and Free space for all tablespaces within a database??
    I have been trying to use the below combinations in my queries and both provide different results..
    1) dba_data_files & dba_free_space
    select t.tablespace, t.totalspace as " Totalspace(MB)", round((t.totalspace-fs.freespace),2) as "Used Space(MB)", fs.freespace as "Freespace(MB)", round(((t.totalspace-fs.freespace)/t.totalspace)*100,2) as "% Used", round((fs.freespace/t.totalspace)*100,2) as "% Free" from (select round(sum(d.bytes)/(1024*1024)) as totalspace, d.tablespace_name tablespace from dba_data_files d group by d.tablespace_name) t, (select round(sum(f.bytes)/(1024*1024)) as freespace, f.tablespace_name tablespace from dba_free_space f group by f.tablespace_name) fs where t.tablespace=fs.tablespace order by t.tablespace;
    2) dba_extents & dba_free_space
    select t.tablespace, t.totalspace as " Totalspace(MB)", round((t.totalspace-fs.freespace),2) as "Used Space(MB)", fs.freespace as "Freespace(MB)", round(((t.totalspace-fs.freespace)/t.totalspace)*100,2) as "% Used", round((fs.freespace/t.totalspace)*100,2) as "% Free" from (select round(sum(d.bytes)/(1024*1024)) as totalspace, d.tablespace_name tablespace from dba_extents d group by d.tablespace_name) t, (select round(sum(f.bytes)/(1024*1024)) as freespace, f.tablespace_name tablespace from dba_free_space f group by f.tablespace_name) fs where t.tablespace=fs.tablespace order by t.tablespace;
    Thanks in advance,
    regards,
    Arul S

    -- check the total,used and free space in tablespaces
    select     a.TABLESPACE_NAME,
         a.BYTES MB_total,
         b.BYTES MB_free,
         b.largest,
         a.BYTES-b.BYTES MB_used,
         round(((a.BYTES-b.BYTES)/a.BYTES)*100,2) percent_used
    from
              select      TABLESPACE_NAME,
                   sum(BYTES)/1048576 BYTES
              from      dba_data_files
              group      by TABLESPACE_NAME
         a,
              select      TABLESPACE_NAME,
                   sum(BYTES)/1048576 BYTES ,
                   max(BYTES)/1048576 largest
              from      dba_free_space
              group      by TABLESPACE_NAME
         b
    where      a.TABLESPACE_NAME=b.TABLESPACE_NAME
    order      by ((a.BYTES-b.BYTES)/a.BYTES) desc;
    Regards
    Asif Kabir

Maybe you are looking for