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 --