Monday, 27 April 2015

Delete Action is AX:

This Deletion are used for deleting the records from the tables.This delete action are mainly used to avoid the inconsistent data in database. the deletion are mainly used when the table data are interdependent on one other for the consistent information about a record. 

Lets Take a example:

Table one : This table has three column that is account number as account,name and city.







accountnamecity

1011sachinMumbai

1012dravidindore

1013dhoniranchi

1014kohlidelhi

1015sehwagNajafgarh

1016rohitNagpur






Table two: This table has three column that account, car id and car name and this account number is depend on the table one.







accountcar idcar name

1011101BENZ

1011102BMW

1011103Audi

1012101BENZ

1012102BMW

1012103Audi

1013104jaguar

1014101BENZ

1014103Audi

1015101BENZ

1016101BENZ









The table two is depend on the table one for consistent data.so if you delete the records in table one like if u have deletes records for "dravid" so all the records with 1012 will be orphan data.

The above tables are relation with each other so this can treated as parent and child tables.so the table one is the parent table and table two is the child table.

So we have how the deletion maintains the consistences of data in data base so now lets us see how many types of delete action are there in ax.

Types of Delete Action:

1.None
2.Cascade
3.Restricted.
4.Cascade + Restricted.

The are the delete action present in AX.

NONE: This delete action will not take any action in the tables.

Cascade : This cascade is used to delete the related data in both the table so let take a Example:

When we define the delete action in the parent table as cascade means in the table one.so lets see what happens.

so when you want delete a record say we want to delete the rohit records so select the rohit record in the table and press alt+f9 it will prompt a alter message saying are you sure you want to delete after pressing the yes both the table will be deleted.

Result will look like this in table one 






accountnamecity

1011sachinMumbai

1012dravidindore

1013dhoniranchi

1014kohlidelhi

1015sehwagNajafgarh






Result will look like this in table two:






accountcar idcar name

1011101BENZ

1011102BMW

1011103Audi

1012101BENZ

1012102BMW

1012103Audi

1013104jaguar

1014101BENZ

1014103Audi

1015101BENZ





The above examples give a how the delete action is taken place.

Restricted : This action is when you want to restrict the deletion of the record if it has any dependence on the other table.

So let see with a example:

So if we define the restricted delete action on the table and we are trying the delete records so let see what will happen. 

Data in Table one as following:






accountnamecity

1011sachinMumbai

1012dravidindore

1013dhoniranchi

1014kohlidelhi

1015sehwagNajafgarh

1016rohitNagpur





Data in Table Two as following:






accountcar idcar name

1011101BENZ

1011102BMW

1011103Audi

1012101BENZ

1012102BMW

1012103Audi

1013104jaguar

1014101BENZ

1014103Audi

1015101BENZ





As you can see the "rohit" 1016 record is not having any record in table two so when you try to delete the 1016 record will allow you to delete the record.

When you to try to delete the ''sachin" record it will through a error saying that you have dependence on the table two. so first delete the those records and after that it will allow you to delete the records in the table one.

Cascade + Restricted:This option is mainly used when deletion is more than one level.That means as we have seen early example it was between parent and child tables so when you have more than two table like we have grand child table and there are also dependent one table one than we have to go for cascade/restricted delete action.