MS Access after insert event - ms-access

I have 2 tables in access, A and B, both with a case ID field and several other fields. I am trying to set up a process where if I insert a record in A with a new case ID, only the case ID of that record inserted in table A gets populated in table B.
I have tried using an After Insert event macro of table A with a create a record into table B action which should create a record with the case ID in table B. This work fine if none of the fields apart from the Case ID in table B are required. However, if I have other fields that are required in Table B, the create a record into table B does not happen upon insert into Table A.
How do I fix this issue? Thanks in advance!

Related

How to remove duplicate records from multiple tables in MySQL

I have a situation like this:
I have 3 tables, for example:
table phones
table computers
table printers
Every table has the same column named "Address" and every column has the same record "06-00-00-00-00-00" (a duplicate record).
Now, I was wondering if it's possible somehow to check all the records from all of the tables and delete the duplicate records from table "computers" and table "printers" but leave the record in table "phones"
In other words: Delete all the duplicate records from all of the tables except from one chosen table (in this case table "phones").
Thanks a lot.
For deleting records,
DELETE TABLE TABLE1
WHERE ADDRESS = (SELECT ADDRESS FROM TABLE2)

Inserting records from one table to another, but on a 'dynamic' table

Let's assume that I have a table 'A' which holds the client's orders - so it is updated within every second - and I want to copy every record of it and put it in a new table 'B'.
How would you manage to do that knowing that every moment new records are added/updated and you cant just simply 'copy + paste' it (cause in that moment new records will be added/updated) ? Do you know any way to do that ?
Please try:
CREATE TRIGGER trigger_INSERTItemDetails ON TABLEA
FOR INSERT AS
BEGIN
INSERT INTO
tableB
(
colB1,
colB2,
colB3
)
SELECT
colA1,
colA2,
colA3
FROM
INSERTED
END
and make sure that you are inserting a NOT NULL value to column Primary column of table.
Similarly you created for UPDATE and DELETE actions, so you don't need to copy separately because all actions which happen in TableA it will affect TableB also.

Unable to copy column data from one table to another in MySQL

I have one table in which each row (event) has a unique (integer) ID. I have another table, which includes the same events, and I am trying to copy the ID column from the first table to the next with no luck. I have tried creating a blank column in the second table first and I have tried it without having a blank column prepared. When I run my queries, it will spin and say that it was successfully executed, but the column in the second table is never updated.
Here is my query:
insert into games2 game_id
(
select games.game_id as game_id
from
games2 join games
on games2.DATE = games.DATE and
games2.HOME = games.HOME and
games2.AWAY = games.AWAY
)
INSERT INTO Item (Name)
SELECT Item
FROM IName
I think this source would help you out Copy from one column to another (different tables same database) mysql

Automatic Update for database rows based on changes in another table

I have a scenario that requires a value in a row of a table to be updated automatically whenever a row has been added or deleted in another table. I'm not sure how to do it.BTW I'm using phpmyadmin in order to manage my database. Thanks in advance.
pages Table
------------
page_no
no_of_choices
choices Table
-------------
page_no
choice_no
When I add a choice with choice number 1 and page_no, then the table page which has the row, page_no=1 should be updated with no_of_choices=no_of_choices+1
You can use triggers.
For example:
CREATE TRIGGER `test1`
AFTER INSERT ON `tbl1`
FOR EACH ROW SET NEW.upd_fld = new_value
Similarly could be done for delete.
You can also create triggers from phpMyAdmin
TABLE A: page_no, no_of_choices
TABLE B: page_no, choice_no...
With a relational database you very rarely want to have duplicate data. If something breaks at some point, you won't know which to trust - the rows in Table B, or the no_of_choices in Table A. A better solution is to do one of the following (depending on which table you are querying):
SELECT COUNT(no_of_choices) FROM B WHERE page_no = 1
or
SELECT A.*, COUNT(choice_no) AS choice_no FROM A LEFT JOIN B USING(page_no)
You get the same result, but now you have one record to go off of, so you won't have inconsistent data.

Need help with simple mysql triggers

I have one table (TABLE A) in my mysql database which has the listed fields:
row1_id - PK
row2_id - PK
row3_data
What I would like to do is, every time a record is inserted or updated in table A, I would like to call a trigger to write me the new information of table A in another table, TABLE A_LOG, which has the following fields:
row0-modification-id - PK
row1_id (from table A) - PK
row2_id (from table A) - PK
row3_data (from table A)
the Table A_LOG should then have 3 PKeys, two from the new inserted/updated record of table A and other that indicates me the number of the modification (1, 2, 3..)
Thank you very much for your help.
Create TableA_Log to autoincrement row0-modification-id.
I bet you don't exactly need this table to have row0-modification-id AND row1_id and row2_id all as the PK.
CREATE TRIGGER dbo.trg_TableA_ins_upd
ON dbo.DatabaseName
AFTER INSERT, UPDATE
AS
BEGIN
INSERT INTO TableA_Log (row1_id, row2_id, row3_data)
SELECT row1_id, row2_id, row3_data FROM inserted
END