请帮助,我需要为汽车经销商创建一个数据库。数据库必须包含商店中的所有员工和商店中的所有汽车。基地还必须包含有关哪辆车出售以及哪位员工已售出该车的信息。
我已经制作了这张桌子,但我无法连接售出的汽车和销售该车的员工。
脚本:
CREATE DATABASE IF NOT EXISTS `classicmodels` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `classicmodels`;
-- MySQL dump 10.13 Distrib 5.6.13, for Win32 (x86)
--
-- Host: localhost Database: classicmodels
-- ------------------------------------------------------
-- Server version 5.1.73-community
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `cars`
--
DROP TABLE IF EXISTS `cars`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `cars` (
`carID` int(11) NOT NULL AUTO_INCREMENT,
`manufacturerName` varchar(50) NOT NULL,
`modelName` varchar(50) NOT NULL,
`price` int(11) NOT NULL,
PRIMARY KEY (`carID`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `cars`
--
LOCK TABLES `cars` WRITE;
/*!40000 ALTER TABLE `cars` DISABLE KEYS */;
INSERT INTO `cars` VALUES (1,'Volkswagen','Jetta',13300),(2,'Renault','Laguna',14700),(3,'Ford','Focus',13600),(4,'Daewoo','Tico',1100),(5,'Toyota','Avensis',14500),(6,'Alfa Romeo','156',8700),(7,'Volkswagen','Passat',22200),(8,'Renault','Clio',6400),(9,'Ford','Fiesta',6900),(10,'Daewoo','Cielo',3600),(11,'Toyota','Rav4',24900),(12,'Alfa Romeo','147',7500),(13,'Volkswagen','Golf',16700),(14,'Renault','Megane',11400),(15,'Ford','Mondeo',14600),(16,'Daewoo','Matiz',1700),(17,'Toyota','Yaris',7400),(18,'Alfa Romeo','159',17000),(19,'Volkswagen','Polo',6500),(20,'Renault','Scenic',6800),(21,'Ford','Escort',2000),(22,'Daewoo','Espero',2500),(23,'Toyota','Corolla',10300),(24,'Alfa Romeo','166',5200);
/*!40000 ALTER TABLE `cars` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `employees`
--
DROP TABLE IF EXISTS `employees`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `employees` (
`employeeID` int(11) NOT NULL,
`lastName` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`position` varchar(50) NOT NULL,
PRIMARY KEY (`employeeID`),
KEY `prodaja_idx` (`employeeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `employees`
--
LOCK TABLES `employees` WRITE;
/*!40000 ALTER TABLE `employees` DISABLE KEYS */;
INSERT INTO `employees` VALUES (1,'Brkic','Goran','goran@prodavnicaautomobila.com','Direktor'),(2,'Milosevic','Srdjan','srdjan@prodavnicaautomobila.com','Marketing'),(3,'Srdic','Boro','boro@prodavnicaautomobila.com','Marketing'),(4,'Marinkovic','Marin','marin@cprodavnicaautomobila.com','Menadzer prodaje'),(5,'Nemanjic','Tamara','tamara@prodavnicaautomobila.com','Prodavac'),(6,'Kuduz','Renato','renato@prodavnicaautomobila.com','Prodavac'),(7,'Salkovic','Vladimir','vladimir@prodavnicaautomobila.com','Prodavac'),(8,'Berin','Marko','marko@prodavnicaautomobila.com','Prodavac'),(9,'Konjevic','Srecko','srecko@prodavnicaautomobila.com','Prodavac'),(10,'Pajic','Sasa','sasa@prodavnicaautomobila.com','Prodavac'),(11,'Goranovic','Milan','milan@prodavnicaautomobila.com','Prodavac');
/*!40000 ALTER TABLE `employees` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `soldcars`
--
DROP TABLE IF EXISTS `soldcars`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `soldcars` (
`carID` int(11) NOT NULL,
`empoyeeID` varchar(50) NOT NULL,
PRIMARY KEY (`carID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `soldcars`
--
LOCK TABLES `soldcars` WRITE;
/*!40000 ALTER TABLE `soldcars` DISABLE KEYS */;
INSERT INTO `soldcars` VALUES (1,'kuduz'),(2,'brkic'),(4,'goranovic'),(5,'milosevic'),(12,'pajic');
/*!40000 ALTER TABLE `soldcars` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2014-03-04 18:47:40
答案 0 :(得分:2)
检查你所售的车牌是否有empoyeeid而不是employeeid。这就是你无法连接
的原因CREATE TABLE `employees` (
`employeeID` int(11) NOT NULL,
`lastName` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`position` varchar(50) NOT NULL,
PRIMARY KEY (`employeeID`),
KEY `prodaja_idx` (`employeeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `soldcars` (
`carID` int(11) NOT NULL,
`empoyeeID` varchar(50) NOT NULL,
PRIMARY KEY (`carID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;