value of a column in table A s connected to another column in table B - mysql-workbench

I have two table Claim and Claimlog
PK.Claimlog is connected to ClaimID.Claim
how do I make them connected?

Related

Turning cells from row into a column and marking them as a primary key? (Postgresql)

So my following table is like this:
Tower_ID|...|Insulator_ID_01|Insulator_ID_02|...|Insulator_ID_12|
Tower_01|...|01_Unique_ID_01|01_Unique_ID_02|...|01_Unique_ID_12|
Tower_02|...|02_Unique_ID_01|02_Unique_ID_02|...|02_Unique_ID_12|
Then the idea is to have a single table for every insulator that belongs to towers in this specific line (towers in this line is the table). But the only way I know how is to have a table for each column of insulators. Is it possible to create a single table with relationships which would store Insulator_ID_01 to Insulator_ID_12 in a column before going into the next row of the and doing the same?

Is it possible, when i save a data in postgresql table, automatically, id of record save in another table without trigger

I have 2 tables. First table is called Person. Second table is called PersonRule. Person table has much columns. But PersonRule has just 2 columns. In the person table, there is a column called ruleid. The column at the same time, there is in the PersonRule table. Is it possible, when i insert to data Person table, i want to automatically create a record in PersonRule table without trigger.?
And in PostgreSQL how can i do this.?

How to copy a Specific Partitioned Table

I would like to shift data from a specific paritioned table of parent to separate table.Can someone suggest what's the better way.
If I create a table
CREATE TABLE parent columns(a,b,c)partition by c
c Type is DATE.
CREATE TABLE dec_partition PARTITION OF parent FOR VALUES FROM '2021-02-12' to 2021-03-12;
Now I want to copy table dec_partition to separate table in single command with least time.
NOTE: The table has around 4million rows with 20 columns (1 of the column is in jsonb)

Doing math while updating Postgresql database

I am working on a small invoicing solution and I Need to add a column to store the price of one unit. I already have a column for total for all the units and the quantity in the db.
My question is, how can I add this column and populate it with accurate numbers? I know that formula will be:
total_col / quantity_col = unit_col
Here is an example of populating a new column with some derived value:
create table products (
total_col int,
quantity_col int);
ALTER TABLE products ADD COLUMN unit_col numeric(10,2) default null;
update products set unit_col=total_col::float / quantity_col;
You'll want to set up a trigger to keep this column up to date. This is what is know as a persistent, computed column.
Another, perhaps better, solution is to set up a view that has the computed column you want:
create table products (
total_col int,
quantity_col int);
create view productsWithUnitCol as
select *, total_col::float / quantity_col as unit_col from products;
Assuming your database is called mydb, the table is called invoices, and the column is unit_col I would do the following:
Connect to your postgresql database via command line, typically psql mydb and then the following:
ALTER TABLE invoices
ADD COLUMN unit_col real;
UPDATE invoices SET unit_col = total_col/quantity_col;

Hive partitioning external table based on range

I want to partition an external table in hive based on range of numbers. Say numbers with 1 to 100 go to one partition. Is it possible to do this in hive?
I am assuming here that you have a table with some records from which you want to load data to an external table which is partitioned by some field say RANGEOFNUMS.
Now, suppose we have a table called testtable with columns name and value. The contents are like
India,1
India,2
India,3
India,3
India,4
India,10
India,11
India,12
India,13
India,14
Now, suppose we have a external table called testext with some columns along with a partition column say, RANGEOFNUMS.
Now you can do one thing,
insert into table testext partition(rangeofnums="your value")
select * from testtable where value>=1 and value<=5;
This way all records from the testtable having value 1 to 5 will come into one partition of the external table.
The scenario is my assumption only. Please comment if this is not the scenario you have.
Achyut