当前位置:网站首页>Database experiment I database definition and data import
Database experiment I database definition and data import
2022-04-23 21:30:00 【Hebuter-Rui】
1. The experiment purpose
Understand and master the database DDL Language , Be able to use SQL DDL sentence , And can complete data import .
2. The contents and requirements of the experiment
Understand and master SQL DDL Sentence syntax , In particular, the specific meaning and usage of various parameters ; Use SQL Sentence creation 、 Modify and delete basic tables ; master SQL How to debug the common syntax errors of statements ; Complete the data import .
3. The experimental steps
3.1 Use menu commands to create a database test
CREATE DATABASE test;
3.2 In the database test The following basic tables are defined on the
surface 1 District Table (region)
Field name | Chinese meaning | type | constraint |
regionkey | Area number | int | Primary key |
name | Area name | char(25) | null |
comment | remarks | varchar(150) | null |
surface 2 Country table (nation)
Field name | Chinese meaning | type | constraint |
nationkey | Country number | int | Primary key |
name | Country name | char(25) | null |
regionkey | Area number | int | Foreign keys , reference region Tabular regionkey |
comment | remarks | varchar(150) | null |
surface 3 Supplier basic table (supplier)
Field name | Chinese meaning | type | constraint |
suppkey | Supplier No | int | Primary key |
name | Name of supplier | char(100) | null |
address | Supplier address | varchar(100) | null |
nationkey | Country number | int | Foreign keys , reference nation Tabular nationkey |
phone | Supplier phone | char(30) | null |
acctbal | Supplier account balance forehead | numeric(12,2) | null |
comment | remarks | varchar(100) | null |
surface 4 Basic parts list (part)
Field name | Chinese meaning | type | constraint |
partkey | Part number | int | Primary key |
name | Part name | varchar(100) | null |
mfgr | manufacturer | char(50) | null |
brand | brand | char(50) | null |
type | Part type | varchar(25) | null |
size | Size | int | null |
container | packing | char(10) | null |
retailprice | wholesale price | numeric(8,2) | null |
comment | remarks | varchar(20) | null |
surface 5 Parts supply contact list (partsupp)
Field name | Chinese meaning | type | constraint | remarks |
partkey | Part number | int | Foreign keys , reference part Tabular partkey | partkey and suppkey Union as primary key |
suppkey | Supplier No | int | Outside key , ginseng mirror supplier surface Of suppkey | |
availqty | Quantity available | int | null | |
supplycost | Supply price | numeric(10,2) | null | |
comment | remarks | varchar(200) | null |
surface 6 Customer watch (customer)
Field name | Chinese meaning | type | constraint |
custkey | Customer number | int | Primary key |
name | full name | varchar(25) | null |
address | Address | varchar(40) | null |
nationkey | Country number | int | Foreign keys , come from nation Tabular nationkey |
phone | Telephone | char(30) | null |
acctbal | Account balance | numeric(12,2) | null |
mktsegment | Market segmentation | char(10) | null |
comment | remarks | varchar(100) | null |
surface 7 The order sheet (orders)
Field name | Chinese meaning | type | constraint |
orderkey | The order no. | int | Primary key |
custkey | Customer number | int | Outside key , ginseng mirror customer surface Of Custkey |
orderstatus | The order status | char(1) | null |
totalprice | Order amount | numeric(10,2) | null |
orderdate | Order date | date | null |
orderpriority | Order priority | char(15) | null |
clerk | Bookkeeper | char(16) | null |
shippriority | Transportation priority | char(1) | null |
comment | remarks | varchar(60) | null |
surface 8 Order details (lineitem)
Field name | Chinese meaning | type | constraint | remarks |
orderkey | The order no. | int | Foreign keys , reference orders Tabular orderkey | orderkey and linenumber United Cooperation is the primary key |
partkey | Part number | int | Foreign keys , reference part surface Of partkey | partkey and suppkey United Combined reference partsupp surface Of partkey and suppkey |
suppkey | Supplier No | int | Foreign keys , reference supplier Tabular suppkey | |
linenumber | Order details Number | int | null | |
quantity | Number of parts | int | null | |
extendedprice | Detailed order price grid | numeric(8,2) | null | |
discount | discount | numeric(3,2) | null | |
tax | tax rate | numeric(3,2) | null | |
returnflag | Return mark | char(1) | null | |
linestatus | Order details state | char(1) | null | |
shipdate | Date of shipment | date | null | |
commitdate | Commission date | date | null | |
receiptdate | Date of receipt | date | null | |
shipinstruct | Shipping instructions | char(25) | null | |
shipmode | Mode of shipment | char(10) | null | |
comment | remarks | varchar(40) | null |
New table source code :
CREATE TABLE region(
regionkey INT PRIMARY KEY,
name CHAR(25),
comment VARCHAR(150)
);
CREATE TABLE nation(
nationkey INT PRIMARY KEY,
name CHAR(25),
regionkey INT,
comment VARCHAR(150),
FOREIGN KEY(regionkey) REFERENCES region(regionkey)
);
CREATE TABLE supplier(
suppkey INT PRIMARY KEY,
name CHAR(100),
address VARCHAR(100),
nationkey INT,
phone CHAR(30),
acctbal NUMERIC(12,2),
comment VARCHAR(100),
FOREIGN KEY(nationkey) REFERENCES nation(nationkey)
);
CREATE TABLE part(
partkey INT PRIMARY KEY,
name VARCHAR(100),
mfgr CHAR(50),
brand CHAR(50),
type VARCHAR(25),
size INT,
container CHAR(10),
retailprice NUMERIC(8,2),
comment VARCHAR(20)
);
CREATE TABLE partsupp(
partkey INT,
suppkey INT,
availqty INT,
supplycost NUMERIC(10,2),
comment VARCHAR(200),
PRIMARY KEY(partkey,suppkey),
FOREIGN KEY(partkey) REFERENCES part(partkey),
FOREIGN KEY(suppkey) REFERENCES supplier(suppkey)
);
CREATE TABLE customer(
custkey INT PRIMARY KEY,
name VARCHAR(25),
address VARCHAR(40),
nationkey INT,
phone CHAR(30),
acctbal NUMERIC(12,2),
mktsegment CHAR(10),
comment VARCHAR(100),
FOREIGN KEY(nationkey) REFERENCES nation(nationkey)
);
CREATE TABLE orders(
orderkey INT PRIMARY KEY,
custkey INT,
orderstatus CHAR(1),
totalprice NUMERIC(10,2),
orderdate DATE,
orderpriority CHAR(15),
clerk CHAR(16),
shippriority CHAR(1),
comment VARCHAR(60),
FOREIGN KEY(custkey) REFERENCES customer(custkey)
);
CREATE TABLE lineitem(
orderkey INT,
partkey INT,
suppkey INT,
linenumber INT,
quantity INT,
extendedprice NUMERIC(8,2),
discount NUMERIC(3,2),
tax NUMERIC(3,2),
returnflag CHAR(1),
linestatus CHAR(1),
shipdate DATE,
commitdate DATE,
receiptdate DATE,
shipinstruct CHAR(25),
shipmode CHAR(10),
comment VARCHAR(40),
PRIMARY KEY(orderkey,linenumber),
FOREIGN KEY(partkey,suppkey) REFERENCES partsupp(partkey,suppkey)
);
3.3 according to qq In the group “ Data import tutorial .rar”, Put the data of each table (.csv Format ) Import to the created table , The import order is in the order of table creation
experimental data (orders The date data of the table needs to be used after the format is modified , The modified format in the link below )
link :https://pan.baidu.com/s/1PMH0_sg-ibD-Gzddfu9HWA
Extraction code :11yn
版权声明
本文为[Hebuter-Rui]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/110/202204200618537028.html
边栏推荐
- Correction of date conversion format error after Oracle adds a row total
- Pyuninstaller package exe cannot find the source code when running, function error oserror: could not get source code
- Opencv reports an error. Expected PTR < CV:: UMAT > for argument '% s'‘
- Reentrant function
- Mixed use of Oracle column row conversion and comma truncated string
- Sequential state
- Getting started with detectron2
- [leetcode refers to offer 47. Maximum value of gift (medium)]
- Graph traversal - BFS, DFS
- Rust更适合经验较少的程序员?
猜你喜欢
2.整理华子面经--2
[leetcode refers to offer 22. The penultimate node in the linked list (simple)]
[leetcode refers to offer 52. The first common node of two linked lists (simple)]
IIS cannot load * woff,*. woff2,*. Solution of SVG file
Chrome 94 引入具有争议的 Idle Detection API,苹果和Mozilla反对
[※ leetcode refers to offer 32 - II. Print binary tree II from top to bottom (simple)]
Some grounded words
Plato Farm元宇宙IEO上线四大,链上交易颇高
Problem brushing plan -- dynamic programming (III)
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:app:stripDe
随机推荐
Pycharm download and installation
阿里云回应用户注册信息泄露事件
Automatic heap dump using MBean
Tencent cloud has two sides in an hour, which is almost as terrible as one side..
Assertionerror: invalid device ID and runtimeerror: CUDA error: invalid device ordinal
[leetcode refers to offer 18. Delete the node of the linked list (simple)]
Display, move, rotate
[※ leetcode refers to offer 48. The longest substring without repeated characters (medium)]
C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
wait、waitpid
Realrange, reduce, repeat and einops in einops package layers. Rearrange and reduce in torch. Processing methods of high-dimensional data
[leetcode sword finger offer 28. Symmetric binary tree (simple)]
How Axure installs a catalog
setInterval、setTimeout、requestAnimationFrame
[leetcode sword finger offer 58 - I. flip word order (simple)]
[leetcode sword finger offer 10 - II. Frog jumping steps (simple)]
How to make Jenkins job run automatically after startup
Keras. Layers introduction to various layers
Two Stage Detection
Mixed use of Oracle column row conversion and comma truncated string