Auto commit

This commit is contained in:
smallkun 2025-03-14 09:06:09 +08:00
parent c2fd89cd97
commit 4958a07e62

View File

@ -47,3 +47,40 @@ ALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1;
DROP TABLE orders;
```
---
### 练习二
```sql
#(1)创建表、插入记录
CREATE TABLE pet(
`name` VARCHAR(20) NOT NULL COMMENT '宠物名称',
`owner` VARCHAR(20) COMMENT '宠物主人',
species VARCHAR(20) NOT NULL COMMENT '种类',
sex CHAR(1) NOT NULL COMMENT '性别',
birth YEAR NOT NULL COMMENT '出生日期',
death YEAR COMMENT '死亡日期'
);
INSERT INTO pet()
VALUES
('Fluffy', 'Harold', 'cat', 'f', 2003, 2010),
('Claws', 'Gwen', 'cat', 'm', 2004,NULL ),
('Buffy', NULL, 'dog', 'f', 2009, NULL),
('Fang', 'Benny', 'dog', 'm', 2000, NULL),
('Bowser', 'Diane', 'dog', 'm', 2003, 2009),
('Chirpy', NULL, 'bird', 'f', 2008, NULL);
#(2)更新记录
UPDATE pet
SET `owner` = 'Kevin'
WHERE `name` = 'Fang';
#(3)
UPDATE pet
SET `owner` = 'Kevin'
WHERE `owner` IS NULL;
#(4)
DELETE FROM pet
WHERE death IS NOT NULL;
#(5)
TRUNCATE pet;
```