Home » SQL & PL/SQL » SQL & PL/SQL » Column Restriction (Oracle 11g)
Column Restriction [message #608813] Tue, 25 February 2014 02:53 Go to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
Am trying to restrict/Alert user on CREATE TABLE if more than 50 columns.

Can anyone suggest on this

Version - Oracle 11g.
Re: Column Restriction [message #608816 is a reply to message #608813] Tue, 25 February 2014 03:37 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Here is an example that prevents you from creating a table with more than five columns
SQL> create or replace trigger test_trigger
  2  after create on schema
  3  begin
  4    <<bk>>
  5    declare
  6      cnt pls_integer := 0;
  7    begin
  8      if sys.dictionary_obj_type = 'TABLE' then
  9        select
 10          count(*)
 11        into
 12          bk.cnt
 13        from
 14          user_tab_columns t1
 15        where
 16          t1.table_name = sys.dictionary_obj_name;
 17  --
 18        if bk.cnt > 5 then
 19          raise_application_error(-20001, 'too many columns');
 20        end if;
 21      end if;
 22    end;
 23  end;
 24  /

Trigger created.

SQL> show errors;
No errors.
SQL> 
SQL> create table t1(n number);

Table created.


SQL> create table t2(n1 number, n2 number, n3 number, n4 number, n5 number, n6 number);
create table t2(n1 number, n2 number, n3 number, n4 number, n5 number, n6 number)
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: too many columns
ORA-06512: at line 17

[Updated on: Tue, 25 February 2014 03:41]

Report message to a moderator

Re: Column Restriction [message #608828 is a reply to message #608816] Tue, 25 February 2014 05:20 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Not strictly related to this question, but: I've attended HrOUG conference and there were people presenting their Forms application. The process seemed rather complex, but data model suggested that only a few tables were used. I wasn't sure whether I missed something so I asked a question whether they really have only those 5-6 tables, and - if so - how many columns do these tables have.

The answer was rather interesting; they said that number of tables is correct, each of them having hundreds of columns (the "largest" one with some 500 columns at the moment.

Whoa! Five hundred! How come?

They said that money they pay Oracle isn't peanuts and that they plan to use full of Oracle (that would be 1000 columns, eh?).

Amazing.

So, why would you stop at (only) 50?!?
Re: Column Restriction [message #608830 is a reply to message #608828] Tue, 25 February 2014 05:27 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Did they by any chance say something about the performance of their application in that conference? Laughing
Re: Column Restriction [message #608838 is a reply to message #608816] Tue, 25 February 2014 06:33 Go to previous messageGo to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
Thanks dariyoosh , Exactly its related to performance of application.

Can i get the user action from SYS like CREATE or ALTER , because based on this i have another work around.

Is this SYS.dictionary_obj_type is table or views?
Re: Column Restriction [message #608841 is a reply to message #608816] Tue, 25 February 2014 07:00 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
dariyoosh wrote on Tue, 25 February 2014 04:37
Here is an example that prevents you from creating a table with more than five columns
[code]


Yes, this is basic solution. But OP also needs to clarify what type of columns shoul be counted. Should virtual column be counted? Hidden column? Invisible column (12C)?

SY.


Re: Column Restriction [message #608856 is a reply to message #608841] Tue, 25 February 2014 09:33 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Am trying to restrict/Alert user on CREATE TABLE if more than 50 columns.
why do folks have the necessary privileges if they can not be trusted to comply with policy?
why not terminate anyone who violates 50 column limit?
why does policy limit require a technical solution?

I suspect application does not comply with Third Normal Form.
Previous Topic: Putting a WITH statement into PL/SQL
Next Topic: Query for the below
Goto Forum:
  


Current Time: Fri Apr 26 15:35:21 CDT 2024