常用sql相关
1修改基本表
添加列 alter table tableName add<新列名><数据类型>[完整性约束]
删除列 alter table tableName drop<新列名><数据类型>[完整性约束]
2创建
建表create table tableName(
id primary key AUTO_INCREMENT(mysql);
id primary key identity(1,1)(sql server)
)
建立索引
create index OID_IDX on 表名(number);
create unique index oin_idx on 表名(number);创建唯一索引
3 删除
删除索引 drop index <索引名>
删除表 drop table <表名>
4 sql功能
数据查询 select
数据定义 create drop alter
数据操控 insert update delete
数据控制 grant(授权) revoke(收回权限)
(1) 数据查询
select * from tableName where <条件表达式> group by<列名>[having<条件>] order by<列名>[ASC DESC]
select distinct Sno from sc 查询数据去掉重复行
常见的查询条件
比较 = ,>,<,<=,<=,!=,<>,!<,!>,
确定范围 between and |not between and
确定集合 in ,not in
字符匹配 like ,not like like '<匹配符>' 匹配符可以包含通配符%和_
空值 is null ,is not null
多重条件(逻辑运算) and,or,not
select a.name,a.mialbox from a where EXISTS(select b.name from b where a.name=b.name)
联接查询join
select a.number,a,name,b.age,b.sort from a join b on a.number=b.number
inner join 内联接 用于返回两个表中要查询的列数据 left join right join
常见运算以及聚集函数
ABS(x)返回绝对值
&
相关文档:
在sql中创建用户自定义拼音函数:
create function f_GetPy(@Str nvarchar(400))
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert @t select '吖','A' union all select '八','B'
union all select '嚓 ......
SQLServer基本函数
1.字符串函数 :
字符操作类 :
upper(char_expr) 转为大写
lower(char_expr) 转为小写
UCase(string) 返回 Variant (String),其中包含转成大写的字符串。
LCase(string) 返回字符串的小写形式。
space(int_expr) 生成int_expr个空格
replicate(char_expr,int_expr) 复制字符串int_expr次
......
在数据库开发过程中,当你检索的数据只是一条记录时,你所编写的事务语句代码往往使用SELECT INSERT 语句。但是我们常常会遇到这样情况,即从某一结果集中逐一地读取一条记录。那么如何解决这种问题呢?游标为我们提供了一种极为优秀的解决方案。 1.1 游标和游标的优点 在数据库中,游标是一个十分重要的概念。游标提供了一 ......
1.直接导入数据库
shp2pgsql -s "4326" -W "GBK" E:\shape\Road_polyline.shp
road_cross| psql -U postgres -h 172.17.40.83 -d test
2.导出sql
shp2pgsql -s "4326" E:\shape\Road_polyline.shp blocks >
E:\roadcross\blocks.sql
3 ......