SQL基础(增删改查基本功能)
来源:互联网 发布:软件版本 alpha beta 编辑:程序博客网 时间:2024/05/21 06:46
SQL基础操作
1.select语句SELECT语句:用于从数据库中选取数据
select * from table1;select name,id from table2;(1)从 "customers" 表中选取 "name" 和 "id" 列:
select name,id from customers;(2)从 "Customers" 表中选取所有列:
select * from customers;
select distinct语句:用于返回唯一不同的值。
(一个列可能包含多个重复值)例:从 "customers" 表的 "name" 列中选取唯一不同的值
select distinct name from customers;
(1)WHERE子句:用于过滤记录
例:从 "menber" 表中选取国家(country)为 "China" 的所有内容:
select * from menber where country='China';(数值字段不用引号)
可在where子句中使用的运算符:
=,<>/!=,>,<,>=,<=,between(在某个范围内),like(搜索某种模式),in(指定针对某个列的多个可能值)
(2)and&or
例:从 "Peron" 表中选取 Country 为 "China" 且 City 为 "Jilin" 或 "Beijing" 的所有内容:
select * from Person where Country="China" and (City="Jilin" or City="Beijing");
(3)ORDER BY:用于对结果集按照一个列或者多个列进行排序
默认升序,降序则用desc关键字例:从 "person1" 表中选取所有内容,并按照 "age" 列降序排序:
select * from person1 order by age desc;
2.INSERT INTO:语句用于向表中插入新记录
两种语法:
insert into table1 values (value1,value2,...);insert into table2 (col1,col2,...) values (value1,value2);例:插入一个新行,但是只在 "name" 和 "country" 列插入数据:
insert into person (name,country) values ('Jack','England');
3.UPDATE语句:用于更新表中的记录
例:把 "person" 表的 name 为 'Jason' 的 country 改为 'China', city 改为 'Shanghai':
update person set country='China',city='Shanghai' where name='Jason';
例:从"person"表中删除name为"Jane"且address为"London"的数据:
delete from person where name='Jane' and address='London';
阅读全文
0 0
- SQL基础(增删改查基本功能)
- sql基础 (表结构的增删改查)
- SQL语句基础(一)增删改查
- SQL的Day1(基础的增删改查)
- SQL 增删改查 参考 基础
- sql 基础语法[增删改查]
- sql 基础 ( 数据的增删改查 )
- SQL 基础增删改查语句
- SQL Server 基础之增删查改
- SQL常用基础语句-增删改查
- SQL基础之增删改查
- Extjs 增删改查基本功能页面Js
- SQL增删改查
- sql 增删改查
- SQL增删改查
- SQL增删改查
- SQL---增删改查
- sql增删改查
- 程序设计实践练习(执行,暴力)2
- Codeforces Round #428 (Div. 2) 839B. Game of the Rows(思维+贪心)
- 根据进程名获取进程id
- 文件合并
- Codeforces Round #428 (Div. 2) 题解 (蓝 -> 紫)
- SQL基础(增删改查基本功能)
- VMware Pro 12 安装 Centos7
- CSU 1976: 搬运工小明(二分)
- 日期计算
- socket(php)(短连接)(循环发count次,但是每次都得重新连接,会自动断开)整理版本2
- hadoop2.x之IO:MapReduce压缩
- 判断合法的压缩字符
- 数据结构实验之查找一:二叉排序树
- CSU 1978: LXX的图论题