SQL 实用语句

2016-02-19 09:32 7 1 收藏

今天图老师小编要向大家分享个SQL 实用语句教程,过程简单易学,相信聪明的你一定能轻松get!

【 tulaoshi.com - 编程语言 】

id name
1 a
2 b
3 c
1 a
2 b
3 c

以下的sql语句都以上面表mytable为准:

1、查询id=1,3记录的所有数据
代码如下:

select * from mytable where id in(1,3)

2、删除id重复的数据,表中数据只剩下id=1,2,3的所有数据
代码如下:

select * into # from mytable
truncate table mytable

insert table select distinct * from #
select * from table
drop table #

3、创建一个新表 films_recent ,它的值包含来自表films
代码如下:

SELECT * INTO films_recent FROM films

来源:https://www.tulaoshi.com/n/20160219/1591167.html

延伸阅读
说明:复制表(只复制结构,源表名:a 新表名:b) select * into b from a where 11 说明:拷贝表(拷贝数据,源表名:a 目标表名:b) insert into b(a, b, c) select d,e,f from b; 说明:显示文章、提交人和最后回复时间 select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title...
1.调整内存 sp_configure 'show advanced options',1 GO RECONFIGURE Go sp_configure 'awe enabled', 1 GO RECONFIGURE Go sp_configure 'min server memory',1024 Go sp_configure 'max server memory',3072 GO RECONFIGURE Go PS: OS需要打开AWE 即在boot.ini里 添加 /3G 或者 /PAE (企业版)才能支持4G以上内存! 2.关...
标签: SQLServer
为了大家更容易理解我举出的SQL语句,本文假定已经建立了一个学生成绩管理数据库,全文均以学生成绩的管理为例来描述。 1.在查询结果中显示列名: a.用as关键字:select name as '姓名' from students order by age b.直接表示:select name '姓名' from students order by age 2.精确查找: a.用in限定范围:select *...
都是一些精典实用的常用语句. MYSQL显示数据库或表: 以下为引用的内容: show databases;//然后可以use database_name; show tables; MYSQL更改表名: alter table table_name rename new_t; MYSQL添加列 : alter table table_name add column c_n column attributes; MYSQL删除列: alter table tabl...
标签: MySQL mysql数据库
2006-10-8 表数据:tab1 id    name  num A     a         9 A     b       11 B     f         7 B     g  ...

经验教程

880

收藏

70
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部