关 键 词:
Sp_adduser 在当前数据库中增加一个用户
sp_changegroup 改变数据库用户组
Sp_dboption 查询或改变数据库系统设置
Sp_dropdevice 删除设备
Sp_dropgroup 删除组
Sp_droplogin 删除帐号
Sp_help 查询数据库对象及所有数据库信息
Sp_helpdb 查询数据库信息
Sp_helpdevice 查询设备信息
Sp_helpgroup 查询组信息
Sp_helpindex 查询给定表信息
Sp_helpuser 查询用户信息
Sp_lock 查询当前加锁信息
Sp_monitor 查询SQL服务器统计信息
Sp_password 改变登录帐号口令
Sp_spaceused 查询表中的行数、数据页数及空间大小
Sp_who 查询当前用户及过程信息
Sp_syntax 查询操作语法
Sp_configure 配置系统参数
例:
1> sp_helpdb
2> go
name db_size owner dbid created status
--------------------------------------------------------------------------
master 3.0 MB sa 1 Jan 01, 1900 no options set
model 2.0 MB sa 3 Jan 01, 1900 no options set
sybsystemprocs 10.0 MB sa 4 Oct 24, 1997 trunc log on chkpt
tele114 370.0 MB sa 5 Oct 24, 1997 select into/bulkcopy, trunc log on chkpt
tempdb 22.0 MB sa 2 May 05, 1998 select into/bulkcopy
(0 rows affected, return status = 0)
例:
1> sp_monitor
2> go
last_run current_run seconds
-------------------------- -------------------------- -----------
May 5 1998 4:09PM May 5 1998 4:13PM 224
(0 rows affected)
cpu_busy io_busy idle
------------------------- ------------------------- -------------------------
17(1)-0% 5(0)-0% 923(223)-99%
(0 rows affected)
packets_received packets_sent packet_errors
------------------------- ------------------------- -------------------------
21(9) 51(23) 0(0)
(0 rows affected)
total_read total_write total_errors connections
------------------- ------------------- ------------------- ------------------
947(1) 595(113) 0(0) 3(1)
(0 rows affected, return status = 0)
(5)触发器(Triggers)
触发器是一种特殊的存储过程,用来维护不同表中的相关数据的一致性。当在一张表中插入、删除和修改数据时,触发器就会触发另一个存储过程,从而保持数据的一致性。
(6)缺省与规则(Defaults and rules)
缺省是在数据录入时,若用户没有输入数据,SQL Server自动输入的值。
规则是可以理解为对数据库、某一列、某用户数据类型的限制。
三、SQL 查询语言
SQL不仅包括查询数据的有关命令,还包括创建数据库及其对象,增、删、改数据等功能。分别定义为数据查询语言,数据定义语言及数据操作语言。这里先介绍数据查询语言。其基本句法为:
Select select_list from table_list where search_conditions
1、简单查询
A、选择若干列
Select expression [,expression]... From table_list
B、选择若干行
查出电话号码以415到头的记录
Select * from code_1th where tel like \'415%\'
查询中消除值重复的行
Select distinct tel from code_1th
对Text 和 char 可用 like ,其中可用通配符‘%’及‘-’,分别代表多个字符和单个字符。
其他常用查询条件有:(出text类型除外)
大小比较 =、>、<、>=、<=、!=、!>、!<
范围确定 between exp1 and exp2 /net between exp1 and exp2
列表或集合 in (exp1[,exp2,[...]]) not in (...)
谓词 like
多重条件 and or not
2、连接查询
A、等值连接和不等值连接:通过‘=’来比较两个表之间的数据时,称为等值连接;而通过其他比较符时,称为不等值连接
等值连接:
Select * from publishers, authors where publishers.city=authors.city
不等值连接:
B、自然连接: 在连接的目标列中相同名的列只保留一个
Select publishers.pub_id publishers.pub_name, publishers.state, authors.*
From publishers, authors where publishers.city=authors.city
3、子查询
A、表达式子查询
Select au_lname, au_fname from authors where city=
(select city from publishers where pub_name="abcde"

