请写出sql语句,要求如下:设计一个银行账户并且实现转账业务
时间: 2024-05-06 21:21:15 浏览: 13
Sure, I can definitely help you with that! Here's the SQL statement to create a basic bank account system with transfer functionality:
```
CREATE TABLE Account (
accountNumber INT PRIMARY KEY,
balance DECIMAL(10, 2) NOT NULL DEFAULT 0
);
INSERT INTO Account (accountNumber) VALUES (1);
INSERT INTO Account (accountNumber) VALUES (2);
CREATE TABLE Transfer (
transferId INT PRIMARY KEY,
senderAccount INT NOT NULL,
recipientAccount INT NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (senderAccount)
REFERENCES Account(accountNumber),
FOREIGN KEY (recipientAccount)
REFERENCES Account(accountNumber)
);
INSERT INTO Transfer (transferId, senderAccount, recipientAccount, amount)
VALUES (1, 1, 2, 1000.00);
```
This creates two tables - one to store account information, and another to store transfer transactions. The `Account` table has a `balance` field to keep track of the account's current balance, and the `Transfer` table has a `senderAccount`, `recipientAccount`, and `amount` field to specify the details of each transfer.
To perform a transfer, you would simply insert a new row into the `Transfer` table with the appropriate values. For example, to transfer $1000 from account 1 to account 2, you would insert a row with `senderAccount` = 1, `recipientAccount` = 2, and `amount` = 1000.00.
I hope this helps! Let me know if you have any other questions.