SQL 增删改查(具体)
一、增:有3种方法
1.使用insert插入单行数据:
insert [into] <表名> [列名] values <列值>
insert into Strdents (name,age) values ('atm',12)
2.使用insert,select语句将现有表中的 数据加入到已有的新表中
insert into <已有的新表> <列名> select <原表列名> from <原表名>
insert into newtable (name,class)select name,class from tableinfo
3.将数据插入原表中(生成測试数据用的较多)
和另外一种方法一样,仅仅是拷贝到原表中
insert into tableinfo ('name','class')select name,class from tableinfo
二、删:有3中方法
1.delete删除
delete from <表名> [where <删除条件>]
delete from tableinfo where name='atm'
2.truncate table 删除整个表的数据
truncate table <表名>
truncate table tableinfo
删除表的全部行。但表的结构、列、约束、索引等不会被删除;不能用于有外建约束引用的表
3、drop删除
drop table <表名>
drop table tableinfo
删除表中全部行。表结构也删除了。
三、update更新改动
update <表名> set <列名=更新值> [where <更新条件>]
update tableinfo set age=12 where name='atm1'
set后面能够紧随多个数据列的更新值(非数字要引號);
四、查
1.普通查询
select <列名> from <表名> [where <查询条件表达试>] [order by <排序的列名>[asc或desc]]
1).查询全部数据
select * from tableinfo
2).查询部分行列--条件查询
select name,age from tableinfo where age=11;
3).在查询中使用AS更改列名
select name as 姓名 from a where age=11;
4).查询空行
select name from tableinf where class is null
5).查询返回限制行数(关键字:top )
select top 6 name from tableinfo
显示列name的前6行,oracle 中用rownum替代(select * from a where rownum<6 )
6).查询排序(关键字:order by , asc , desc)
例:select name from tableinfo where age>=11 order by desc(默觉得ASC升序)
2.模糊查询
1).使用like进行模糊查询
请看还有一篇文章, SQL like四种使用方法
2).使用between在某个范围内进行查询
select * from tableinfo where age between 11 and 22
3).使用in在列举值内进行查询(in后是多个的数据)
select name from tableinfo where name in ('atm','atm1','atm2');
SQL 增删改查(具体)的更多相关文章
- Linq to sql 增删改查(转帖)
http://blog.csdn.net/pan_junbiao/article/details/7015633 (LINQ To SQL 语法及实例大全) 代码 Code highlightin ...
- 表结构修改以及sql增删改查
修改表结构 修改表名 alter table 表名 rename 新名 增加字段 alter table 表名 add 字段名 数据类型 约束 删除字段 alter table 表名 drop 字段名 ...
- sql增删改查封装
App.config文件 <?xml version="1.0" encoding="utf-8" ?> <configuration> ...
- sql增删改查-转载
一.增:有2种方法 1.使用insert插入单行数据: 语法:insert [into] <表名> [列名] values <列值> 例:insert into Strdent ...
- SQL增删改查
1.增 INSERT INTO table_name VALUES (value1, value2,....) INSERT INTO table_name (列1, 列2,...) VALUES ( ...
- linq to sql 增删改查
ORM<Object Relation Mapping> Linq To Sql: 一.建立Linq To Sql 类 : 理解上下文类: Linq To Sql 类名+context 利 ...
- SQL——Hibernate SQL增删改查
1.查询list数据 实例:user login public String userLogin(){ Session session = HibernateSessionFactory.getSes ...
- SQL 增删改查
create table [表名]([自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,[字段1] nVarChar(50) default \'默认值\' null , ...
- SQL Server高速生成SQL增删改查语句
你还在手写程序生成SQL语句吗?你还在为由于马虎出错的SQL语句而感到无语吗?你还在为不知如何表达复杂的SQL语句而纠结吗?假设你的回答为"是".那你就OUT啦.快来试试应用SQL ...
随机推荐
- 洛谷P1137 旅行计划 解题报告(拓扑排序+DP)
我看了一下其他大佬的题解,大部分都是拓扑排序加上DP.那么我想有的人是不明白为什么这么做的,拓扑排序有什么性质使得可以DP呢?下面我就提一下. 对一个有向无环图(Directed Acyclic Gr ...
- 一天一个算法:求Sn=a+aa+aaa+…+aa…a之和
/* 求Sn=a+aa+aaa+…+aa…a之值,其中a是一个数字. 例如:2+22+222+…+22222(此时n=5),n由键盘输入.*/ void Function3() { int a,n,s ...
- 基于分布式的短文本命题实体识别之----人名识别(python实现)
目前对中文分词精度影响最大的主要是两方面:未登录词的识别和歧义切分. 据统计:未登录词中中文姓人名在文本中一般只占2%左右,但这其中高达50%以上的人名会产生切分错误.在所有的分词错误中,与人名有关的 ...
- Android——PullToRefresh自动刷新
需求:强制刷新 方法一: PullToRefreshListView本身提供了一个setRefreshing()接口,调用该接口会自动触发下拉刷新的操作(前提是支持下拉刷新).按照一般的操作我们直接在 ...
- Sql Server 基本数据类型
第一大类:整数数据 bit:bit数据类型代表0,1或NULL,就是表示true,false.占用1byte. int:以4个字节来存储正负数.可存储范围为:-2^31至2^31-1. smallin ...
- Mac上vmware虚拟机Windows10安装Tomcat8.0及配置环境
1.下载tomcat8.0或其他版本.下载地址:http://tomcat.apache.org/download-80.cgi 2.双击进行解压. 3.安装成功之后,右键我的电脑 --> 选择 ...
- Linux启动用户空间-init初始化进程
- centos7 初始化安装
CENTOS7 初装 一.分区 挂载路径 格式 容量 / xfs 102400 swap 等同内存大小 /home xfs 剩余 二.时区 Asia/Shanghai 三.安装包选择 选择最小化安装 ...
- struts2中标签库访问静态成员
struts2中是可以访问静态成员的,需要以下设置: 1.设置配置文件 struts.xml 中如下: <!-- 设置运行通过ONGL访问静态方法 --> <constant nam ...
- 搭建Lvs负载均衡群集
一.Lvs详解 lvs内核模型 1.模型分析 用户访问的数据可以进入调度器 匹配调度器分配的虚拟IP|IP+端口(路由走向) 根据调度器的算法确定匹配的服务器 2.调度条件:基于IP.基于端口.基于内 ...