首先复习创建学生表Students。
---注意表名大小写问题
CREATE TABLE public."Students"(
"StudentID" INTEGER PRIMARY KEY,
"StudentName" TEXT NOT NULL,
"StudentBirthday" DATE,
"StudentAddress" VARCHAR(50),
"StudentSalary" REAL ---学费
);
先在表内插入2条数据。
INSERT INTO public."Students"("StudentID","StudentName","StudentBirthday","StudentAddress","StudentSalary") VALUES
('1','贾明','1988-08-18','江苏省南京市鼓楼区','200'),
('2','贾宝玉','1988-09-09','江苏省南京市鼓楼区','300'),
('3','甄宝玉','1988-08-08','江苏省南京市鼓楼区','200');
更新StudentID=2行StudentBirthday=1988-9-9数据。
UPDATE public."Students" SET "StudentBirthday"='1988-9-9' WHERE "StudentID"=2;
再次练习插入一次修改多个值。
UPDATE public."Students" SET "StudentBirthday"='1988-8-8',"StudentSalary"=300 WHERE "StudentID"=1;
再次插入3条数据。
INSERT INTO public."Students"("StudentID","StudentName","StudentBirthday","StudentAddress","StudentSalary") VALUES
('4','张大宝','1988-08-18','江苏省无锡市梁溪区','100'),
('5','张小宝' ,'1988-9-9','江苏省无锡市梁溪区','200'),
('6','王小宝', '1988-8-8','江苏省无锡市新吴区','100');
批量修改某列数据
---批量修改学费数据
UPDATE "public"."Students" SET "StudentSalary" = "StudentSalary" * 1.5 ;
根据条件修改多列数据
---修改多列数据
UPDATE "public"."Students" SET "StudentSalary" = 300 , "StudentAddress" = '江苏省南京市玄武区' WHERE "StudentSalary" > 300 ;
温馨提示:本文代码和截图数据可能会存在不一致情况,请以代码为准。