Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:54:35+00:00 2026-05-24T13:54:35+00:00

I have a question about my database. I try to delete my database but

  • 0

I have a question about my database.
I try to delete my database but I understood that we need to clear the tables in a certain order.

I want to know how to do it with my database. In which order to enter my tables in my SQL file. I heard about the ON CASCADE DELETE thing and I don’t know either how to add records in my database (in order to be correct)

So, my question is : How can I delete, insert, update records in my database dynamically (not manually in PHPMYADMIN)

I know it’s much information I asked.

Here’s my code to help:

DROP TABLE IF EXISTS Panier;
DROP TABLE IF EXISTS Materiel;
DROP TABLE IF EXISTS Medicament;
DROP TABLE IF EXISTS ListePatient;
DROP TABLE IF EXISTS Patient;
DROP TABLE IF EXISTS Specialiste;
DROP TABLE IF EXISTS TelPers;
DROP TABLE IF EXISTS Personne;
DROP TABLE IF EXISTS Produit;
DROP TABLE IF EXISTS Telephone;
DROP TABLE IF EXISTS Adresse;

CREATE TABLE Adresse(
idAdresse   INT(100) NOT NULL PRIMARY KEY AUTO_INCREMENT,
num         INT(5) NOT NULL,
rue         VARCHAR(30) NOT NULL,
ville           VARCHAR(15) NOT NULL,
postal      VARCHAR(6) NOT NULL
)ENGINE=InnoDB;

CREATE TABLE Telephone(
idTel           INT(100) NOT NULL PRIMARY KEY AUTO_INCREMENT,
typeTel     VARCHAR(15) NOT NULL,
ind         INT(3) NOT NULL,
quartier        INT(3) NOT NULL,
num         INT(4) NOT NULL
)ENGINE=InnoDB;

CREATE TABLE Personne(
idPersonne      INT(100) PRIMARY KEY NOT NULL AUTO_INCREMENT,
nom             VARCHAR(15) NOT NULL,
prenom          VARCHAR(15) NOT NULL,
idTel               INT(100) NOT NULL,
idAdresse       INT(100) NOT NULL,
FOREIGN KEY(idAdresse) REFERENCES Adresse(idAdresse),
FOREIGN KEY(idTel) REFERENCES Telephone(idTel)
)ENGINE=InnoDB;

CREATE TABLE TelPers(
idPersonne      INT(100)NOT NULL,
idTel           INT(100)NOT NULL,
FOREIGN KEY(idPersonne) REFERENCES Personne(idPersonne),
FOREIGN KEY(idTel) REFERENCES Telephone(idTel)
)ENGINE=InnoDB;

CREATE TABLE Specialiste(
login           VARCHAR(10) PRIMARY KEY NOT NULL,
password    VARCHAR(10) NOT NULL,
profession  VARCHAR(20) NOT NULL,
idListeP        INT(5),
idPanier        INT(5),
idPersonne  INT(100),
INDEX(idListeP),
INDEX(idPanier),
FOREIGN KEY(idPersonne) REFERENCES Personne(idPersonne)
)ENGINE=InnoDB;

CREATE TABLE Patient(
idPatient    INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
sexe            CHAR NOT NULL,
anniv           DATE,
assurance   INT(3) NOT NULL,
idPersonne  INT(100),
FOREIGN KEY(idPersonne) REFERENCES Personne(idPersonne)
)ENGINE=InnoDB;

CREATE TABLE ListePatient(
idListeP        INT(5) NOT NULL,
idPatient   INT(10)NOT NULL,
PRIMARY KEY (`idPatient`,`idListeP`),
FOREIGN KEY(idListeP) REFERENCES Specialiste(idListeP),
FOREIGN KEY(idPatient) REFERENCES Patient(idPatient)
)ENGINE=InnoDB;

CREATE TABLE Produit(
idProduit       INT(100) NOT NULL PRIMARY KEY AUTO_INCREMENT,
nom         VARCHAR(50) NOT NULL,
descr           VARCHAR(255) NOT NULL,
prix            DECIMAL(5,2) NOT NULL,
qte         INT(100) NOT NULL
)ENGINE=InnoDB;

CREATE TABLE Medicament(
idMedic         INT(100)NOT NULL PRIMARY KEY AUTO_INCREMENT,
marque      VARCHAR(10) NOT NULL,
typeMed     VARCHAR(10) NOT NULL,
idProduit       INT(100) NOT NULL,
FOREIGN KEY(idProduit) REFERENCES Produit(idProduit)
)ENGINE=InnoDB;

CREATE TABLE Materiel(
idMateriel  INT(100) NOT NULL PRIMARY KEY AUTO_INCREMENT,
rabais      INT(99) NOT NULL,                                           
idProduit       INT(100) NOT NULL,
FOREIGN KEY(idProduit) REFERENCES Produit(idProduit)
)ENGINE=InnoDB;

CREATE TABLE Panier(
idPanier        INT(5) NOT NULL,
idProduit       INT(100) NOT NULL,
PRIMARY KEY (`idPanier`,`idProduit`),
FOREIGN KEY(idPanier) REFERENCES Specialiste(idPanier),
FOREIGN KEY(idProduit) REFERENCES Produit(idProduit)
)ENGINE=InnoDB;

