The database has two consumption-related tables, xfjl (primary consumption record) and xfxxjl (consumption detail record). The two tables have a master-slave relationship, however, I have not established the relationship between tables in the database.CodeDirectly write SQL statements, such as the delete from xfjl where condition. There is no condition for clearing the original data. You can directly delete all the records in the table, and then add a time period to delete only the data in a certain time period, but the xfxxjl table does not have a consumption time, all records are recorded in xfjl. How can I delete the qualified records in the xfxxjl table?
Try the statement: delete from xfxxjl inner join xfjl on xfxxjl. xfxxjl_zd = xfjl. xfjl_zd where xfjl. Limit>: dt1 and xfjl. xfjl_xfsj <dt2; Syntax Error!
Delete xfxxjl from xfxxjl inner join xfjl on xfxxjl. xfxxjl_zd = xfjl. xfjl_zd where xfjl. xfjl_xfsj>: dt1 and xfjl. Limit <dt2; Syntax Error!
After searching for half a day in Google, I found that SQL Server mostly uses triggers. Continue searching and finally find one: Use the integrity of the reference!
You don't have to write anything in the code. You just need to establish the relationship between the two tables. The original post content is as follows:
Take Access 2003 as an example: You can create a relationship between tables in the tool menu relationship. In the edit relationship dialog box, there is an implementation reference integrity. Check it, below is a list of "cascade update related fields" and "cascade Delete related records". Isn't it checked! As shown in the preceding table, you can create the master table idname = slave table idname, and then edit their relationships! OK?