用sql server语句做一个外卖管理系统
时间: 2024-02-01 18:03:57 浏览: 75
好的,以下是一个简单的外卖管理系统的SQL Server语句:
1. 创建用户表
```
CREATE TABLE [dbo].[User](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Username] [nvarchar](50) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[Nickname] [nvarchar](50) NULL,
[Phone] [nvarchar](20) NOT NULL,
[Address] [nvarchar](100) NOT NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[ID] ASC
)
);
```
2. 创建商家表
```
CREATE TABLE [dbo].[Merchant](
[ID] [int] IDENTITY(1,1) NOT NULL,
[MerchantName] [nvarchar](50) NOT NULL,
[Phone] [nvarchar](20) NOT NULL,
[Address] [nvarchar](100) NOT NULL,
CONSTRAINT [PK_Merchant] PRIMARY KEY CLUSTERED
(
[ID] ASC
)
);
```
3. 创建菜品表
```
CREATE TABLE [dbo].[Dish](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DishName] [nvarchar](50) NOT NULL,
[Description] [nvarchar](200) NULL,
[Price] [decimal](18, 2) NOT NULL,
[MerchantID] [int] NOT NULL,
CONSTRAINT [PK_Dish] PRIMARY KEY CLUSTERED
(
[ID] ASC
),
CONSTRAINT [FK_Dish_Merchant] FOREIGN KEY([MerchantID])
REFERENCES [dbo].[Merchant] ([ID])
);
```
4. 创建订单表
```
CREATE TABLE [dbo].[Order](
[ID] [int] IDENTITY(1,1) NOT NULL,
[UserID] [int] NOT NULL,
[MerchantID] [int] NOT NULL,
[DishIDs] [nvarchar](max) NOT NULL,
[Address] [nvarchar](100) NOT NULL,
[Amount] [decimal](18, 2) NOT NULL,
[Status] [nvarchar](20) NOT NULL,
CONSTRAINT [PK_Order] PRIMARY KEY CLUSTERED
(
[ID] ASC
),
CONSTRAINT [FK_Order_User] FOREIGN KEY([UserID])
REFERENCES [dbo].[User] ([ID]),
CONSTRAINT [FK_Order_Merchant] FOREIGN KEY([MerchantID])
REFERENCES [dbo].[Merchant] ([ID])
);
```
以上是一个简单的外卖管理系统的SQL Server语句,可以实现用户注册、登录、下单、商家接单、配送等操作。当然,实际开发中还需要考虑数据的安全性、性能优化等方面。
阅读全文