PostgreSQL 数据库设计:构建汽车配件电商网站
根据 PostgreSQL 的语法,可以创建以下常用的表来支持一个销售汽车配件的电商网站:\n\n1. 用户表(users):\n\nCREATE TABLE users (\n  id SERIAL PRIMARY KEY,\n  username VARCHAR(255) NOT NULL,\n  email VARCHAR(255) NOT NULL UNIQUE,\n  password VARCHAR(255) NOT NULL,\n  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\n\n\n2. 产品表(products):\n\nCREATE TABLE products (\n  id SERIAL PRIMARY KEY,\n  name VARCHAR(255) NOT NULL,\n  description TEXT,\n  price DECIMAL(10, 2) NOT NULL,\n  stock INT NOT NULL,\n  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\n\n\n3. 购物车表(carts):\n\nCREATE TABLE carts (\n  id SERIAL PRIMARY KEY,\n  user_id INT NOT NULL,\n  product_id INT NOT NULL,\n  quantity INT NOT NULL,\n  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  FOREIGN KEY (user_id) REFERENCES users (id),\n  FOREIGN KEY (product_id) REFERENCES products (id)\n);\n\n\n4. 订单表(orders):\n\nCREATE TABLE orders (\n  id SERIAL PRIMARY KEY,\n  user_id INT NOT NULL,\n  total_amount DECIMAL(10, 2) NOT NULL,\n  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  FOREIGN KEY (user_id) REFERENCES users (id)\n);\n\n\n5. 订单详情表(order_details):\n\nCREATE TABLE order_details (\n  id SERIAL PRIMARY KEY,\n  order_id INT NOT NULL,\n  product_id INT NOT NULL,\n  quantity INT NOT NULL,\n  price DECIMAL(10, 2) NOT NULL,\n  FOREIGN KEY (order_id) REFERENCES orders (id),\n  FOREIGN KEY (product_id) REFERENCES products (id)\n);\n\n\n这些表可以作为一个销售汽车配件的电商网站的基本数据库结构,用于存储用户信息、产品信息、购物车信息和订单信息等。根据实际需求,还可以根据以上表结构进行扩展和优化。
原文地址: https://www.cveoy.top/t/topic/qgzB 著作权归作者所有。请勿转载和采集!