I have a huge table that i am querying and i just wanted to know how do i find the composite keys of a table as this table does not have a primary key however it contains an auto incremented id.
The table looks like this :
I am a beginner to SQL so any help will be appreciated thanks.
Related
Could someone please help me understand how to populate the fact table with Surrogate keys from dimensions using SSIS?
I load my dimension tables and assign for each a surrogate key. I want to add these surrogate keys to my fact table but I don't know from where to start.
You just join your fact source record to the relevant dimension tables and get the surrogate keys, which you then insert into your fact table
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.
I read that we cannot create a primary key on a column in a Hive table. But I saw the below DDL in some other place and executed it. It worked without any problem.
create table prim(id int, name char(30))
TBLPROPERTIES("PRIMARY KEY"="id");
After this I executed "describe formatted prim" and got to see that a key is created on the column ID
Table Parameters:
PRIMARY KEY id
I inserted two records with same ID number into the table.
insert into prim values(1,'ABCD');
insert into prim values(2,'EFGH');
Both the records were inserted into the table. What baffles me is that we cannot give the PRIMARY KEY in the create statement which I can understand, but when given in TBLPROPERTIES("PRIMARY KEY"="id") how different is it to the primary key in RDBMS.
PRIMARY KEY in TBLPROPERTIES is for metadata reference to preserve column significance. It does not apply any constrain on that column. This can be used as a reference from design perspective.
I have a table which needs to be ingested from Oracle source to Greenland target using ETL tool talend. The table is huge , hence we want to load the data on daily basis incrementally. The table doesn't have any primary or unique key.
Table has date column, I am able to get both inserted/updated records from last update date but to insert that data, we need a primary key.
Any solution on how to load the data without using a primary key?
You need to define your key in talend in the schema of the component that insert into your target table, like this :
And you can use this key to update your table, in the advanced settings of the same component, activate the check box use fields optins and select your key :
This is tested and worked fine against Oracle table that does not have primary key, and it should work for you.
I'm experiencing some difficulties with foreign key constraints. I have a table 'ADDR', whose FK constraints are:
I'm writing a UDF on Hive to analyze constraints for a target table, but I don't have any clue how to implement this.
I tried below sql script to analyze constraints FK4_ADDR, but it didn't returned empty because column CTRY_CD was also a foreign key referencing table CTRY_PSTL and CTRY. So is there any other ways to check FK integrity? Any help on this would be greatly appreciated!
select
distinct
SRC_SYS_CD,CTRY_CD,CTRY_SB_DVSN_CD
from user.ADDR t
where t.src_sys_cd='123'
minus
select
distinct
SRC_SYS_CD,CTRY_CD,CTRY_SB_DVSN_CD
from user.CTRY_SB_DVSN t1
where t1.src_sys_cd='123'