用mysql创建动物园管理系统 要具体代码
时间: 2023-12-11 16:02:42 浏览: 124
好的,首先你需要在MySQL中创建一个名为"zoo"的数据库,然后创建以下4个表格:
1. animals表格,用于存储动物的信息
```sql
CREATE TABLE animals (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
species VARCHAR(50) NOT NULL,
age INT(11) NOT NULL,
gender ENUM('male','female') NOT NULL,
exhibit_id INT(11) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (exhibit_id) REFERENCES exhibits(id)
);
```
2. exhibits表格,用于存储展览的信息
```sql
CREATE TABLE exhibits (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
location VARCHAR(50) NOT NULL,
PRIMARY KEY (id)
);
```
3. employees表格,用于存储员工的信息
```sql
CREATE TABLE employees (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
job_title VARCHAR(50) NOT NULL,
exhibit_id INT(11) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (exhibit_id) REFERENCES exhibits(id)
);
```
4. visitors表格,用于存储游客的信息
```sql
CREATE TABLE visitors (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
age INT(11) NOT NULL,
gender ENUM('male','female') NOT NULL,
PRIMARY KEY (id)
);
```
以上是创建表格的代码,你可以根据需求自己修改表格的字段和类型。接下来,你可以插入一些数据来测试:
```sql
INSERT INTO exhibits(name, location) VALUES('Big Cats', 'South Africa');
INSERT INTO exhibits(name, location) VALUES('Aquatic', 'North America');
INSERT INTO employees(name, job_title, exhibit_id) VALUES('John', 'Zookeeper', 1);
INSERT INTO employees(name, job_title, exhibit_id) VALUES('Jane', 'Aquarist', 2);
INSERT INTO animals(name, species, age, gender, exhibit_id) VALUES('Tiger', 'Panthera tigris', 6, 'male', 1);
INSERT INTO animals(name, species, age, gender, exhibit_id) VALUES('Dolphin', 'Tursiops truncatus', 10, 'female', 2);
INSERT INTO visitors(name, age, gender) VALUES('Tom', 25, 'male');
INSERT INTO visitors(name, age, gender) VALUES('Mary', 30, 'female');
```
这些数据可以帮助你测试查询和过滤操作。希望这些代码能对你有所帮助!
阅读全文