Irwsoft Data Framework

Delete Record/s of Multi-Tables in MySql
Brief Information
DataschemaTable and View.
TopicsDelete Multi-tables syntax.

MySql provides escalate delete syntax to delete records from multi tables using relation tables.


  • Supported by MySql provider.
  • Ultimate Edition feature only.

Example : Delete record/s in Person and related Country table with FirstName equal to 'Andy'.

C# code
// Must declare and initiate a new instance of PersonTable class.
PersonTable person = new PersonTable();

// Must declare and initiate a new instance of CountryTable class.
CountryTable country = new CountryTable();

// using MySqlDelete to delete multi tables.
MySqlDelete delete = new MySqlDelete(person);
// Don’t forget to set connection string !
// NOTE : it is optional if the data-schema class using default connection .

delete.ConnectionString = "...";  // [OPTIONAL]

// Set the relation to Country table
delete.Tables.InnerJoin(country).On.Compare(person.CountryId, ComparisonOperator.Equal, country.CountryId);

// Set where condition FirstName = "Andy"
delete.Where.Compare(person.FirstName, ComparisonOperator.Equal, "Andy");

// You can specify target tables to delete with code below,
// delete.Filter(person);
// since not specify the target tables then this will delete all Person records with the FirstName is Andy and
// related Country records

// Execute the query and return number of rows affected by operation.
int r = delete.Execute();

Related Topics :

Irwsoft Data Ultimate Edition provides all enhanced features of Irwsoft Data Framework and support from irwsoft.