C
C
Chvalov2017-09-25 00:11:28
MySQL
Chvalov, 2017-09-25 00:11:28

Database design, which option to use?

Task:
There is a list of ip addresses table ipAddress ip field with which we will work
. It is necessary to check whether this ip is pinged, if not, write True in the dead_ping field.
After ip is checked, change the value of the checked field to True so as not to check again.
Then we take the ip of the servers that ping and look for domains that are hosted on the server
. Table ipToWeb, if we found domains by ip, we write them in the domain_address field, and in the ip_id field we write the id of the IP address from which the domains
received on its id in the ipToWeb table
How to properly design a database?
Now I have two options:
First:
SC8Mqj4.png
Second:
A6KDbLA.png
Ultimately, you need to output: ip, domain_address, domain_title, domain_headers
SQL:

DROP DATABASE ip_site_list;
CREATE DATABASE ip_site_list CHARACTER SET utf8 COLLATE utf8_general_ci;
USE ip_site_list;

CREATE TABLE ipAddress (
  id              INT(8)      NOT NULL        PRIMARY KEY       AUTO_INCREMENT,
  ip              VARCHAR(15) NOT NULL        UNIQUE,
  checked         BOOLEAN     DEFAULT FALSE,
  dead_ping       BOOLEAN     DEFAULT FALSE,
  update_up       TIMESTAMP   # По дефоллу NOT NULL и DEFAULT -> NOW()
);

CREATE TABLE ipToWeb (
  id              INT(10)     NOT NULL        PRIMARY KEY       AUTO_INCREMENT,
  ip_id           INT(8)      NOT NULL,
  domain_address  VARCHAR(255),
  update_up       TIMESTAMP, 

  FOREIGN KEY (ip_id) REFERENCES ipAddress (id)
);

CREATE TABLE domainInfo (
  id              INT(10)     NOT NULL        PRIMARY KEY       AUTO_INCREMENT,
  domain_id       INT(10)     NOT NULL,
  domain_title    VARCHAR(255),
  domain_headers  TEXT,
  update_up       TIMESTAMP,

  FOREIGN KEY (domain_id) REFERENCES ipToWeb (id)
);

INSERT INTO ipAddress VALUES (1, '95.183.15.59', TRUE, FALSE, CURRENT_TIMESTAMP());
INSERT INTO ipAddress VALUES (2, '178.248.232.5', TRUE, FALSE, CURRENT_TIMESTAMP());
INSERT INTO ipAddress VALUES (3, '95.183.15.66', TRUE, TRUE, CURRENT_TIMESTAMP());
INSERT INTO ipToWeb VALUES (1, 1, 'zaycev.fm', CURRENT_TIMESTAMP());
INSERT INTO ipToWeb VALUES (2, 2, 'toster.ru', CURRENT_TIMESTAMP());
INSERT INTO ipToWeb VALUES (3, 2, 'autokadabra.ru', CURRENT_TIMESTAMP());
INSERT INTO ipToWeb VALUES (4, 2, 'brainstorage.me', CURRENT_TIMESTAMP());
INSERT INTO ipToWeb VALUES (5, 2, 'tmfeed.ru', CURRENT_TIMESTAMP());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2017-09-25
@AlexMaxTM

The second option is more correct. Several domains can sit on one IP, at the same time one domain can change its IP over time. Therefore, only the composite IP-domain key can be unique.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question