Declare
@pr char(20) --定义变量
Exec
存储过程名
参数
--
执行存储过程
CREATE
PROCEDURE dbo.sp_who
AS SELECT
getDate() --创建存储过程
create
function hh (@payRate float)—
实现函数
returns
float
as
begin
return (@payRate*8*30)
end
-—
创建索引
create
(clustered)index indName
on
tableName(DepartmentID)
--
创建视图
create
view vi
as
select * from Person.Address
--
重命名
sp_rename
[dbo.vi],newvi
sp_renamedb
odlName,[newName]
--
激活全文搜索
sp_fulltext_database
enable
--
数据库编程语句
if
boolean_exception
{sql
语句
}
else
{sql
语句
}
case
表达式
where
布尔表达式
then
sql
语句
where
布尔表达式
then
sql
语句
[else sql
语句
]
End
while
布尔表达式
{sql
语句
}
[break]
[continue]
—-
以下是
case
事例
select
EmpliyeeID,'Marital Status'=
case
MaritalStatus--
如果是
M
就显示
Married
如果是
S
就显示
Single
where 'M' then 'Married'
where 'S' then 'Single'
else 'Not specified'
end
from
[table]
--
创建存储过程
create
proc
存储过程名
输入参数
输出参数
as
begin
语句
end
--
创建触发器
create
trigger tt on tablename for delete
as
要执行的语句
--
查询系统中对象的信息
select
* from sysobjects where [name]='??'
in
和
exists --