PL/SQL :: How To Create Primary Key Like W1
Jul 10, 2012primary key should be
W1
W2
W3 like this.
1,2,3 are sequence numbers.
primary key should be
W1
W2
W3 like this.
1,2,3 are sequence numbers.
A Master form in a tabular format. Id is a display item. I want to auto generate Id with following query.
select nvl(max(issue_id),0)+1 into :issue_mt.issue_id from issue_mt;
It works:
1)When each record is saved before creating new record.
It doesn't work:
2)If multiple records are entered with out saving each record.
What to do to generate unique Id in both cases?
how to create a primary key with out creating an index?
View 10 Replies View RelatedCreate table X(
var1 varchar2(20) null,
var2 varchar2(20) not null,
constraint pk_var1 primary key(var1)
We all know Primary key doesnt treat NULL as a value. But the above statement is fine to be executed without problem.
Is this something to be highlighted? or am i not right in understanding 'var1 varchar2(20) null '?
I have to create primary key using local on a partitioned table.
Since the table is huge it has to be done parallel. Following stmt is giving error
alter table XYZ add CONSTRAINT PKN_XYZ PRIMARY KEY (ID,LogDtTm)
USING INDEX LOCAL parallel 25 INITRANS 5 TABLESPACE OLTP_IDX_TS ;
i'm new to oracle environment.how can i specify NONCLUSTERD INDEX on Primary cloumn during table creation.By default it will create clusterd index but i need non-clusterd index on it.
I'm using following stmt to create normal primary constarint during table creation,
CONSTRAINT PKFORM_PROPS PRIMARY KEY (FORM_PROPS_PK) USING INDEX TABLESPACE DB123_INDEX
how can i change the above query, so that it should create NONCLUSTERED INDEX on Primary key column.
I want to create a trigger with the requirement of achieving Primary key functionality.
I have a "EMP" table. the table already contains a duplicate data on "EMPNO" column. i want to restrict entering duplicate data further into table for that i want to create a trigger.
where can i find different triggering events of DML(like update, delete etc...)and DDL(database and schema level).
I'm trying to create a sequence for a primary key to simply auto-increment by the default of 1. I have a sql script written to generate mt tables, and I'm not sure how to modify the script to include the sequence. I also just want the sequence for a specific column, ie, PK, not the PK in all tables.
Here's a snippet from my script:
create table image
(
image_id int NOT NULL,
source_id int NOT NULL,
CONSTRAINT image_id_pk PRIMARY KEY (image_id),
CONSTRAINT fk_source_id FOREIGN KEY (source_id) REFERENCES source(source_id)
);
Would I add the create sequence statement right after the create table, and if so, how do I apply the sequence to only 1 table and a single column?
What is difference when you issue a create controlfile with "standby" keyword on the primary database
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/path/db_stby.ctl';
vs. creating a control using
ALTER DATABASE BACKUP CONTROLFILE to '/path/db_control.ctl';
what does ORACLE put into the standby control that is "extra"? ie. what is the difference between a standby control file and a normal control file?
is it possible to create primary key on view and use this view for creating foreign key .
View 3 Replies View RelatedI am using RAC to RAC data guard environment. Os hp-unix. during primary(old standby) to standby(old primary) switchover I am ussing:
SQL>ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
I have 11.2.0.1 environment with standby and when performing switch over - it was hanging for more than 2 hours and i had to cancel it. This is what all i see in the database alert.log:
Errors in file /u02/app/oracle/diag/rdbms/drpdb/drpdb1/trace/drpdb1_m000_15160.trc:
ORA-01155: the database is being opened, closed, mounted or dismounted
Thu Apr 04 17:44:03 2013
Errors in file /u02/app/oracle/diag/rdbms/drpdb/drpdb1/trace/drpdb1_m000_15780.trc:
ORA-01155: the database is being opened, closed, mounted or dismounted
Thu Apr 04 17:59:03 2013
Errors in file /u02/app/oracle/diag/rdbms/drpdb/drpdb1/trace/drpdb1_m001_16373.trc:
[code]....
ORA-01155: the database is being opened, closed, mounted or dismounted.
While making a view.
1. Is it advisable to have primary key in a view.
2. Why can't we have a primary key in a view, what are its advantages. I mean one cannot search a view by index.
3. Is it because of hibernate, but again i have used distinct keyword in a view declaration which means i cannot insert via view.
Here is my code for view to make a primary key in a view.
CREATE OR REPLACE FORCE VIEW VU_NAME
PRIMARY_KEY, NAME_ID, ADDRESS_ID
)
[Code]....
alter view VU_NAME add constraint vemp_pk primary key (PRIMARY_KEY) disable
I have a table called Order_Mstr
order_id order_Desc
-------- ----------
1 Order1
2 Order2
3 Order3
4 Order4
Child tables referring Order_id are:
Order_child1
Order_child2
Order_child3
Order_child4
Order_child5
Order_child6
.
.
.
Order_child50
I have to update Order_id with some 8 digit number generated by some algorithm. And i have to update that value in child tables as well. In how many ways i can do this task. for example..
1) Disabling the constraint and updating Master value and child value.
what is the difference between these two and in where we use Primary key and where we choose Surrogate Key.How to understand the difference between these two keys.
View 7 Replies View Relatedunderstanding composite primary key.
I know what is composite key and how it stores the data.. but i am not able to find when i have to choose the columns to be composite keys.
Whats the command to show the name of the primary key in a table using oracle sql plus?
View 1 Replies View RelatedI have set up a schema using a DDL script in Oracle 10g. I am linking this through to a Visual Basic 2008 fron end. The connection is fine. My database of is for a car hire company project.
I need to know how to create an auto increment for a primary key field, like Access does.
For example here is my table structure for my Rental_Payment table.
-- TABLE RENTAL_PAYMENT
CREATE TABLE RENTAL_PAYMENT (
PAYMENTNO NUMBER NOT NULL,
CARDNO NUMBER NOT NULL,
[Code]....
So for example the first record would appear as:
PAYMENTNO CARDNO AMOUNT CARD_TYPE
======== ===== ====== =======
01
I would then enter values and the next payment number would be 02 etc.
PAYMENTNO CARDNO AMOUNT CARD_TYPE
======== ===== ====== =======
01 123412 £40.00 VISA
02
Visual Basic will usually have a star (*) beside a new entry field so 02 will be
* 02
etc........
I have about creating a sequence. So how can I tie this to my table?
I am trying to establish PK-FK relationship between 2 tables. Table 1 has VACC_ID as a primary key. Table 2 has VACC_ID and SCH_ID as the primary keys. I am trying to add VACC_ID from Table 2 as a FK to Table 1. This is the code I used
ALTER TABLE Table_1
ADD CONSTRAINT FK_VACC_ID
FOREIGN KEY (VACC_ID)
REFERENCES Table_2(VACC_ID)
I also tried to add it without writing the query and editing the Table 1. By default, I am getting 2 columns(both VACC_ID) in the local column being referenced to the 2 primary keys(VACC_ID and SCH_ID) of table 2. I also uploaded the screeshot of the error, when I run the query.
In my application I am facing peculiar error. For easy understanding I am considering emp table. In my package P1 I have two procedures Proc1,Proc2.
Proc1 : It is receiving employee details and for checking if employee already exists it is calling Proc2.
Proc2 : Here it checks if employee exists. If exists it deletes old record, commit and inserts new record in sequence.
But however in few instances Proc2 is returning unique constraint (CONSTRAINT_NAME) violated. I am very much confused why this error is coming.
What is the default key created when a primary key is created in a table ?
View 1 Replies View RelatedI have the following 3 columns in my VERSIONS table.
MAJOR
MINOR
MICRO
The MAJOR,MINOR and MICRO columns create a unique composite primary key. I need to query out the last version by doing the following 3 queries and combine them.
select max(major) as max_major from versions
select max(minor) as max_minor from versions where major = :max_major
select max(micro) as max_micro from versions where minor = max_minor and major = max_major
Is there any way I can query out max(major),max(minor),max(micro) in a single query.
we apply partitioning concept on a table which don't have any primary key ?
I just want to add one more field as primary key with some sequence generated values while partitioning ? Is it possible ?
On my system 2 oracles are installed for different applications one having version 8.0 & other 10.0.
The oracle 10.0 is required for Windchill application. When I am trying to access the sqlplus by windchill shell it access the Oracle 8.0 sqlplus. how to set one oracle as primary on system so i am able to access the oracle 10 sqlplus in windchill shell.
PM_KEY.. PCN....... JOBNO...PM_VERNO
20......... 137....... XX23..... 0
21......... 137....... XX24..... 1
22......... 137....... XX17..... 2
23......... 137....... XX81..... 3
22......... 137....... XX90..... 2
I have a dilemma......the constraint was disable somehow in my table of about 900,000 records which allowed the insertion on duplicate primary keys as well as duplicate records. I've managed to get rid of the duplicate records, but I haven't quite figured out how to update the primary key and version number. I've tried the following but
UPDATE TABLE
SET PM_PM_KEY=(MAX(PM_KEY)+1), PM_VERNO=(MAX(PM_VERNO)+1)
WHERE TBLDATE= MAX(TBLDATE)
ORDER BY TBLDATE ASC
GROUP BY PCN;
The query is failing with
Error at Command Line:2 Column:19
Error report:
SQL Error: ORA-00934: group function is not allowed here
00934. 00000 - "group function is not allowed here"
*Cause:
*Action:
what is the difference between primary key and natural key ?
View 3 Replies View RelatedI have a table called TRANS, and a primary key field tran_id. How would i check if there is a record matching tran_id 'DUP7927' ?
View 25 Replies View Relatedi need to set primary key for a column consists of the datatype date.
View 5 Replies View RelatedHow can i retrieve which tables have composite primary keys, and only one of the primary key columns is a foreign key to another table?
Like:
CREATE TABLE club (
clubId NUMBER,
name VARCHAR(20) NOT NULL,
PRIMARY KEY (ClubId)
);
CREATE TABLE team (
teamid NUMBER(10),
clubid NUMBER(10),
teamname VARCHAR(10) NOT NULL,
PRIMARY KEY (teamid, clubid),
FOREIGN KEY (clubid) REFERENCES club (clubid));So in this case, the team table
I have a table say EMP with 2 fields ID and Name, with ID being the primary key. The name of the primary key constraint is ID_PK.Now my scenario is :
1. Rename the table EMP to EMP_TEMP;
2. Create an empty table EMP
3. If (data successfully loaded into EMP)
{
Drop EMP_TEMP;
}
else
{
Drop EMP;
Rename EMP_TEMP to EMP;
}
The problem here for me is the primary key constraint. When I am in 2, I cannot create the primary key constraint again since the old one is still in tact. If I go ahead to drop the original pk constraint and re-create a new one in 2, then in case of else part , I need to get the constraint again while renaming the original table.
I am working on a new project in OBIEE. I am asked to do the data modeling in the database using oracle sql developer. I have to create the joins based on the requirements. I have the tables created already. But the primary keys for few tables are not defined for few tables. PK-FK joins are also not done properly.
My questions are
(1) If I have to define the primary key for the existing tables can I do that using the alter table command or should I create the table all over again and then define it?
(2) If I have to make the changes in the existing PK-FK joins how do i go about doing that?