Is constraints important for for select? - oracle

I have table on database1 with some constraints like primary key and check. I have all my logic on this database for insert data in this table, then I need this table on database2 to just select data.
So I made replication for this table using database links (select data from database1 insert data into database2), from database1 to database2. I made this table on database2 without constraints, I just create index on the fields which I need in my select's where clause.
Is there any reason why I need to create same constraints(primary key and checks) on database2, when I need this table just for select on this base? Maybe it gets performance difference?

Is there any reason why I need to create same constraints(primary key
and checks) on database2, when I need this table just for select on
this base? Maybe it gets performance difference?
There is no need to have same constraints on your table in database2 until you are not populating that table other that source table of database1 which is having constraints. This is because all validation is already been done while inserting records to table of database1. There is no performance related improvement with constraints addition. Indexing table of database2 will help in performance.

Related

How to create table in Hive with specific column values from another table

I am new to Hive and have some problems. I try to find a answer here and other sites but with no luck... I also tried many different querys that come to my mind, also without success.
I have my source table and i want to create new table like this.
Were:
id would be number of distinct counties as auto increment numbers and primary key
counties as distinct names of counties (from source table)
You could follow this approach.
A CTAS(Create Table As Select)
with your example this CTAS could work
CREATE TABLE t_county
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE AS
WITH t AS(
SELECT DISTINCT county, ROW_NUMBER() OVER() AS id
FROM counties)
SELECT id, county
FROM t;
You cannot have primary key or foreign keys on Hive as you have primary key on RBDMSs like Oracle or MySql because Hive is schema on read instead of schema on write like Oracle so you cannot implement constraints of any kind on Hive.
I can not give you the exact answer because of it suppose to you must try to do it by yourself and then if you have a problem or a doubt come here and tell us. But, what i can tell you is that you can use the insertstatement to create a new table using data from another table, I.E:
create table CARS (name string);
insert table CARS select x, y from TABLE_2;
You can also use the overwrite statement if you desire to delete all the existing data that you have inside that table (CARS).
So, the operation will be
CREATE TABLE ==> INSERT OPERATION (OVERWRITE?) + QUERY OPERATION
Hive is not an RDBMS database, so there is no concept of primary key or foreign key.
But you can add auto increment column in Hive. Please try as:
Create table new_table as
select reflect("java.util.UUID", "randomUUID") id, countries from my_source_table;

Populating Tables into Oracle in-memory segments

I am trying to load the tables into oracle in-memory database. I have enable the tables for INMEMORY by using sql+ command ALTER TABLE table_name INMEMORY. The table also contains data i.e. the table is populated. But when I try to use the command SELECT v.owner, v.segment_name name, v.populate_status status from v$im_segments v;, it shows no rows selected.
What can be the problem?
Have you considered this?
https://docs.oracle.com/database/121/CNCPT/memory.htm#GUID-DF723C06-62FE-4E5A-8BE0-0703695A7886
Population of the IM Column Store in Response to Queries
Setting the INMEMORY attribute on an object means that this object is a candidate for population in the IM column store, not that the database immediately populates the object in memory.
By default (INMEMORY PRIORITY is set to NONE), the database delays population of a table in the IM column store until the database considers it useful. When the INMEMORY attribute is set for an object, the database may choose not to materialize all columns when the database determines that the memory is better used elsewhere. Also, the IM column store may populate a subset of columns from a table.
You probably need to run a select against the date first

Move an Oracle table to being Index Organised

I have an Oracle table in a live production environment and the table is over half a gig in size. Is it possible to change this normal Oracle table from being heap organised to index organised or is this only achievable by moving the data from this table to another new table which is index organised? Either way, I would be grateful if you could you please list the steps involved in this procedure.
There is no way to alter a table to make it index-organized table. Instead you can redefine the table(using DBMS_REDEFINITION)or can create new table using CTAS.
Example:
create table t2 (
id number, first_name varchar2(20),
constraint pk_id primary key (id)
)
organization index
as select * from t1;
I never used DBMS_REDEFINITION but with CTAS it is not only step to create table if it is production.
List all indexes, constraints, foreign keys and so on based on system views
Prepare create index, constraints and alter foreign keys statements. prepare list of triggers, procedures that depend on table.
Create table as select (consider lock before that step if you can)
Create all indexes, constraints with prepared statements from step 2
Swap table names and swap foreign keys (this step may cause some errors if you hit insert on foreign keys (if you expect it on that time you should lock the table and tables referencing by foreign key).
Compile dependent objects from 2 (if you locked tables unlock here)
(if you haven't locked on step 3) Insert into table select * from new minus select * from old; or if you have timstamp of inserting row just insert new rows.
I hope the list is complete.

How to use Oracle Dblinks that honor referential integrity constraints?

I have a need to move data between two identical Oracle databases. I have figured out how to use dbLinks to achieve most of it. Here is my confusion.
Lets say I have Table A, which refers to Table B present in DB1 and also similar structure in DB2. Is there any way possible for me to create db link to move data between Table A in DB1 and DB2 which automatically copies the relevant data in Table B to support referential constraints (without me having to spell it out)?
Thanks
Kay
A simple approach would be to duplicate the foreign key and check constraints in DB2.TableB in the destination table DB1.TableA.
A little more work is to create a materialized view in DB1 along the lines of
Create Materialized View TableA as Select * from TableB#DB2.link;
Refresh as required... You cannot do a fast refresh on a remote database but very few applications require true real time synchronization.

create a backup table with all parameter

I'm trying to move the data from one table TABLE5 another one TABLE5_BKP.
CREATE TABLE TABLE5_BKP AS SELECT * FROM TABLE5;
The table created and the data moved. when I checked the constraints,
The primary key,foreign key etc are not generated but all other constraints like,
SYS_C2211111 Check "COLUMN1" IS NOT NULL
etc are created. What to do in this case? Need to create the primary key,foreign key etc separately? What about indexes and other parameters, which I was not able to check.
You can't implicitly create PK, FK, Indexes, etc. just using
CREATE TABLE tablename AS SELECT *...
You have to specify them after creating. Also I suggest you to use oracle tools, like exp/imp, data pump, etc. if you want to move the database structure from one database to another.

Resources