ArcGIS拓扑规则说明

2024-10-19 17:34:08

1创建数据库

  创建之前判断该数据库是否存在

if exists (select * fr泠贾高框om sysdatabaseswhere name='databaseName')

drop database databaseName

go

Create DATABASE databasename

2删除数据库

drop database dbname

3备份sql server

---创建备份数据的device

USE master

EXEC sp_addumpdevice 'disk', 'testBack','c:\mssql7backup\MyNwind_1.dat'

---开始备份

BACKUP DATABASE pubs TO testBack

4创建新表

create table tabname(col1 type1 [notnull] [primary key],col2 type2 [not null],..)

  根据已有的表创建新表:

A:go

use原数据库名

go

select * into目的数据库名.dbo.目的表名from原表名(使用旧表创建新表)

B:create table tab_new as select col1,col2… fromtab_old definition only

5创建序列

create sequence SIMON_SEQUENCE

minvalue 1 --最小值

maxvalue 999999999999999999999999999 --最大值

start with 1 --开始值

increment by 1 --每次加几

cache 20;

6删除新表

drop table tabname

7增加一个列

Alter table tabname add colname coltype

8删除一个列

Alter table tabname drop column colname

9添加主键

Alter table tabname add primary key(col)

  说明:删除主键:Alter table tabname drop primarykey(col)

10创建索引

create [unique] index idxname ontabname(col…。)

  删除索引:drop index idxname on tabname

  注:索引是不可更改的,想更改必须删除重新建。

11创建视图

create view viewname as select statement

  删除视图:drop view viewname

12简单基本的sql语句

(1)数据记录筛选:

sql="select * from数据表where字段名=字段值order by字段名[desc]"

sql="select * from数据表where字段名like '%字段值%' order by字段名[desc]"

sql="select top 10 * from数据表where字段名=字段值order by字段名[desc]"

sql="select top 10 * from数据表order by字段名[desc]"

sql="select * from数据表where字段名in ('值1','值2','值3')"

sql="select * from数据表where字段名between值1 and值2"

(2)更新数据记录:

sql="update数据表set字段名=字段值where条件表达式"

sql="update数据表set字段1=值1,字段2=值2 ……字段n=值n where条件表达式"

(3)删除数据记录:

sql="delete from数据表where条件表达式"

sql="delete from数据表" (将数据表所有记录删除)

(4)添加数据记录:

sql="insert into数据表(字段1,字段2,字段3 …) values (值1,值2,值3…)"

sql="insert into目标数据表select * from源数据表" (把源数据表的记录添加到目标数据表)

(5)数据记录统计函数:

AVG(字段名)得出一个表格栏平均值

COUNT(*;字段名)对数据行数的统计或对某一栏有值的数据行数统计

MAX(字段名)取得一个表格栏最大的值

MIN(字段名)取得一个表格栏最小的值

SUM(字段名)把数据栏的值相加

  引用以上函数的方法:

sql="select sum(字段名) as别名from数据表where条件表达式"

set rs=conn.excute(sql)

  用rs("别名")获取统计的值,其它函数运用同上。

  查询去除重复值:select distinct * from table1

(5)数据表的建立和删除:

CREATE TABLE数据表名称(字段1类型1(长度),字段2类型2(长度) …… )

(6)单列求和:

SELECT SUM(字段名) FROM数据表

13几个高级查询运算词

A:UNION运算符

UNION运算符通过组合其他两个结果表(例如TABLE1和TABLE2)并消去表中任何重复行而派生出一个结果表。当ALL随UNION一起使用时(即UNION ALL),不消除重复行。两种情况下,派生表的每一行不是来自TABLE1就是来自TABLE2。

B:EXCEPT运算符

EXCEPT运算符通过包括所有在TABLE1中但不在TABLE2中的行并消除所有重复行而派生出一个结果表。当ALL随EXCEPT一起使用时(EXCEPT ALL),不消除重复行。

C:INTERSECT运算符

INTERSECT运算符通过只包括TABLE1和TABLE2中都有的行并消除所有重复行而派生出一个结果表。当ALL随INTERSECT一起使用时(INTERSECT ALL),不消除重复行。

  注:使用运算词的几个查询结果行必须是一致的。

14使用外连接

A、left outer join:

  左外连接(左连接):结果集既包括连接表的匹配行,也包括左连接表的所有行。

SQL: select a.a, a.b, a.c, b.c, b.d, b.ffrom a LEFT OUT JOIN b ON a.a = b.c

B:right outer join:

  右外连接(右连接):结果集既包括连接表的匹配连接行,也包括右连接表的所有行。

C:full outer join:

  全外连接:不仅包括符号连接表的匹配行,还包括两个连接表中的所有记录。

15判断数据库是否存在

