Postgresql question for changing data without effecting table - sql

Tables
The above image shows the table that I have created in postgresql.
Say if I create an account saying 'entertainment' and add 40 entries to it over a month
before realizing that I spelt it as entertainmunt.
so now, you'd want to rename that account, right?
With this table structure..
how should achieve that?

Related

Trigger vs Oracle Materialized View Log

I have a table person with columns of interest
id, ab_num, is_valid_act
The is_valid_act data is being modified by users many times.
We have been asked to build a service for a team that will only give them the changes that are happening on a is_valid_act column from person table and they can call X times a day.
The initial thought was to create a new table with the id, person_id, ab_num, is_valid_act. Then have a trigger for any time the person.is_valid_act column is modified.
Then the service can get the records where id > then the last id the other team is passing out. And we would manually seed their database.
But we worry about table becoming so big that they will lose performance.
Also, we could use the date based but we feel it like that could be error prone.
Another idea is to create a materialized view which only will get the newest records with Materialized View Log.
Any thought/ideas which way is better to go with?
Thank you

Possible to have a new table for every row in another table? (SQL)

The only way I can think of doing it, since what I want to do is have a database of all the companies, and their respective information, then have another database per each company that sorts their orders and jobs, Is there a cleaner way than creating a table for each element in the company list table? If not, how would I go about doing this?
create trigger on yourdb for insert
then inside the trigger
create table and insert int it the specific row
Your question is a bit confusing. It seems that you may want to add the company id as a key on all the relations that exist. This would allow you to keep various company information in the same table structure and select from it by filtering on the company id.

Loading a Union SQL View into access table

I'm trying to create an access table (with a Primary key) that loads in the data from a Union SQL view.
Im hoping there is a way of achieving this? Ive tried an append and create table queries which copies the data but still no primary key.
I've created a blank table with the fields i want but cant think how to import the fields from the view into it?
Am i better off loading the view into excel?
Any tips would be great!
thanks
I assume you are trying to turn this query into a table because the query takes a long time to run and the data don't change often. In which case this is fine. Otherwise you should really be using your query. And if having a PK is a problem (which it shouldn't be because you can't edit a union query) then you should explain more about what you are trying to do.
Anyway, to turn your query into a table you need to make a table with the columns in your query and add one more column which is an AutoNumber column. This is your PK. Then create your append query like normal. Don't append anything to the AutoNumber column, it will automatically populate itself when a new row is added.

general issue about creating views

I have got a rather basic question but I could not find a confirmation about it online. When you create a view like the one below
create view report AS
select employee_id
from employees
It will store the data in a virtual table. That's ok. But when you add additional employee ids AFTER you have created the view will they be displayed when you run the view again? Cuz what I need is basically some view that will display the latest records I have added in the tables. Is that possible?
Short answer is Yes, it will update....
Ok, so Views don't quite "store" data, they just present data in a different format or select certain columns from a table to create your own "view" of the data.
If you are just looking to find the most recent employee ids through a view, I would recommend adding a column with a created or modified date field defaulting to the date entered. Then have your table do an Order By the datefield descending and select only top few rows so you only get recent records. The way to do this is slightly different depending on if you are using SQL, Oracle, or MySQL.

How to create query to update records only when changes occur and to add new records that do not already exist

I am running a query that fetches data(records) form a linked table from another database.
The linked table is populated by users using a form remotely, like the web.
I created this piece of code that queries the data from the linked table into a new table, like this:
`INSERT INTO NEW_TBL(ENT_CUS_NUM, ENT_FIRST_NAME, ENT_LAST_NAME, ENT_ADDRESS1, ENT_CITY, ENT_STATE, ENT_ZIP, ENT_PHONE)
SELECT LINK_TBL.CUS_NUM, LINK_TBL.FIRST_NAME, LINK_TBL.LAST_NAME, LINK_TBL.ADDRESS1, LINK_TBL.CITY, LINK_TBL.STATE, LINK_TBL.ZIP, LINK_TBL.PHONE
FROM LINK_TBL`
Is it possible to modify this query so that it inserts new records from the link table if the record has not already been added, or update existent records
that have been modified? Example: Lets say a person changes their address, Can I update or bring over only their address without re-inserting their entire record because of an address change?
This is what confuses, I could write an update statement but modifying this querying so that it brings over new records or update records with changes is way over my head.
I would appreciate your input and help.
Guy
If you can designate a field as a unique key, you can use REPLACE INTO instead of INSERT INTO at least with mysql