   `address` varchar(100) NOT NULL,
   `registrar_key` varchar(20) DEFAULT NULL,
   PRIMARY KEY (`personal_data_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=168 ;
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=173 ;
 
 --
 -- Дамп данных таблицы `personal_data`

  `name` varchar(100) NOT NULL,
  `class_id` int(11) NOT NULL,
  `coordinates` text NOT NULL,
  `owner_data_id` int(11) DEFAULT NULL,
  `reason` text NOT NULL,
  `date` date DEFAULT NULL,

--
-- База данных: `resource_registry`
--

DELIMITER $$
--
-- Функции
--
CREATE DEFINER=`root`@`localhost` FUNCTION `distance`(lat1 FLOAT, lng1 FLOAT, lat2 FLOAT, lng2 FLOAT) RETURNS float
BEGIN
	DECLARE pi80 FLOAT;
	DECLARE r FLOAT;
	DECLARE dlat FLOAT;
	DECLARE dlng FLOAT;
	DECLARE a FLOAT;
	DECLARE c FLOAT;
	DECLARE km FLOAT;
	
	SET pi80 = PI() / 180;
	SET lat1 = lat1 * pi80;
	SET lng1 = lng1 * pi80;
	SET lat2 = lat2 * pi80;
	SET lng2 = lng2 * pi80;
 
	SET r = 6372.797; 
	SET dlat = lat2 - lat1;
	SET dlng = lng2 - lng1;
	SET a = sin(dlat / 2) * sin(dlat / 2) + cos(lat1) * cos(lat2) * sin(dlng / 2) * sin(dlng / 2);
	SET c = 2 * atan2(sqrt(a), sqrt(1 - a));
	SET km = r * c;

  RETURN km;
END$$

DELIMITER ;

-- --------------------------------------------------------

