SQL triggers, how to invite records deleted from one table to another table

Updated on technology 2024-03-04
11 answers
  1. Anonymous users2024-02-06

    In the deleted table of the trigger, the deleted row is saved. Just take it out and insert another table.

    Example: create trigger tri delon table name for delete

    as declare @id int

    declare @name varchar(20)select @id = id, @name = name from deleted -- retrieve the deleted data.

    insert into tablename2 values(@id = id,@name) - Inserts another table.

  2. Anonymous users2024-02-05

    As follows: Create trigger del kh on dboCard Info Sheet after delete as insert into Deactivated Card Info Sheet (kh,xm,xb,kmc,sjhm,sysycs,fxrq,dqrq) select kh,xm,xb,kmc,sjhm,sysycs,fxrq,dqrq from deleted ==== When the trigger is activated, the deleted records will be placed in the deleted temporary table. This table can only read, The structure is directly responsible for deleting the table, so export this data directly to the table you need!

  3. Anonymous users2024-02-04

    1.Adopt not exists fast execution speed delete from t ad where not exists (select 1 from t ad play where t = t ad )2Slow execution with not in delete from t ad where n ad not in (select n ad from t ad play).

  4. Anonymous users2024-02-03

    delect from Table B

    where exists(select 1 from A table A where a.)Form number = bForm number and to char(a.Billing time,'yyyy') <2013)

  5. Anonymous users2024-02-02

    If table A is a sale master, and table B is a sale detail idea, first find out the order number of table A in 2013.

    Then delete these tracking numbers from Table B.

    delete sale_detail

    where id in (select id from sale_master where year(date)<2013 )

  6. Anonymous users2024-02-01

    In SQL, if you delete a record in a table and take a condition from another table, the two tables must be the primary and foreign key relationships

    For example, create table aa

    aaid int primary key,aadate varchar(50),create table bb

    bbid int primary key,bbname varchar(50),bbaa int foreign key references aa(aaid )

    If AA has 10 data records and BB has 10 data, delete one of the BBAA data in BB.

    delete bb where bbid in (select aaid from aa where aadate <'2013-01-01')

  7. Anonymous users2024-01-31

    delete from b where form number in (

    select form number from a where billing time<=2013....

  8. Anonymous users2024-01-30

    delete table B where form number in (select form number from table A where billing time<.)'2013-01-01')

  9. Anonymous users2024-01-29

    This is relatively simple, after the syntax of the trigger is clear, write a before insert trigger, and then write the delete statement to the statement block.

  10. Anonymous users2024-01-28

    delete 'Temporary table name' where (e,f,g) in(select b,c,d from test);

    Changed to. delete 'Temporary table name' where (e,f,g) in(select ,,from 'Temporary table name' x,test y where and and

  11. Anonymous users2024-01-27

    Two ways: 1. Use SQL statements directly, and insert into table ......from……

    2. Create a trigger in the current table and delete the data in the table when you add it.

Related questions
13 answers2024-03-04

In the case of sqlserver, you can write a database-based trigger in which you can get the name of the table to be operated on, and sqlserver prohibits the user from deleting the specified table. >>>More

10 answers2024-03-04

select top(1)* from table_name order by update_time desc

My idea is to find the result of the first place in descending order of modification time, isn't it? >>>More

9 answers2024-03-04

Draw a zone A and zone B, next to the zone a pokemon to return to player X, and put a hero C to return to neutral. >>>More

14 answers2024-03-04

EventTrigger's actions are not actions, and actions can support multiple actions >>>More

15 answers2024-03-04

The road is also taken step by step, and it is also a result of the current decision of one's own choice. At any time, there is no way to open the window and see, it is another angle. Really, you have to believe that there is no end to it. >>>More