创建sql表和字段的语句写10个
时间: 2024-12-15 22:17:30 浏览: 7
创建SQL表并指定字段的基本语法通常是这样的,这里我会提供10个例子,假设我们有一个数据库叫`CompanyDB`,它包含几个常见的表格:
1. **员工信息表(Employees)**:
```
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Position VARCHAR(50),
Salary DECIMAL(10,2)
);
```
2. **部门表(Departments)**:
```
CREATE TABLE Departments (
DepartmentID INT PRIMARY KEY,
Name VARCHAR(50),
ManagerID INT,
FOREIGN KEY (ManagerID) REFERENCES Employees(ID)
);
```
3. **产品表(Products)**:
```
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
Name VARCHAR(100),
Category VARCHAR(50),
Price DECIMAL(10,2)
);
```
4. **订单表(Orders)**:
```
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
ProductID INT,
Quantity INT,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID),
FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);
```
5. **客户信息表(Customers)**:
```
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100)
);
```
6. **销售统计表(SalesStats)**:
```
CREATE TABLE SalesStats (
SaleID INT PRIMARY KEY,
EmployeeID INT,
SaleDate DATE,
FOREIGN KEY (EmployeeID) REFERENCES Employees(ID)
);
```
7. **库存管理表(Inventory)**:
```
CREATE TABLE Inventory (
ItemCode VARCHAR(20) PRIMARY KEY,
StockQuantity INT,
ReorderLevel INT
);
```
8. **供应商表(Suppliers)**:
```
CREATE TABLE Suppliers (
SupplierID INT PRIMARY KEY,
Name VARCHAR(100),
ContactPerson VARCHAR(50)
);
```
9. **交易表(Transactions)**:
```
CREATE TABLE Transactions (
TransactionID INT PRIMARY KEY,
SupplierID INT,
PurchaseDate DATE,
FOREIGN KEY (SupplierID) REFERENCES Suppliers(SupplierID)
);
```
10. **用户反馈表(Feedbacks)**:
```
CREATE TABLE Feedbacks (
FeedbackID INT PRIMARY KEY,
CustomerID INT,
Comment TEXT,
Rating INT,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
```
阅读全文