利用SQL Server Management Studio对象资源管理器建立帐户信息数据库,并定义以下基本表: 帐户(帐户编号,姓名,余额,建立日期,储蓄所编号) 储蓄所(储蓄所编号,名称,地址,人数,所属城市) 借贷(帐户编号,借贷类型,金额,日期)用代码输入数据
时间: 2023-06-11 21:07:47 浏览: 138
以下是建立帐户信息数据库和定义基本表的SQL代码:
```
CREATE DATABASE AccountInfo;
USE AccountInfo;
CREATE TABLE Account (
AccountNumber INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Balance DECIMAL(18,2),
CreationDate DATE,
SavingsBankNumber INT,
FOREIGN KEY (SavingsBankNumber) REFERENCES SavingsBank(SavingsBankNumber)
);
CREATE TABLE SavingsBank (
SavingsBankNumber INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Address VARCHAR(100),
NumberOfPeople INT,
City VARCHAR(50)
);
CREATE TABLE Loan (
AccountNumber INT,
LoanType VARCHAR(50),
Amount DECIMAL(18,2),
Date DATE,
FOREIGN KEY (AccountNumber) REFERENCES Account(AccountNumber)
);
INSERT INTO SavingsBank VALUES (1, 'ABC Savings Bank', '123 Main St.', 100, 'New York');
INSERT INTO SavingsBank VALUES (2, 'XYZ Savings Bank', '456 Maple Ave.', 200, 'Los Angeles');
INSERT INTO Account VALUES (1, 'John Smith', 5000.00, '2021-01-01', 1);
INSERT INTO Account VALUES (2, 'Jane Doe', 10000.00, '2021-02-15', 2);
INSERT INTO Loan VALUES (1, 'Personal Loan', 1000.00, '2021-03-01');
INSERT INTO Loan VALUES (2, 'Car Loan', 5000.00, '2021-04-15');
```
阅读全文