数据库的一些基本操作(sql增删改查的简单代码例子实现)

创建表:
create table 表名(
列名 字段长度
)

create table testsix(
bookno char(20),
bookname char(20),
name char(20)
time char(20)
timetwo char(20)
);

增加一些字段数据:
insert into 表名 (字段1, 字段2) values (值1, 值2);
insert into testfive (‘id’,‘name’) values(‘1’,‘3’);

增加全部字段数据:
insert into 表名values (值1, 值2);

insert into testfive values(‘1’,‘3’,‘33’,‘333’);
insert into testfive values(‘2’,‘web’,‘湖中大’,‘学习’);
insert into testfive values(‘3’,‘数据库’,‘北大’,‘学习’);
insert into testfive values(‘3’,‘数据库’,‘北大’,‘学习’);

查看表的所有属性:
select * from testfour;

有条件的查看表的所有属性:
select * from testfour where id=‘1’;

有条件的删除数据:
delete from testthree where bookno=1;
String sql =“delete from test where username=’” + username + “’”;

直接删除表中的数据
delete from testthree;
或者
truncate testthree;

在这里插入图片描述

修改数据:
update testthree set bookname=2,bookpublic=3,booktype=4 where bookno=1;

String sql =“update testthree set bookname=’” + bookname + “’ , bookpublic=’” + bookpublic + “’ , booktype=’” + booktype + “’ where bookno=’” + bookno + “’”;

上面所有的例子全是以代码为例写的。
要是在数据库的增删改查,就需要对表名等信息加上英文的双引号。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值