sql常用记录
查看列:desc 表名;
修改表名:alter table 表名 rename to table2;
添加列:alter table 表名 add column 列名 varchar(30);
删除列:alter table 表名 drop column 列名;
修改列属性: alter table 表名 modify name varchar(22);
1.说明:复制表(只复制结构源表名:a 新表名:b)(法一:select * into b from a where 1<>1),法二:select top () * into b from a;
2.说明:拷贝表(拷贝数据:源表名:a 目标表名: b)
insert Into b(a,b,c)select d,e,f from b;
3.说明:跨数据库之间表的拷贝(具体数据使用绝对路径)
insert into b(a,b,c)select d,e,f from b in '具体数据库' where条件例子: ..from b in ''&serverMapPath(".")&"data.mdb"&""where ..
4.说明:子查询(表名1:a 表名2:b)
select a,b,c from a where a IN(select d from b ) 或者;select a,b,c from a where a IN(1,2,3)
6.说明:外连接查询(表名1:a 表名2:b)
select a.a,a.b,a.c,b.c,b.d,b.f from LEFT OUT JOIN b ON a.a =b.c;
7.说明:在线视图查询(表名1:a)
select * from (select a,b,c from a) T where t.a>1;
8.说明:between的用法 between限制查询数据范围时包括了边界值 not between不包括
select * from table where time between time1 and time2;
select a,b,c from table where a not between 数值1 and 数值2;
9.说明:in的使用方法
select * from table where a [not] in ('值1','值2','值3');
10.说明:日程安排提前五分钟提醒
select * from 日程安排 where datediff(‘minute’,f开始时间.getdate())>5;
11.说明:一条sql语句搞定数据库分页
select top 10 b.*from(select top 20 主键字段,排序字段 from表名 order by 排序字段desc)a 表名b where b 字段= a.主键字段 orderby a.排序字段
12:.说明:前10条记录
select top 10* from table1 where 范围
13.说明:初始化表名table1
TRUNCATE TABLE table1
14.说明:选择从10到15的记录
select top 5 * from(select top 15* from table order by id asc)table_别名 order by id desc‘;