MySQL官方示例數(shù)據(jù)庫是MySQL官方提供的用于學(xué)習(xí)和演示的示例數(shù)據(jù)庫,該數(shù)據(jù)庫包含了多張數(shù)據(jù)表,每張表都有各自的數(shù)據(jù)字段和條目。使用該示例數(shù)據(jù)庫可以幫助學(xué)習(xí)者更好的理解MySQL數(shù)據(jù)庫的使用方法和操作原理。
CREATE DATABASE classicmodels;
USE classicmodels;
CREATE TABLE IF NOT EXISTS employees (
employeeNumber INT(11) NOT NULL,
lastName VARCHAR(50) NOT NULL,
firstName VARCHAR(50) NOT NULL,
extension VARCHAR(10) NOT NULL,
email VARCHAR(100) NOT NULL,
officeCode VARCHAR(10) NOT NULL,
reportsTo INT(11),
jobTitle VARCHAR(50) NOT NULL,
PRIMARY KEY (employeeNumber)
);
CREATE TABLE IF NOT EXISTS offices (
officeCode VARCHAR(10) NOT NULL,
city VARCHAR(50) NOT NULL,
phone VARCHAR(50) NOT NULL,
addressLine1 VARCHAR(50) NOT NULL,
addressLine2 VARCHAR(50),
state VARCHAR(50),
country VARCHAR(50) NOT NULL,
postalCode VARCHAR(15) NOT NULL,
territory VARCHAR(10) NOT NULL,
PRIMARY KEY (officeCode)
);
INSERT INTO employees (employeeNumber, lastName, firstName, extension, email, officeCode, reportsTo, jobTitle)
VALUES (1002, 'Murphy', 'Diane', 'x5800', 'dmurphy@classicmodelcars.com', '1', null, 'President'),
(1056, 'Patterson', 'Mary', 'x4611', 'mpatterso@classicmodelcars.com', '1', '1002', 'VP Sales'),
(1076, 'Firrelli', 'Jeff', 'x9273', 'jfirrelli@classicmodelcars.com', '1', '1002', 'VP Marketing'),
(1143, 'Bow', 'Anthony', 'x5428', 'abow@classicmodelcars.com', '1', '1056', 'Sales Manager (NA)');
上面的示例代碼是創(chuàng)建一個名為classicmodels的數(shù)據(jù)庫,并創(chuàng)建了用于演示的兩張表,即employees和offices,同時在employees表中插入了一些示例數(shù)據(jù)。在實際使用中,我們需要根據(jù)自己的需求和業(yè)務(wù)邏輯來自定義各個數(shù)據(jù)表和數(shù)據(jù)字段,同時,也可以根據(jù)具體情況來進(jìn)行增刪改查等操作。