用T-SQL语言表示以下操作: 题目1实验内容: 1.把全部红色零件颜色改为粉红色; 2.由S1供给J1的零件P1今改为由S2供应,作必要修改; 3.删去全部蓝色零件及相应的SPJ记录; 4.把全部螺母的重量置为0; 5.为SPJ表的QTY字段设计CHECK约束:0〈 QTY〈1000; 6.实现对SPJ表的操作权限管理的使用。 题目2实验内容: 1. 将B5的单价改为6.00元 2. 删去图书B2及相应的发行记录 3. 修改江苏新华书店的图书的数量为50 4. 为图书发行LBS表的QTY字段设计CHECK约束: 0<QTY<100 5. 将(B6,人工智能库论,4.5)加入图书B 6. 实现对LBS表的操作权限管理的使用。
时间: 2024-02-19 13:57:24 浏览: 238
题目1:
1. 更新SP表,将COLOR为‘红色’的记录的COLOR字段改为‘粉红色’:
```
UPDATE SP
SET COLOR = '粉红色'
WHERE COLOR = '红色'
```
2. 更新SPJ表,将SNO为‘S1’,JNO为‘J1’,PNO为‘P1’的记录的SNO字段改为‘S2’:
```
UPDATE SPJ
SET SNO = 'S2'
WHERE SNO = 'S1' AND JNO = 'J1' AND PNO = 'P1'
```
3. 删除SP表中COLOR为‘蓝色’的记录,同时删除SPJ表中相应的记录:
```
DELETE FROM SP
WHERE COLOR = '蓝色'
DELETE FROM SPJ
WHERE PNO IN (
SELECT PNO
FROM SP
WHERE COLOR = '蓝色'
)
```
4. 更新P表,将WEIGHT为‘螺母’的记录的WEIGHT字段置为0:
```
UPDATE P
SET WEIGHT = 0
WHERE PNAME = '螺母'
```
5. 为SPJ表的QTY字段设计CHECK约束:
```
ALTER TABLE SPJ
ADD CONSTRAINT CHK_QTY CHECK (QTY > 0 AND QTY < 1000)
```
6. 实现对SPJ表的操作权限管理的使用:
```
-- 创建用户并授权
CREATE USER user1 WITH PASSWORD 'password'
GRANT SELECT, INSERT, UPDATE, DELETE ON SPJ TO user1
-- 撤销权限
REVOKE INSERT ON SPJ FROM user1
```
题目2:
1. 更新B表,将BNO为‘B5’的记录的PRICE字段改为6.00:
```
UPDATE B
SET PRICE = 6.00
WHERE BNO = 'B5'
```
2. 删除B表中BNO为‘B2’的记录,同时删除LBS表中相应的记录:
```
DELETE FROM B
WHERE BNO = 'B2'
DELETE FROM LBS
WHERE BNO = 'B2'
```
3. 更新L表,将STORE为‘江苏新华书店’,BNO为‘B’的记录的QTY字段改为50:
```
UPDATE L
SET QTY = 50
WHERE STORE = '江苏新华书店' AND BNO = 'B'
```
4. 为LBS表的QTY字段设计CHECK约束:
```
ALTER TABLE LBS
ADD CONSTRAINT CHK_QTY CHECK (QTY > 0 AND QTY < 100)
```
5. 向B表中插入记录(B6, 人工智能库论, 4.5):
```
INSERT INTO B(BNO, BNAME, PRICE)
VALUES ('B6', '人工智能库论', 4.5)
```
6. 实现对LBS表的操作权限管理的使用:
```
-- 创建用户并授权
CREATE USER user1 WITH PASSWORD 'password'
GRANT SELECT, INSERT, UPDATE, DELETE ON LBS TO user1
-- 撤销权限
REVOKE INSERT ON LBS FROM user1
```
阅读全文