(三)数据的基本操作

一、添加数据

1.为所有字段添加数据

insert into dept(cept_id , dept_name , address , zip , code, telephone)

values

(1,"北京总行","北京金融街一号",100000,123456789);

2.添加多条数据

insert into dept

values

(2,"北京2号支行","北京金融街2号",100002,123456789),

(3,"北京3号支行","北京金融街3号",100003,123456789),

二、删除数据

delete from ttable_name

truncate table table_name

delete 删除数据可以回滚

truncate 删除数据不可回滚

那么在效率上 truncate的效率就要高很多了。

删除任何数据之前切记要备份!备份!备份!备份占不了你多大点空间的。

三、查询数据

1.查询指定字段

select column1 column2 from table_name

2.查询指定记录

select column1, column2 from table_name where condition;

例1:select name ,price from books where name = "java"

例2:查询价格范围在45到70之间的

select name,  price from books where price>=45 and price <=70

四、IN查询

查询价格为45和68的书籍

select name , price from books where price in(45,68)

查询价格不为45和6的书籍

select name , price from books where price not in(45,68)

五、BETWEEN AND查询

1.查询价格在45到68的书籍

select name , price from books where price between 45 and 68;

2.查询价格不在45到68的书籍

select name , price from books where price not between 45 and 68;

发表评论

电子邮件地址不会被公开。必填项已用 * 标注