How Badly Do You Abuse Reserved Words in Column Names

I have a challenge for all you DBA's out there.  Most of us agree that reserved words as column names is a bad practice but how clean is your database and some people are quit outspoken about it.  Run the following query on some of your custom, non-COTS, databases and post your top 5.  You may want to run it in Development to make sure new tables don't violate the best practice.  Often we don't think when creating column names or inherited ugly databases, but the fact is, we all have reserved word column names.
Marcus Bacon
SELECT   col.column_name , COUNT(1)
FROM     all_tab_columns col, sys.v_$reserved_words rwrd
WHERE    col.column_name = rwrd.keyword
AND      owner NOT IN
           ( 'SYS',
            'SYSTEM',
            'MDSYS',
            'DBSNMP',
            'WMSYS',
            'XDB',
            'APPQOSSYS',
            'OPSG',
            'ORDDATA',
            'ORDSYS',
            'OUTLN' ,
            'CTXSYS',
            'OE',
            'HR',
            'TOAD')
GROUP BY col.column_name
ORDER BY count(1) desc,col.column_name;
COLUMN_NAME                 
COUNT(1)
TO_DATE                           
32
NAME                              
21
ID                                
14
OWNER                              
9
CLASS                              
6

Hi,
Interesting exercise!
I modified your query, showing separate counts for Oracle, COTS and In-House schemas:
WITH   got_developer  AS
    SELECT  CASE
                WHEN  a.owner  IN ( 'APPQOSSYS'
                                  , 'CTXSYS'
                                  , 'DBSNMP', 'DMSYS'
                                  , 'HR'
                                  , 'MDSYS'
                                  , 'OE', 'OLAPSYS', 'OPSG', 'ORDDATA', 'ORDSYS', 'OUTLN'
                                  , 'SCOTT', 'SYS', 'SYSTEM'
                                  , 'TOAD', 'TSMSYS'
                                  , 'WKSYS', 'WMSYS'
                                  , 'XDB'
                                  )                THEN  'ORACLE'
                WHEN  a.owner  IN ( 'FUBAR'
                                  )                THEN  'COTS'
                                                   ELSE  'IN_HOUSE'
            END   AS developer
    ,       r.keyword
    ,       r.reserved
    FROM    all_tab_columns        a
    JOIN    sys.v_$reserved_words  r  ON  r.keyword = a.column_name