If you want more precision, I delete all my records in my database manually and I tried to reimport those data (SQL FILE) in the database and it shoots me an Error:

-- Dumping data for table `adresse`
--
INSERT INTO `adresse` ( `idAdresse` , `num` , `rue` , `ville` , `postal` )
VALUES ( 1, 4256, 'de la Vallee', 'Laval', 'H8A1J7' ) , ( 2, 121, 'du Coin', 'Laval', 'N6A1B8' ) , ( 3, 31, 'rue Galt', 'Montreal', 'A3B6N8' ) , ( 4, 5, 'rue du Ranch', 'Laval', 'D1C0V8' ) ;

MySQL said: Documentation
#1062 - Duplicate entry '1' for key 'PRIMARY' 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:54:35+00:00Added an answer on May 24, 2026 at 1:54 pm

    If you want to delete entire database just do DROP DATABASE yourDatabaseName;

    If on the other hand, you want to make sure, that if you delete a row from a parent table (for example Addresse) then rows from referencing tables (Personne,Specialiste) are deleted as well, then you need to modify your foreign key definitions

    CREATE TABLE Personne(
    idPersonne      INT(100) PRIMARY KEY NOT NULL AUTO_INCREMENT,
    nom             VARCHAR(15) NOT NULL,
    prenom          VARCHAR(15) NOT NULL,
    idTel               INT(100) NOT NULL,
    idAdresse       INT(100) NOT NULL,
    FOREIGN KEY(idAdresse) REFERENCES Adresse(idAdresse) ON DELETE CASCADE,
    FOREIGN KEY(idTel) REFERENCES Telephone(idTel) ON DELETE CASCADE
    )ENGINE=InnoDB;
    

    (and similarly in other tables)

    See more here: http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

    and be very, very careful, so that you don’t delete more than you want

    Here’s a working example:

    mysql> USE test;
    Database changed
    mysql> SET foreign_key_checks = 0;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> DROP TABLE IF EXISTS Specialiste;
    Query OK, 0 rows affected (0.05 sec)
    
    mysql> DROP TABLE IF EXISTS Personne;
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> SET foreign_key_checks = 1;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
    mysql> CREATE TABLE Personne(
        -> idPersonne      INT(100) PRIMARY KEY NOT NULL AUTO_INCREMENT,
        -> nom             VARCHAR(15) NOT NULL
        -> )ENGINE=InnoDB;
    Query OK, 0 rows affected (0.08 sec)
    
    mysql>
    mysql> CREATE TABLE Specialiste(
        -> login           VARCHAR(10) PRIMARY KEY NOT NULL,
        -> idPersonne  INT(100),
        -> FOREIGN KEY(idPersonne) REFERENCES Personne(idPersonne) ON DELETE CASCADE
        -> )ENGINE=InnoDB;
    Query OK, 0 rows affected (0.07 sec)
    
    mysql>
    mysql> SHOW TABLES;
    +----------------+
    | Tables_in_test |
    +----------------+
    | personne       |
    | specialiste    |
    +----------------+
    2 rows in set (0.00 sec)
    
    mysql>
    mysql> INSERT INTO personne VALUES (null,'personne1'),(null,'personne2');
    Query OK, 2 rows affected (0.02 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql>
    mysql> INSERT INTO Specialiste VALUES ('login1',1),('login2',2);
    Query OK, 2 rows affected (0.03 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql>
    mysql> SELECT * FROM personne;
    +------------+-----------+
    | idPersonne | nom       |
    +------------+-----------+
    |          1 | personne1 |
    |          2 | personne2 |
    +------------+-----------+
    2 rows in set (0.00 sec)
    
    mysql> SELECT * FROM specialiste;
    +--------+------------+
    | login  | idPersonne |
    +--------+------------+
    | login1 |          1 |
    | login2 |          2 |
    +--------+------------+
    2 rows in set (0.01 sec)
    
    mysql>
    mysql> DELETE FROM personne WHERE idPersonne = 1;
    Query OK, 1 row affected (0.02 sec)
    
    mysql>
    mysql> SELECT * FROM personne;
    +------------+-----------+
    | idPersonne | nom       |
    +------------+-----------+
    |          2 | personne2 |
    +------------+-----------+
    1 row in set (0.00 sec)
    
    mysql> SELECT * FROM specialiste;
    +--------+------------+
    | login  | idPersonne |
    +--------+------------+
    | login2 |          2 |
    +--------+------------+
    1 row in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a general question about the way that database indexing works, particularly in
hihi i have a question that i want to ask about c# and window
I have posted a question about multilanguage database design here, [] What are best
I have a question about Criteria method, one-to-many relation to the database, 'one' is
I have a question about a site I'm developing. It is a database driven
I have a question, but let me first say that this is being performed
There have been several questions recently about database indexing and clustered indexing and it
Do you have any experience about this question? I have currently 1900 MySQL databases
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.