Oracle SQL Developer - using foreign keys - oracle

First of, this is a pretty basic question but I cant seem to find a basic tutorial on how to use the software.
If i have a table named COUNTRY with the field region_id
and then another table named REGION with a primary key as region_id.
I want to set the region_id field in COUNTRY table as a foreign key.
Are the following steps correct?
Go to constraints, add a new foreign key.
Select COUNTRY as table
Change local column to region_id
![enter image description here][1]
Am I doing it correctly? if not, where am i going wrong

Yes, This is the correct procedure.
If you want your foreign key to have additional behavior (e.g., ON DELETE CASCADE), you can use the "on delete" drop-down in the wizard.

I cant seem to find a basic tutorial on how to use the software.
Have you looked at the Oracle Learning Library for SQL Developer tutorials?
If you search for: Getting Started with Oracle SQL Developer 4.0 you will find a tutorial that gets you up and running SQL Developer, this tutorial includes how to create Foreign Key Constraints.

Related

How to insert data into destination table without having any primary key in Talend

I am using talend for ETL I don't have enough experience in this, I am having two tables for example- account and account_roles account table is having id, name, password etc fields and account_roles table is having account_id which is f.k to account table's pk. and one more field.
Both the fields in account_roles are having duplicates, I want to save account_roles in destination with update and insert logic using talend.
But I am getting error as I don't have any table that can be treated as primary key in the account_roles table, so talend can't update or insert it.
How I deal with this situation I tried tDBOutput advance option use_field_option but still it requires unique entries.
Is there any possible solution to this issue, I also want to know if I can make table Foreign key in the account_roles table will it work then? If yes then How to make F.k in talend OPen studio is my second question.
Attaching Snapshots of my tables and tMap below -
I want to know the way I can put my tables into database if I don't have any primary key! Kindly help me.
First question
I think you should place the primary key in the physical account_roles table. Talend will use the key indication of the dbOutput component, and the physical key of the table.
In order to delete duplicates rows, you can also use a tUniqRow before the dbOutput: The key you indicate in the UniqRow is not directly linked to the database; this is only the key on which tUniqRow will be based.
Second question
It's not possible to delegate the f.k. verification to Talend. But you can do this verification in your database by placing foreign keys in your table. If an id is not present in the reference table, the database returns an error that is returned by Talend.

How to create form/report on a table which has only primary keys?

Im trying to create a form with a report on a table that has only primary keys.
I have a table:
create table WRITE
(
author varchar(5) references AUTHOR (authorcode) ,
book varchar(20) references BOOK (bookid),
primary key(author,book)
);
I'm using APEX Application Builder to create a form on a table with report;
But When I get to the "Select the columns to include in the form" , I have no options to select from because I only have unique primary keys in my table.
Which Apex version is it? I've tried it on apex.oracle.com which uses 19.1 and it doesn't have that problem.
Anyway, two options I can think of:
temporarily drop primary key constraint
then create report + form pages
after you're done, create the primary key constraint once again
create an interactive report (using the wizard)
then create a form, manually adding items
this isn't as easy as it looks like because you'll have to create all processes as well (initialization one, along with automatic row processing)
I presume that the first option is a lot simpler.

How to apply both on delete and on update cascade simultaneously in oracle12c?

I'm beginer and I'm working on oracle 12c database so, In my database project I want to apply cascade on delete and on update simultaneously as i did in mysql but when i apply tha same technique in oracle it show me the error so how can i do that?
There is no ON UPDATE CASCADE on Oracle. While you can probably argue updating a table's primary key is valid in SQL, you probably should not, hence the decision of Oracle not to implement it.
More info here:
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5773459616034
EDIT: As discussed in comments below, think of that constraint as a way Oracle prevents people from doing something wrong (updating primary keys).
The correct way to handle the case of a primary key that might be updated is to create a separate field that will act as the surrogate primary key. The surrogate key, of course, is immutable.
The danger of using a natural key as primary key is discussed there.

How to specify foreign keys to a table in Parse.com

I take Trains as one table and passenger as other table.
train table has train_no, train_name.
Passenger table has pnr and train_no.
i would like to create train_no as foreign key in passengers table.
please provide sufficient code for it..
i am rookie in it.
Thanks in advance
Parse is MongoDB like Object DBMS.
Concept of FK constraints is not available in Parse.
In order to use referencing you have to use Pointers. Although you can write some code for having FK constraint satisfaction (One easy option for the same is to use beforeSave feature of Cloud Code.)

Is there a table designer for VS2010 database project?

Am I missing something here? It seems that the only options to create a new table in a database project in VS2010 is:
Create a table object as a file, then create all constraints (defaults) as separate files, then create each index as a separate file, and primary key as a separate file and on and on...
Or
Create the entire table schema using the table designer in SSMS and then use the schema compare tool to create a single monolithic file of SQL statements for each element of the table and copy each block of code to a newly created file in VS.
This question was asked 2 years ago and I'm hoping the answer has changed.
Please tell me there's a hidden table designer for the database project in VS2010 that I have just overlooked.
I'm pretty sure there isn't one!
Can I ask why you need a table designer over creating and modifying creation script files for your new objects? Is there anything that this doesn't give you that a designer would?
I just noticed that VS 11 Beta now includes a designer, although it is rough around the edges (relationships, for example, still need to be typed by hand).
The way I use the database project in VS2010 is:
Create everything with SQL Server Management Studio.
Synchronize it into my database project.
When I need to change something, do it in SQL Server Management Studio.
Use Schema Comparisons to synchronize your database project.
Wow... can't believe no one has taken the time to answer this in all this time. Here's a sample of table creation script with some simple constraints.
CREATE TABLE [User]
(
UserID INT NOT NULL IDENTITY (1,1),
UserName NVARCHAR(20) NOT NULL,
UserPassword NVARCHAR(20) NOT NULL,
EmailAddress NVARCHAR(50) NOT NULL,
Location NVARCHAR(100),
MobileNumber VARCHAR(10),
CreatedDate DATETIME NOT NULL
CONSTRAINT User_CreatedDate_DF DEFAULT (GETDATE()),
CONSTRAINT User_UserID_PK PRIMARY KEY CLUSTERED (UserID),
CONSTRAINT User_UserName_UQ UNIQUE (UserName),
CONSTRAINT User_EmailAddress_CK CHECK (EmailAddress LIKE '%#%.%'),
CONSTRAINT User_MobileNumber_CK CHECK (MobileNumber LIKE '[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9]')
)
You can use functions to embed in your check constraints, but again, this is a simplistic exaxmple.
As I commented here, the VS2010 reference states that there exist a Table Designer in this document.
But for some reason, no matter what kind of project I create (Server project 2008/2005, database project 2008/2005) I can't get the Table Designer being shown.

Resources