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 ...
随机推荐
- CentOS7下安装二进制MYSQL8
早看到MySQL8发布, 性能相比MySQL7提升2倍,今天准备安装下试试看 1.先卸载当前系统中已安装的mariadb rpm -qa | grep mariadb rpm -e mysql*/ma ...
- 无滚动条GridView少量图片展示
import android.content.Context; import android.util.AttributeSet; import android.util.Log; import an ...
- codeforces 544 D Destroying Roads 【最短路】
题意:给出n个点,m条边权为1的无向边,破坏最多的道路,使得从s1到t1,s2到t2的距离不超过d1,d2 因为最后s1,t1是连通的,且要破坏掉最多的道路,那么就是求s1到t1之间的最短路 用bfs ...
- Android chromium 1
For Developers > Design Documents > Java Resources on Android Overview Chrome for Android ...
- php重新编译,gd扩展支持jpeg文件
晚上写东西的时候,报了一个错误: Call to undefined function imagecreatefromjpeg() 没有开启 jpeg 支持?原来是默认安装的 gd 扩展默认不支持 j ...
- Incermental GC
目录 增量式垃圾回收 什么是增量式垃圾回收 三色标记算法 GC 标记清除算法的分割 根查找阶段 标记阶段 写入屏障 清除阶段 分配 优点和缺点 缩短最大暂停时间 降低了吞吐量 Steele 的算法 m ...
- 紫书 习题 10-7 UVa 10539(long long + 素数筛)
注意要开long long 如果int * int会炸 那么久改成long long * int #include<cstdio> #include<vector> #incl ...
- jquery中$.get()提交和$.post()提交有区别
jquery中$.get()提交和$.post()提交有区别吗? 相同点:都是异步请求的方式来获取服务端的数据: 异同点: 1.请求方式不同:$.get() 方法使用GET方法来进行异步请求的.$.p ...
- ECNUOJ 2149 华丽的队列
华丽的队列 Time Limit:3000MS Memory Limit:65536KBTotal Submit:531 Accepted:68 Description 每年,都有很多新同学来到我们 ...
- ArcGIS 空间查询
public static bool QueryMessPoint(IActiveView activeView, IFeatureClass featureClass, string whereCl ...