SELECT    keyword
,         reserved
,         SUM (CASE WHEN developer = 'IN_HOUSE' THEN 1 END)     AS in_house
,         SUM (CASE WHEN developer = 'COTS'     THEN 1 END)     AS cots
,         SUM (CASE WHEN developer = 'ORACLE'   THEN 1 END)     AS oracle
,         COUNT (keyword)                                       AS all_sources
FROM      got_developer
GROUP BY  GROUPING SETS ( (keyword, reserved)
                        , (reserved)
ORDER BY  keyword
,         reserved
Output from one database:
KEYWORD         R   IN_HOUSE       COTS     ORACLE ALL_SOURCES
A               N                                1           1
ACCOUNT         N                     2                      2
ADMIN           N                                3           3
ADMINISTRATOR   N          3                                 3
ADVISE          N                     2                      2
ALIAS           N                     2                      2
ALWAYS          N                                3           3
ATTRIBUTE       N          8                    34          42
ATTRIBUTES      N                               11          11
AUTHENTICATION  N                                3           3
AUTHID          N                                3           3
BIGFILE         N                                4           4
VALUE           N          8          3        173         184
VERSION         N          1          2        124         127
WAIT            N                                2           2
WHEN            N                                1           1
WHERE           Y                                2           2
WRITE           N                                1           1
XID             N                               20          20
XMLSCHEMA       N                               15          15
YEAR            N         21          1                     22
ZONE            N          2         30                     32
                N        479        182       4253        4914
                Y                                3           3
                         479        182       4256        4917
241 rows selected.
Over 85% of the cases (including all 3 of the reserved words (1 ORDER and 2 WHEREs) were in Oracle-supplied schemas.
The most commonly used keywords, outside of Oracle schemas, were
ID (used in 206 tables)
NAME (80)
PERCENT (38)
ZONE (32)
YEAR (22)
TIMESTAMP (18)
USAGE (17)
COST (15)
CLASS (12)
STATEMENT_ID (12)
LOCATION, which was one of your most common examples, only occured 4 times in this database, and OWNER not at all  (outside of Oracle schemas).

Similar Messages

  • How to create list of a View's column names and source

    Using SQL 2005, 2008, and 2012
    How to create list of a View's column names and source. For the following example would like to @Print something like the following.  Does anyone already have some code to do this? I realize there are probably some gotchas, but the views that I am looking
    at to use this follows the code snippet pattern below.
    DBACCT.[Account Number]
    dbo.ConvertDate(DBACDT). [Boarding Date]
    DBXES.DBXES
    CREATE VIEW [dbo].[v_ods_DBAL]
    AS
    SELECT DBACCT AS [Account Number], dbo.ConvertDate(DBACDT) AS [Boarding Date], DBXES
    FROM dbo.ods_DBAL

    The column information can be obtained from INFORMATION_SCHEMA.COLUMNS view using logic like below
    SELECT c.COLUMN_NAME,c.DATA_TYPE
    FROM INFORMATION_SCHEMA.COLUMNS c
    WHERE EXISTS (SELECT 1
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_NAME = c.TABLE_NAME
    AND TABLE_TYPE='VIEW')
    http://technet.microsoft.com/en-us/library/ms188348.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • I need to use a reserved word as parameter name in proc called from URL

    Let me preface this post by saying I already know this is terrible to attempt, but it's short term fix only.
    Ok, so I have to create a procedure that will be called by a vendors application via a API that calls our URL to send data over. The terrible part is
    that the API they have uses the parameter FROM=vendor_data A change is on the way so in the future the API won't use FROM as a paramter, so this isn't something I want to do, but it's a workaround.
    So the nastiness is this..., I can create a procedure that'll compile when I enclose FROM in double quotes "FROM" as my input parameter
    but if I try to call my procedure via URL (as their application will do) the procedure isn't working. I searched for someway to do an inline
    replace of the FROM parameter to something else, but no luck. I'm open to all positive comments. I cannot go outside of Oracle
    to do this, so I can't call a shell script and replace. Basically I need some way to use a reserved word as a parameter name, and then be able to call
    that proc from a URL, or someway to change the FROM in the URL inline. Any help on this admittedly whacky situation would be appreciated much.
    I tried ...\myproc?from=text
    ...\myproc?"from"=text
    ...\myproc?'from'=text
    proc is simple test procedure
    create or replace procedure myproc
    ("from" in varchar2 default 0)
    is
    v_from varchar2(30);
    begin
    v_from:="FROM";
    insert into test(col1) values(v_from);
    end;
    **** Update
    I didn't get any more replies but came to a solution that I thought I'd post. It's much better, more elegant and maybe can help others.
    So instead of using FROM as the parameter name I did some research and decided I can use flexible parameters. Basically you end up having
    2 input parameters for a procedure, one holds a parameter name the other holds the parameter value. They get loaded into arrays
    and you access the values with regular name_array(1), value_array(1), etc. ?v=parameter&v2=value
    Once I figued I could use flexible parameter it took me tons of research to find out the actual syntax. I'll post some examples for others
    later, but was suprised with the lack of resources consideriing how "flexible" they are.
    Thanks again for the replies. Cheers.
    Edited by: Mitz on Jul 29, 2009 11:37 PM

    Scott,
    Thanks for the reply. I'm not familiar with the wwv_flow_epg_include_mod_local, however I know that the
    myproc is available via URL. I passed the my procedure name(myproc) on to the dba a while back to make it "accessible" so, I'm assuming that he
    added it to this the www_flow_epg_mod_local (assuming this has something to do with access control).
    If I modify myproc procedure and remove "FROM" as the input variable, and replace with say,
    IN_FROM I can then call the procedure via the URL ./myproc?in_from=test without any problems.
    I'm pretty confident that it's the "FROM" that is the hurdle and not a security or setup issue. The proc is fine to call from the URL until I got the curveball that the only available parameter was FROM. How the URL should be when inputing to that parameter?
    Edited by: Mitz on Jul 25, 2009 7:36 PM
    Edited by: Mitz on Jul 25, 2009 9:16 PM

  • How to change recordset bahaviour to accept dynamic column names in the where clause

    Hi
    im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
    "select id,name from mytable where $tablename-$myvar";
    but when i do this my i break the recordset and it disappear
    and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
    and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
    so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
    thanks in advance.

    As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
    Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
    // create array of acceptable values
    $valid = array('column_name1', 'column_name2', 'column_name3');
    // if the query string contains an acceptable column name, use it
    if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
      $col = $GET['colname'];
    } else {
      // set a default value if the submitted one was invalid
      $col = 'column_name1'
    You can then use $col directly in the SQL query.

  • How to make dynamic query using DBMS_SQL variable column names

    First of all i will show a working example of what i intend to do with "EXECUTE IMMEDIATE":
    (EXECUTE IMMEDIATE has 32654 Bytes limit, which isn't enough for me so i'm exploring other methods such as DBMS_SQL)
    -------------------------------------------------CODE-----------------------------------
    create or replace PROCEDURE get_dinamic_query_content
    (query_sql IN VARCHAR2, --any valid sql query ('SELECT name, age FROM table') 
    list_fields IN VARCHAR2) --list of the columns name belonging to the query (  arr_list(1):='name';   arr_list(2):='age';
    -- FOR k IN 1..arr_list.count LOOP
    -- list_fields := list_fields || '||content.'||arr_list(k)||'||'||'''~cs~'''; )
    AS
    sql_stmt varchar (30000);
    BEGIN
                   sql_stmt :=
    'DECLARE
         counter NUMBER:=0;     
    auxcontent VARCHAR2(30000);     
         CURSOR content_cursor IS '|| query_sql ||';
         content content_cursor%rowtype;     
         Begin
              open content_cursor;
              loop
                   fetch content_cursor into content;
                   exit when content_cursor%notfound;
                   begin                              
                        auxcontent := auxcontent || '||list_fields||';                    
                   end;
                   counter:=counter+1;     
              end loop;
              close content_cursor;
              htp.prn(auxcontent);
         END;';
    EXECUTE IMMEDIATE sql_stmt;
    END;
    -------------------------------------------------CODE-----------------------------------
    I'm attepting to use DBMS_SQL to perform similar instructions.
    Is it possible?

    Hi Pedro
    You need to use DBMS_SQL here because you don't know how many columns your query is going to have before runtime. There are functions in DBMS_SQL to get information about the columns in your query - all this does is get the name.
    SQL> CREATE OR REPLACE PROCEDURE get_query_cols(query_in IN VARCHAR2) AS
    2 cur PLS_INTEGER;
    3 numcols NUMBER;
    4 col_desc_table dbms_sql.desc_tab;
    5 BEGIN
    6 cur := dbms_sql.open_cursor;
    7 dbms_sql.parse(cur
    8 ,query_in
    9 ,dbms_sql.native);
    10 dbms_sql.describe_columns(cur
    11 ,numcols
    12 ,col_desc_table);
    13 FOR ix IN col_desc_table.FIRST .. col_desc_table.LAST LOOP
    14 dbms_output.put_line('Column ' || ix || ' is ' ||
    15 col_desc_table(ix).col_name);
    16 END LOOP;
    17 dbms_sql.close_cursor(cur);
    18 END;
    19 /
    Procedure created.
    SQL> exec get_query_cols('SELECT * FROM DUAL');
    Column 1 is DUMMY
    PL/SQL procedure successfully completed.
    SQL> exec get_query_cols('SELECT table_name, num_rows FROM user_tables');
    Column 1 is TABLE_NAME
    Column 2 is NUM_ROWS
    PL/SQL procedure successfully completed.
    SQL> exec get_query_cols('SELECT column_name, data_type, low_value, high_value FROM user_tab_cols');
    Column 1 is COLUMN_NAME
    Column 2 is DATA_TYPE
    Column 3 is LOW_VALUE
    Column 4 is HIGH_VALUE
    PL/SQL procedure successfully completed.I've just written this as a procedure that prints out the column names using dbms_output - I guess you're going to do something different with the result - maybe returning a collection, which you'll then parse through in Apex and print the output on the screen - this is just to illustrate the use of dbms_sql.
    best regards
    Andrew
    UK

  • How to add pop up menu on the column name of a jtable

    hi all,
    i am naive to swing .
    i want to know that how can i open a pop up menu on the right click of the column of a jtable build in frame.i mean to say i on th eright click on the header of table which has column names.

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup]How to Use Popup Menus.

  • How to set naming standard that sets max number of words in column name?

    Hi all,
    Is it possible to set naming standard that sets max number of words in colum (or table) name?
    I was looking video (1:08min)
    http://download.oracle.com/otn_hosted_doc/sqldev/UserDefinedDesignRules/UserDefinedDesignRules.html
    And here you can see how rule is triggered.
    "...Name has 2 words; Max permitted - 1".
    Thanks a lot

    Hi,
    you need to create glossary and set it in naming standards for your design.
    This document is still valid - http://www.oracle.com/technetwork/developer-tools/datamodeler/datamodelernamingstandards-167685.pdf
    Naming standard settings are located :
    - DM 3.x - "Preferences>Data Modeler>Naming Standard"
    - DM 4.0 - Design dialog>Settings>Naming Standard
    If you want only check on number of words then glossary can be empty and you can set "Incomplete modifiers" option in that glossary.
    Philip

  • Does the Class Word always have to be the last word in column name? What about Units?

    Sometimes we are required to store both a US and a metric column in the same table.  Is it ok to use the unit type as a suffix to the class word like AreaSqMi and AreaSqkm in the case of watersheds which cross both the US and Canadian borders?
    Before everyone jumps on me let me explain.  The software environment we are using is from ESRI's (Geographic Information System) for displaying maps.  The popups for displaying attribute data can only display existing columns so no derived columns.

    Use columns standarts
    http://www.codeproject.com/Articles/22947/A-Naming-Scheme-for-Database-Tables-and-Fields
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to remove white seperators in ALV Table columns names?

    Hi,
    I am trying to remove white seperators which appeared dynamically on using ALV table on each of the column names. I checked in ALV API's but could not find anything there to remove code wise. Please help to remove this.
    Thanks
    Praveen

    Hi Praveen,
    Please use the following method.
      DATA lo_table  TYPE REF TO cl_salv_wd_config_table.
      CALL METHOD lo_table->if_salv_wd_std_functions~set_sort_headerclick_allowed( EXPORTING value  = abap_false ) .
    Regards,
    Manogna

  • Best practice for the use of reserved words

    Hi,
    What is the best practice to observe for using reserved words as column names.
    For example if I insisted on using the word comment for a column name by doing the following:
    CREATE TABLE ...
    "COMMENT" VARCHAR2(4000),
    What impact down the track could I expect and what problems should I be aware of when doing something like this?
    Thank You
    Ben

    Hi, Ben,
    Benton wrote:
    Hi,
    What is the best practice to observe for using reserved words as column names.Sybrand is right (as usual): the best practice is not to use them
    For example if I insisted on using the word comment for a column name by doing the following:
    CREATE TABLE ...
    "COMMENT" VARCHAR2(4000),
    What impact down the track could I expect and what problems should I be aware of when doing something like this?Using reserved words as identifiers is asking for trouble. You can expect to get what you ask for.
    Whatever benefits you may get from naming the column COMMENT rather than, say, CMNT or EMP_COMMENT (if the table is called EMP) will be insignificant compared to the extra debugging you will certainly need.

  • SQL Developer 1.5 migration issue with MS use of reserved words

    In version 1.2 the was and advanced option that allowed the use of reserved words for column names, I can not find that option in 1.5. What happened to this option? I can not find it and I need to port those applications with out changing the column names. I know I can hand edit the scripts but I did not have to do that with 1.2.
    Any one know if this can still be done?

    n 1.2 iIt was under preferences - > Migration -> Advanced, in version 1.5 no advanced options and I searched around and could not find it else where. gulp as for the reserved words ( don't laugh I am just migrating under orders) there are date, number and some columns with embedded / that it barfs on. I am under orders to do it the way it is written.

  • Oracle Reserved Words in EJB Implementations

    Hello Everybody!
    Suppose there is a table in Oracle , say Account which has a column, say comment. comment is a reserved word in Oracle. I would like to know how Oracle reserved words are handled in EJB implementation. For example, suppose there is an enterprise application that accesses such a table using CMP beans, how would we specify the <field-map>
    <field-map>
    <cmp-field>comment</cmp-field>
    <dbms-column>COMMENT</dbms-column>
    </field-map>
    This doesnt work because COMMENT is a reserved word in Oracle. In Oracle,
    if we use comment as a column name, it has to be represented in double quotations.
    for example, this select query doesnt work
    select COMMENT from account;
    these select queries works
    select "COMMENT" from account;
    select A."COMMENT" from account A;
    Regarding the current EJB implementations, the question is whether they support Oracle reserved words in their mappings??
    "COMMENT"s welcome
    Thanks!
    Manu Ramakrishnan

    >
    This doesnt work because COMMENT is a reserved word in
    Oracle. In Oracle,
    if we use comment as a column name, it has to be
    represented in double quotations.
    Did you try it?
    Did you try it with double quotes?
    The specs I looked at do not discuss this(jdbc, ejb, j2ee.) The ejb spec reserves as part of EJB QL some standard ANSI SQL reserved words and specifically suggests that other ANSI SQL reserved words should not be used.
    And if I am reading the EJB QL section correctly identifiers (which would be a table, field names) do not allow quoted identifiers. Or at least they specifically do not allow fields with, for example, a space. This sort of name is specifically allowed for in ANSI SQL and has been since the first version of ANSI SQL. They also do not allow for case sensitive names, which again is allowed in ANSI SQL as part of a quoted identifier.
    That suggests to me that you use reserved words that either you going to be using a non-J2EE feature of a container or it simply won't work in the first place.

  • How bad will this hurt?

    I have been considering buying a RV for a while. My boys aren't getting any younger. We currently have our house on the market. It seems like it is going to take forever to sell. My question is how bad do you think it will hurt my credit if I were to take out a small loan for approx $10,000 for a RV? My credit scores on fico 8 are around 660-670. I know waiting until after we buy a house is probably the best idea, but it just doesn't seem like it's going to sell anytime soon and I am dying to go camping and enjoy the summer with my husband and two boys.

    Kyliemarie85888 wrote:
    I have been considering buying a RV for a while. My boys aren't getting any younger. We currently have our house on the market. It seems like it is going to take forever to sell. My question is how bad do you think it will hurt my credit if I were to take out a small loan for approx $10,000 for a RV? My credit scores on fico 8 are around 660-670. I know waiting until after we buy a house is probably the best idea, but it just doesn't seem like it's going to sell anytime soon and I am dying to go camping and enjoy the summer with my husband and two boys.How about teaching your boys the joy of camping in a tent while hiking in the mountains or in a campground?  Most boys would rather do this than hang out in a motorhome.  (Motorhomes: Think retirees). I have been reading a lot about personal finance and the rule seems to be borrow only for necessities, pay cash for luxuries.    Just something to think about. I know RV's can easily cost 60K - 100K or more, so I might be concerned about a 10K RV needing expensive repairs. Your boys won't be boys forever, but the important part is that you spend time with them.  They don't need an RV to enjoy their parents. You could also rent a lot of nights in a nice cabin for less than 10K if you don't like sharing your bedroom space with bugs and bears.

  • How to rename a column name in a table? Thanks first!

    I tried to drop a column age from table student by writing the
    following in the sql plus environment as :
    SQL> alter table student drop column age ;
    but I found the following error
    ORA-00905: &#32570;&#23569;&#20851;&#38190;&#23383; (Lack of Key word)
    I have oracle enterprise edition 8.0.5 installed at windows 2000
    thank you
    And I want to know how to rename a column name in a table?
    thanks

    In Oracle 8i, your syntax would have worked.  However, if I
    recall correctly, in Oracle 8.0, you can't rename or drop a
    column directly.  One way to get around that problem is to
    create another table based on a select statement from your
    original table, providing the new column name as an alias if you
    want to change the column name, or omitting that column from the
    select statement if you just want to drop it.  Then drop the
    original table.  Then re-create the original table based on a
    select statement from the other table.  Then you can drop the
    other table.  Here is an example:
    CREATE TABLE temporary_table_name
    AS
    SELECT age AS new_column_name,
           other_columns
    FROM   student
    DROP TABLE student
    CREATE TABLE student
    AS
    SELECT *
    FROM   temporary_table_name
    DROP TABLE temporary_table_name
    Something that you need to consider before doing this is
    dependencies.  You need to make a list of all your dependecies
    before you do this, so that you can re-create them afterwards. 
    If there are a lot of them, it might be worthwhile to do
    something else, like creating a view with an alias for the
    column or just providing an alias in a select.  It depends on
    what you need the different column name for.

  • How to use get column name.vi in SQL toolkit 2.0?

    Due to the vi "get column name.vi" paremeters,no table name has connected to the vi. So, I want to ask how to use this vi for gain one column name of a table. Maybe there are some other ways to solve column name getting.
    Thanks.

    Thanks!
    Error 4101 Description:
    Execute SQL - The connection, statement, or query handle you provided is not valid.
    I don't just used the toolkit in a while,now, I am developing a irrigation system. For the table field names defined by users,column names must be known before any select operations. Do you have any other good idea about drawing out the columnname parameters?
    As you know, a valid DSN and table have been also available. The database I used is Access. The bad thing to me is that there is no any text information gotten. And I think, it may be some problems in connection way which I don't find out.
    Really appreciated by your reply.
    Could you give me some example in the aspect?
    Thank you again.

Maybe you are looking for

  • Itunes will not sync songs to ipod

    I am using itunes 8 and have a 80gb classic ipod sixth generation. I cannot get over 400 songs to sync up from itunes to my ipod and there have been no error messages indicating that there is anything wrong with the songs themselves. In the past it h

  • What do I need to implement to recognize a "return" in a JTextArea?

    When the user presses the return key, I wish to trigger an event, but I don't know what to implement to do that (I can't get ActionListener to work, and KeyListener covers all the keys and I just want to listen for the return key) Thanks

  • Standard KM Content on 7.31

    Hi all, we have upgraded our portal from 7.0 to 7.31 all working fine except KM content. if im trying to open any document(pdf, txt,html,doc...etc) in KM content its giving portal run time error . any one knowing what was the issue? i have checked in

  • ColdFusion Developer roles

    Hi, I urgently required 2 ColdFusion Developer for 2 permanent roles based in central London. Ideally you will have 3+ years experience but less is considered if recent. Please send me an email if you are interested or if you know someone who is. Tha

  • Should I compress our FCP4 project or drag our QT movie to iDVD?

    We're relativity new to editing and have completed a project in FCP4, which is 50 mintues in length. We rendered the project and then made a QT movie. We believe we need to now compress the project in FCP prior to dragging it into iDVD for completion