Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is it not a good practice to display primary key on UI?

Badam123Mar 13 2018 — edited Mar 15 2018

Hi All

Presently we get device details though a feed where multiple devices can be mapped to single CustomerId. The device details are loaded in table : TBL_DEVICES . The devices presently do not have any natural primary key so we have created a sequence as primary key . We had a new request to assign a unique key for each device so that they can be searched from the UI using the unique key (Presently they can search using CustomerId) . The team has asked me to create a new column and increment using a sequence .

TBL_DEVICES  ( Existing structure)

-----------------

DEVICE_ID         NUMBER  PRIMARY KEY using Sequence

CUSTOMER_ID  NUMBER  FOREIGN KEY

DEVICE_DESC  VARCHAR2(100) 

CAPACITY         NUMBER

Can't we use the existing primary key as a unique key? . When I asked the same they said that showing primary key on UI is not a good practice . I was not convinced as it doesn't make sense to add a column and sequence which adds no value.

Please suggest.

Thanks

Comments

Marwim

Hello,

you should give us more information about your tables etc. Most of as have no crystal ball to see things not mentioned in your post ;-)

Regards

Marcus

1004386

DELETE FROM TABLE_NAME A

WHERE ROWID<>(SELECT MAX(ROWID)

FROM TABLE_NAME B

WHERE A.COLUMN_NAME=B.COLUMN_NAME);

Purvesh K

You must be look out for Foreign Keys, which will cascade the Delete operation to its Children. But this will require you to delete the Parent record, which you do not want to delete.

Hence, the only option that you are left with is to manually write the Delete statements starting with the Tables that appear at the bottom of the hierarchy and moving upwards.

I did prepare a dynamic solution once, but not sure if you can adopt it for your situation. please check https://forums.oracle.com/thread/2483825 for the provided solution.

santhosh T

Delete all data related to a record, but not the record itself.

Not sure by this, If you delete all the data from a record, how the record will be exists.

must accept input parm

delete from emp where empno=&empno;

This will promt you for the input value.

There is is RI in the tables so I must delete children first

By querying the USER_CONS_COLUMNS table you can get the constraint names on a table and then you can act according to it.

Shitab_416

Hi,

First check the table refrentials. and delete the data from child tables based on key column.

then delete the data from main table.

to pass parameters in query use  (:bind Variable)

for ex.

delete from emp where empno = :empno;

Thanks

BluShadow

1004386 wrote:

DELETE FROM TABLE_NAME A

WHERE ROWID<>(SELECT MAX(ROWID)

FROM TABLE_NAME B

WHERE A.COLUMN_NAME=B.COLUMN_NAME);

That is a potentially dangerous piece of SQL you have provided.

That will likely delete all records from the table.

Purvesh K

BluShadow wrote:

1004386 wrote:

DELETE FROM TABLE_NAME A

WHERE ROWID<>(SELECT MAX(ROWID)

FROM TABLE_NAME B

WHERE A.COLUMN_NAME=B.COLUMN_NAME);

That is a potentially dangerous piece of SQL you have provided.

That will likely delete all records from the table.

Or maybe, it won't delete any record from the Table if the data in Column is unique, which to me does not look like what OP is looking for.

BluShadow

PurveshK wrote:

BluShadow wrote:

1004386 wrote:

DELETE FROM TABLE_NAME A

WHERE ROWID<>(SELECT MAX(ROWID)

FROM TABLE_NAME B

WHERE A.COLUMN_NAME=B.COLUMN_NAME);

That is a potentially dangerous piece of SQL you have provided.

That will likely delete all records from the table.

Or maybe, it won't delete any record from the Table if the data in Column is unique, which to me does not look like what OP is looking for.

Indeed.  Whichever way, it's not safe SQL, relying on ROWID's, and certainly does not do what the OP was asking.

I guess ur requirement is something like this. Let sat I have employees table and EMPID is the primary key, Now u wanted to delete all the remaining table which has empid column for an employee not deleting the main employee base table ? Am i Correct, If that is the requirement Here u go:

  SELECT 'delete from '||TABLE_NAME||' where '||COLUMN_NAME||'=&emp_id;

  ' from user_tab_cols where column_name='EMPNO' and table_name<>'EMP';

The above select lists u the delete statements that u need to perform. U need to modify the column name nad table name value in the aboce query for ur requirement.

1 - 9
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 12 2018
Added on Mar 13 2018
29 comments
2,521 views