if exists (select*fromsysdatabaseswhere name= '数据库名')

dropdatabase[数据库名]

16判断表是否存在

if not exists (select * from sysobjectswhere [name] = '表名'and xtype='U')

begin

--这里创建表

end

17判断存储过程是否存在

if exists (select*fromsysobjectswhereid = object_id(N'[存储过程名]')and OBJECTPROPERTY(id, N'IsProcedure') = 1)

dropprocedure[存储过程名]

18判断临时表是否存在

if object_id('tempdb..#临时表名')isnot null

droptable#临时表名

19判断视图是否存在

--SQL Server 2000

IF EXISTS (SELECT*FROMsysviewsWHEREobject_id = '[dbo].[视图名]'

--SQL Server 2005

IF EXISTS (SELECT*FROMsys.viewsWHEREobject_id = '[dbo].[视图名]'

20判断函数是否存在

if exists (select*fromdbo.sysobjectswhereid = object_id(N'[dbo].[函数名]') and xtype in (N'FN', N'IF', N'TF'))

dropfunction[dbo].[函数名]

21获取创建信息

SELECT[name],[id],crdateFROMsysobjectswherextype='U'

/*

xtype的表示参数类型,通常包括如下这些C =CHECK约束D =默认值或DEFAULT约束F =FOREIGNKEY约束L =日志FN =标量函数IF =内嵌表函数P =存储过程PK =PRIMARYKEY约束(类型是K)RF =复制筛选存储过程S =系统表TF =表函数TR =触发器U =用户表UQ =UNIQUE约束(类型是K)V =视图X =扩展存储过程*/

22判断列是否存在

if exists(select*fromsyscolumnswhereid=object_id('表名')andname='列名')

altertable表名dropcolumn列名

23判断列是否自增列

ifcolumnproperty(object_id('table'),'col','IsIdentity')=1

print '自增列'

else

print '不是自增列'

SELECT*FROMsys.columnsWHEREobject_id=OBJECT_ID('表名')

AND is_identity=1

24判断表中是否存在索引

if exists(select*fromsysindexeswhereid=object_id('表名')andname='索引名')

print '存在'

else

print '不存在

25查看数据库中对象

SELECT*FROMsysobjectsWHEREname='对象名'

select * from table(所要查询的表名)where coloum(条件)

26复制表

(只复制结构,源表名:a新表名:b) (Access可用)

  法一:select * into b from a where 1<>1

  法二:select top 0 * into b from a

27拷贝表

(拷贝数据,源表名:a目标表名:b) (Access可用)

insert into b(x, y, z) select d,e,f froma;

28跨数据库之间表的拷贝

(具体数据使用绝对路径)(Access可用)

insert into b(x, y, z) select d,e,f froma in ‘具体数据库’where条件

  例子:。.from b in'"&Server.MapPath("."&"\data.mdb" &"'where..

29子查询

(表名1:a表名2:b)

select a,b,c from a where a IN (select dfrom b或者:select a,b,c from a where a IN (1,2,3)

30显示文章最后时间

select a.title,a.username,b.adddate fromtable a,(select max(adddate) adddate from table where table.title=a.title) b

31外连接查询

(表名1:a表名2:b)

select a.a, a.b, a.c, b.c, b.d, b.f froma LEFT OUT JOIN b ON a.a = b.c

32在线视图查询

(表名1:a

select * from (Select a,b,c FROM a) Twhere t.a > 1;

33between的用法

between为查询某字段的指定范围,限制查询数据范围时包括了边界值,not between不包括边界值

select * from table1 where time betweentime1 and time2

select a,b,c, from table1 where a notbetween数值1and数值2

34in的使用方法

select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)

35删除主表没有的信息

  两张关联表delete from table1 where not exists (select * from table2 where table1.field1=table2.field1

36四表联查问题

select * from a left inner join b ona.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....

37日程安排提前五分钟

SQL: select * from日程安排where datediff('minute',f开始时间,getdate())>5

38一条sql搞定数据库页

select top 10 b.* from (select top 20主键字段,排序字段from表名order by排序字段desc) a,表名b where b.主键字段= a.主键字段order by a.排序字段

39前10条记录

select top 10 * from table1 where范围

40选择排名

  选择在每一组b值相同的数据中对应的a最大的记录的所有信息(类似这样的用法可以用于论坛每月排行榜,每月热销产品分析,按科目成绩排名,等等。)

select a,b,c from tablename ta wherea=(select max(a) from tablename tb where tb.b=ta.b)

41派生结果表

  包括所有在TableA中但不在TableB和TableC中的行并消除所有重复行而派生出一个结果表

(select a from tableA except (select afrom tableB) except (select a from tableC)

42随机取出10条数据

select top 10 * from tablename order bynewid()

43随机选择记录

select newid()

猜你喜欢