I want delete an record by 'url' key match in this table:
$sql = "CREATE TABLE IF NOT EXISTS Articls
(
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
alias INT(10) UNSIGNED NOT NULL,
title VARCHAR(254) COLLATE utf8_persian_ci NOT NULL,
url VARCHAR(2083) COLLATE utf8_persian_ci NOT NULL,
UNIQUE (alias),
UNIQUE (title),
) DEFAULT COLLATE utf8_persian_ci";
but After that I want delete all relative tags name in 'Tags' table too!
$sql = "CREATE TABLE IF NOT EXISTS Tags (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
alias INT(10) UNSIGNED NOT NULL,
name VARCHAR(256) COLLATE utf8_persian_ci NOT NULL,
state INT(2) NOT NULL DEFAULT 1,
created INT(11) NOT NULL,
FOREIGN KEY (alias) REFERENCES Articls (alias)
) DEFAULT COLLATE utf8_persian_ci";
Can I do it just with mysql query?
I do it with some php/mysql now:
1-get alias where url = 'my url' in Articls.
2- delete all record in Tags table.
- delete target record (where url = 'my url') in 'Articls' table.
You should use 2 queries
Or you can use cascade delete.
Instead:
you need:
in this case each time when you delete row from Articls appropriate rows at Tags will be automatically deleted.