Primary key deletion in custom database table
hi,
I've created a ztable.In which i've have created primary key and foreign key.
I've activated the table.Now my requirement is that i want to delete the primary key as i've shoosen wrong field as primary key.
For that first of all i deleted the foreign key relationship than i have unchecked the primary key but it is giving me an error.
even though if i deleted that field having primary key it is also giving me error as "Primary key change not permitted for value table.
Please help me out if possible.
waiting for ur response.
Thanks,
Dheeraj
Make sure u dont have any data in the table..u have to delete all the data..Also make sure you are not using that table any where else.do a where used list in the table.
Similar Messages
-
Default Primary Key Field of any database table
hi,
I am working on a database in which the data in the tables is generated from some other modules. I have to add, view and update functionalities to this table in the database. Unfortunately there is no primary key field for the table i am working on and as some existing modules are using this table i am not allowed to change the design of the table at this stage.
Without primary i think its not possible to do updates. Because if all fields can have their values changed, then there will be a breakdown if the field value changes in the mid time when i had already retrieved the data to show on the screen, but not yet updated the value in the database. I hope you understood my problem.
Please suggest solutions. I am not sure, but i think i read somewhere that every table created has a default primary associated whose value is always incresing with a new addtion of recored and its value never decreases. But i am unable to recollect the field name...i think it is some thing like[b] OID .... But i checked there is no such field name by OID. So please help me with some alternative solution...or by telling the default primary key field name.
ThanxAll the databases I know (namely Informix, PostgreSQL, SQL Server, even Access) have a row id column generated automatically.
PostgreSQL example
There is a way to read the value of this column; for example with PostgreSQL let�s say you have the following:
CREATE TABLE no_id_column (
column_one varchar(80),
column_two varchar(80)
INSERT INTO no_id_column(column_one, column_two) VALUES (�red�, �pink�);
INSERT INTO no_id_column(column_one, column_two) VALUES (�yellow�, �orange�);Certainly, if we executed:
SELECT * FROM no_id_column;Would obtain:
column_one column_two
red pink
yellow orangeBut if we modify the query
SELECT oid, * FROM no_id_column;We magically obtain a row identificator
oid column_one column_two
21569 red pink
21570 yellow orangeThe data in the oid column is generated automatically by the database manager. Every time we insert a row we�ll have a different one. Just take into account that if the database contains a large amount of data, the oid could cycle. -
How to find out the primary key column of a database table?
Hi
Given the following scenario :
Given an inputfield, the user can enter a table name. The code behind will base on the table name given and extract out the fieldname of the primary key and concatenate the two field to become a unique string.
Eg. Order ID and Product ID make out a primary key.
How do i achieve that? Any code sample?
Regards,
RaydenCheck the below code :
REPORT zTest no standard page heading.
data : i_DD03P like DD03P occurs 0 with header line.
data v_table like DCOBJDEF-NAME.
parameters : p_table like dd02l-tabname.
start-of-selection.
v_table = p_table.
CALL FUNCTION 'BDL_DDIF_TABL_GET'
EXPORTING
NAME = v_table
STATE = 'A'
LANGU = 'E'
IMPORTING
GOTSTATE =
DD02V_WA =
DD09L_WA =
TABLES
DD03P_TAB = i_DD03P
DD05M_TAB =
DD08V_TAB =
DD12V_TAB =
DD17V_TAB =
EXCEPTIONS
ILLEGAL_INPUT = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at i_DD03P.
if i_dd03p-KEYFLAG = 'X'.
write:/ 'Key fields', i_dd03p-FIELDNAME.
endif.
endloop.
Thanks
Seshu -
Update primary key/delete and reinsert records
Hi, I have been told to update some fields. The database is new to me, and now I see the field is the primary key (and it has child tables with that as foreign key). The person who told me isn't reachable until next week...
...wasn't a bad idea to update pk's? I see it's possible, deferring constraints...
update primary key
Re: Update Primary Key
...but it's better/safer the script deletes and later re-insert the records, right?
ThanksAlways is better be able to undo any change .
But ¡, why would you update pk's? it's possible but you colud find few problems like:
- many levels of foreign keys exists.
- not validate pk
Look at:
Re: Novalidate primary key -
Hi ,
I need to delete all the records in the dtabase table and insert new data into it.
I use the below code , but the delete returns with sy-subrc 4 and doesnt delete the records in table ?
delete ZZVT2_BW.
commit work and wait.
insert ZZVT2_BW from table itab_zvt2 accepting duplicate keys.
commit work and wait.
Thanks,Deleting from a Database Table
<b>- DELETE FROM dbtab. or
DELETE FROM (dbtabname).</b>
- DELETE dbtab FROM wa. or
DELETE (dbtabname) FROM wa.
- DELETE dbtab FROM TABLE itab. or
DELETE (dbtabname) FROM TABLE itab.
- DELETE dbtab. or
DELETE *dbtab.
- DELETE dbtab VERSION vers. or
DELETE *dbtab VERSION vers.
use the bold text in u r program -
Delete all the database table content
Hello Friends,
I have a z table with 5 fields (all the key fields) and I want to delete all the table content and load fresh content from internal table.
I tried using syntax 'delete ztable' but sy-subrc value is coming as 4, means no table content is getting deleted.
Please suggest me any alternative way to delete all the database table content.
Thanks in advance,
ShreekantHi,
try using
delete from ztable.
This will delete all records from your ztable. After this command u can fill your ztable from itab by the following command
select *
from std table
into corresponding fields of itab.
insert ztable from table itab.
Hopefully this will solve your problem.
Regards,
Ibrar -
How to edit one particular entry in custom database table
Hi all,
I want edit one particular entry in custom database table with or without a program.
1. I tried using SE16N and &SAP_EDIT but im unable to get entries to edit.
2. I tried using '/h' and 'code = edit' but it is prompting me to delete an entry but not edit.
3. I tried using modify statement. But in vain.
I tried this statements through programatically,
MODIFY itab FROM wa_itab TRANSPORTING zabc.
MODIFY zsample_02 FROM itab.
please suggest with out writing a program, if possible.Hi ,
Try with FM SE16N_INTERFACE.
1 .Go to SE37
2. Enter FM SE16N_INTERFACE and execute
3. Give table name in Itab,
I_EDIT =
X
I_SAPEDIT =
X
4. Press F8
5. Edit table entries and save.
Thanks -
Primary key constraint for index-organized tables or sorted hash cluster
We had a few tables dropped without using cascade constraints. Now when we try to recreate the table we get an error message stating that "name already used by an existing constraint". We cannot delete the constraint because it gives us an error "ORA-25188: cannot drop/disable/defer the primary key constraint for index-organized tables or sorted hash cluster" Is there some sort of way around this? What can be done to correct this problem?
What version of Oracle are you on?
And have you searched for the constraint to see what it's currently attached to?
select * from all_constraints where constraint_name = :NAME; -
NULL in primary keys NOT logged to exceptions table
Problem: Inconsistent behavior when enabling constraints using the "EXCEPTIONS INTO" clause. RDBMS Version: 9.2.0.8.0 and 10.2.0.3.0
- NULL values in primary keys are NOT logged to exceptions table
- NOT NULL column constraints ARE logged to exceptions table
-- Demonstration
-- NULL values in primary keys NOT logged to exceptions table
TRUNCATE TABLE exceptions;
DROP TABLE t;
CREATE TABLE t ( x NUMBER );
INSERT INTO t VALUES ( NULL );
ALTER TABLE t
ADD ( CONSTRAINT tpk PRIMARY KEY (x) EXCEPTIONS INTO exceptions );
SELECT * FROM exceptions; -- returns no rows
-- NOT NULL column constraints logged to exceptions table
TRUNCATE TABLE exceptions;
DROP TABLE t;
CREATE TABLE t ( x NUMBER );
INSERT INTO t VALUES ( NULL );
ALTER TABLE t MODIFY ( X NOT NULL EXCEPTIONS INTO EXCEPTIONS );
SELECT * FROM exceptions; -- returns one row
I would have expected all constraint violations to be logged to exceptions. I was not able to find any documentation describing the behavior I describe above.
Can anyone tell me if this is the intended behavior and if so, where it is documented?
I would also appreciate it if others would confirm this behavior on their systems and say if it is what they expect.
Thanks.
- Doug
P.S. Apologies for the repost from an old thread, which someone else found objectionable.I should have posted the output. Here it is.
SQL>TRUNCATE TABLE exceptions;
Table truncated.
SQL>DROP TABLE t;
Table dropped.
SQL>CREATE TABLE t ( x NUMBER );
Table created.
SQL>INSERT INTO t VALUES ( NULL );
1 row created.
SQL>ALTER TABLE t ADD ( CONSTRAINT tpk PRIMARY KEY (x) EXCEPTIONS INTO exceptions );
ALTER TABLE t ADD ( CONSTRAINT tpk PRIMARY KEY (x) EXCEPTIONS INTO exceptions )
ERROR at line 1:
ORA-01449: column contains NULL values; cannot alter to NOT NULL
SQL>SELECT * FROM exceptions;
no rows selected
SQL>
SQL>TRUNCATE TABLE exceptions;
Table truncated.
SQL>DROP TABLE t;
Table dropped.
SQL>CREATE TABLE t ( x NUMBER );
Table created.
SQL>INSERT INTO t VALUES ( NULL );
1 row created.
SQL>ALTER TABLE t MODIFY ( X NOT NULL EXCEPTIONS INTO EXCEPTIONS );
ALTER TABLE t MODIFY ( X NOT NULL EXCEPTIONS INTO EXCEPTIONS )
ERROR at line 1:
ORA-02296: cannot enable (MYSCHEMA.) - null values found
SQL>SELECT * FROM exceptions;
ROW_ID OWNER TABLE_NAME CONSTRAINT
AAAkk5AAMAAAEByAAA MYSCHEMA T T
1 row selected.
As you can see, I get the expected error message. But I only end up with a record in the exceptions table for the NOT NULL column constraint, not for the null primary key value. -
Adding 2 new fields as Primary Key field in a Z Table which is existing PRD
Hi Friends,
I have to add two new fields as primary key fields in a Z TABLE, which is existing in Quality and Production Systems with Data.
If I incorporate these two new fields (Primary Key fields) in development and if the TR is moved to Quality and Production sytems, is there any possibility of loss in data will happen at Quality and Prd systems?
At present, Table is having 20 fields with 2 primary key fields and i have to add 2 more primary key fields.
I have checked in SCN and not find relevant threads.
Please help me out.
Regards,
Suresh.NO . It wont be a problem .
For ex :
If you have VBELN , POSNR are key fields now , you have an unique reord with that combination .
If you add one other field in it fo ex VKBUR then records will be like this
VBELN POSNR VKBUR MATERIAL QTY
10020 10 abcxyz 1
10020 10 1234 abcxyz 1
So your previous records before adding new primary keys , will have new fields balnk , and the new records will have data filled up in all primary key fields .
However , if you try to update the existing records that will be in existing PRIMARYKEY combination only .
for example if you try update record 1 above with VKBUR value 85858 , it creates a new record , it wont be updated in existing record.
Hope this helps , Pls let me know if u have any more doubts. -
How to know primary key column name form a table name in sql query
Suppose I only know the table name. How to get its primary key column name from the table name?
ThanksViews don't have primary keys though their underlying tables might. You'd need to pick apart the view to determine where it's columns are coming from.
You can select the text of the view in question from user_views. -
Delete entries from Database table t71inp1
Hi,
I want to Delete entries from Database table t71inp1. Its a H R Table. I want to know the exact code.
i saw the cide delete bkpf where usnam = p_name.
Will it work the same here. Also.
Please let me know.
I hope to get reply from you soon.
where should i write the code. i.e. Tcode SE38 and directly deeleting write the code.
Please give me some inputs. I am new to H R ABAp
Shivakumar K B
919886920258hi
You can write a program in se38.
create a program.
use delete from t71inp1 where<condition> command in it. -
Hi!
Is there a way to delete row in database table by telling the number of the row?
Thanx!Oh, sorry I didn't properly read your post.
Try out what rvflannery suggests.
But, for reference, you should always delete a row by it's unique ID.
Don't go deleting things, by their position on a table, because a rows position can change.
V -
Knowing the primary key columns of the given table
Hi,
How can I get the primary key columns of the given table?
Regards,
Sachin R.K.You can find the constraint_name from all_constraints/user_constraints for constraint_type = 'P' (which is the primary key constraint).
And then see which columns are in for the constriant_name
in all_cons_columns/user_cons_columns view.
Below is the example
select acc.column_name from
all_cons_columns acc, all_constraints ac
where acc.constraint_name = ac.constraint_name
and acc.table_name = 'DEPT' AND acc.owner = 'SCOTT'
and ac.constraint_type = 'P'
Hope this helps
Srinivasa Medam -
How add primary key constraint to already existing table with data
I want apply primary key constraint to already existing table with data
is there any command or way to doAlternatively, assuming you want to ensure uniqueness in your primary key column you can do this:
alter table <table name> add constraint <cons name> primary key (col1,col2) exceptions into <exception_table>
If the altter table statement fails this will populate the EXCEPTIONS table with the rows that contain duplicate values for (col1,col2).
You will need to run (or get a DBA to run) a script called UTLEXCPT.SQL (which will be in the $ORACLE_HOME/rdbms/admin directory) if you don't already have an EXCEPTIONS table.
Cheers, APC
Maybe you are looking for
-
Previewing videos in Quick Look isn't the same in Snow Leopard.
Does previewing videos on Quick Look in Mac OS 10.6 Snow Leopard no longer allows you to use the two finger gesture to move forward or backwards in the video, or is it just me?
-
Why is my font dropdown blinking in RH 11?
The Style, Font and Font Size dropdowns in the upper left of the RH11 window (above the project manager panel) begin blinking back and forth, in time with the cursor, as soon as more than one Design/HTML tab is opened. Attempting to drop one of thos
-
Trying to transfer a movie file from my ipod to my pc
I am trying to put a movie file I have saved on my ipod classic and transfer it over to my pc. Now the ipod is set up to work with my macbook so when I hook it up to the pc it wants me to reformat it. I am using the ipod as an external storage so the
-
I purchased an IPAD 2 about three weeks ago. When I go to my Trash and Send foloders it appears that none of my deleted or sent e mails are bing captured/stored in these folders. do i have a configuration problem???
-
Speed up load to ftp server in window server 2008 slow
Dear all. I have configure FTP in window server 2008 (IIS 7.5...), when I test in LAN speed upload to ftp server is slow ( 60-80 KB/S). Please help me fix it. Thanks so much