字段名 字段说明 字段名 字段说明 t_customer_info 客户基本信息表 reg_address 注册地址 t_cust_credit_level 客户信用等级表 post_code 邮政编码 t_his_cust_credit_level 客户信用等级历史表 id 序号 cust_id 客户编号 credit_level 信用级别 cust_name 客户名称 begin_date 评级有效起始日期 legal_name 法人代表 end_date 评级有效中止日期 (1)创建数据库BankCreditLoanDB。 (2)根据图2.1.2和表2.1.1,创建数据表T_customer_info、T_cust_credit_level、T_his_cust_credit_level。其中,客户信用等级历史表中的序号为自动增长字段。 (3)创建数据表间的关系及约束。为表设置主键,主键命名为“pk_<表名>_<主键标识>”;根据逻辑模型,创建数据表之间的关系,关系命名为“fk_<表名>_<主表名>_<外键标识>”;将信用级别字段默认值设置为“01”。 (4)数据访问。用SQL语句完成如下操作: 根据对逻辑数据模型的理解,分别向三个表中插入一条测试数据 T_customer_info表插入测试数据:('1001', 'XX_Company', 'zhangsan', 'hcfs', '123456') T_cust_credit_level表插入测试数据:('1001',01,'2010-10-17','2021-10-17') T_his_cust_credit_level表插入测试数据:(1,'1001',01,'2010-10-17','2021-10-17'); 查询客户名称为“XX_Company”的信用等级
时间: 2024-03-27 17:38:50 浏览: 299
抱歉,我是一个语言模型AI,无法直接访问数据库或执行SQL语句。但我可以为您提供一些思路,您可以在数据库管理系统中执行。
您可以使用以下SQL语句向表中插入测试数据:
```
-- 插入T_customer_info表测试数据
INSERT INTO T_customer_info(cust_id, cust_name, legal_name, reg_address, post_code)
VALUES ('1001', 'XX_Company', 'zhangsan', 'hcfs', '123456');
-- 插入T_cust_credit_level表测试数据
INSERT INTO T_cust_credit_level(cust_id, credit_level, begin_date, end_date)
VALUES ('1001', '01', '2010-10-17', '2021-10-17');
-- 插入T_his_cust_credit_level表测试数据
INSERT INTO T_his_cust_credit_level(id, cust_id, credit_level, begin_date, end_date)
VALUES (1, '1001', '01', '2010-10-17', '2021-10-17');
```
然后,您可以使用以下SQL语句查询客户名称为“XX_Company”的信用等级:
```
SELECT credit_level
FROM T_cust_credit_level
WHERE cust_id = '1001' AND EXISTS (
SELECT 1 FROM T_customer_info WHERE cust_name = 'XX_Company' AND T_customer_info.cust_id = T_cust_credit_level.cust_id
);
```
这个查询语句会在T_cust_credit_level表中查找cust_id为“1001”且对应的T_customer_info表中cust_name为“XX_Company”的记录,返回该记录中的credit_level字段值。
阅读全文
相关推荐

















