数据库的增删改查

1. 查询 

1.1 简单查询:

        select 语法: select 列名称 from 表名称(*表示显示所有列)

        select *  from Region  select distinct 列名称 from 表名称

1.2 带条件查询where

        语法: select 列名称 from 表名称 where 列 运算符  值 (运算符有=、<=、!=、>=、< 、> 、 <> 、like 、between、and、or、order by)Note:条件值周围使用单引号(文本),若为数字则不要使用引号

        例如 select ID, NAME, GRADE   from students where ID <= 4 就是查询id 小于4的数据

        select ID, NAME, GRADE   from students where NAME like 'F%'     /* 查询名字中首字母为F的数据*/

        select ID, NAME, GRADE   from students where ID between 1 and 9 /*查询ID在1和9之间的数据*/

        select ID, NAME, GRADE   from students where GRADE=5 and NAME='May'   /* 查询5班May同学*/

       select ID, NAME, GRADE   from students where GRADE=5 or NAME='May'   /* 查询5班学生或 May同学*/

       select score, NAME, GRADE   from students where grade=5 order by score desc   /*查询5班的学生的姓名及成绩,查询结果按分数降序排列*/ 其中desc为降序, asc为升序

2. insert 插入数据

2.1 insert into 表的名称 values(值1, 值2, 值3...)

insert into 表名称 (列1,列2,...)values (值1, 值2,...),(值3, 值4),(值5,值6)

例如插入一条数据: insert into students(name, score)  values('Tom', 23)

       插入多条数据:insert into students(name, score)  values('Tom', 23),('jack', 57)

      插入特定的数据: insert into students(name, score)  select name, score  form students where ID =1  /*这里添加的就是EmployeeID=1的数据*/

3. 更改数据update

        语法: update 表名称 set 列名称=新值  where 列名称=某值

        example: 更新一列: update students set score=90 where ID=30 将ID为30的数据的分数更改为90

                        更新多列: update students where ID=30 set score=90, name='jack'

                        更新特定的数据: update students where ID in (from name where id=021) select ID set name='HUA'

4. 删除delete

        delete from 表名称 where 条

                      删除单条数据: delate where ID=32 from students

                      删除所有行数据: delate from students

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值