易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL Server 存储过程入门学习

创建存储过程之前要先用use语句声明要将存储过程存储在哪个数据库中. e.g use company; 执行之.之后就可以声明存储过程了. e.g create procedure *** @id varchar(50) , @name int output as select @name=name from table where id=@id 然后可以用alter对存储过程进行修改. declare可以声明一个变量 用set对变量赋值 e.g alter proc getempp @ID int
as
declare @Department int
select @Department=a.Department
from company.dbo.employee a
inner join company.dbo.department b
on a.Department=b.ID
where a.ID=@ID
if @@ROWCOUNT>0
begin
select *
from company.dbo.department
where ID=@Department
select * from company.dbo.employee
where Department=@Department
end
else
begin
RAISERROR('No record found',10,1)
end 上例中的@Department是被选择出来的值,然后用来为下面的if语句块中的查询服务的.


相关文档:

sql语言

select *from customers
 
select *from orders
 
select customers.cust_id, orders.order_num  from customers inner join orders on customers.cust_id=orders.cust_id
 
select customers.cust_id, orders.order_num  from customers left outer join orders on customers.cust_id=orde ......

sql中 in 、not in 、exists、not exists 用法和差别


exists (sql 返回结果集为真) 
not exists (sql 不返回结果集为真) 
如下: 
表A 
ID NAME 
1    A1 
2    A2 
3  A3 
表B 
ID AID NAME 
1    1 B1 
2  & ......

SQL 语句练习


–1、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。
select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),’日期不详’) birthday
from employee
order by dept
–2、查找与喻自强在同一个单位的员工姓名、 ......

SQL中object_id函数的用法

SQL中object_id函数的用法 收藏
 int object_id('objectname');
此方法返回数据库对象标识号。
其中,参数objectname 表示要使用的对象,其数据类型为nchar或char(如果为char,系统将其转换为nchar)
返回类型为int,表示该对象在系统中的编号。
比如:
use wf_timesheet
select object_id('usp_check_excess ......

Sql helper使用方法

    public List<FirmAttachmentModel> LoadFirmAttachmentByFirmId(int FirmId, int pageIndex, int pageSize)
        {
            List<FirmAttachmentModel> result = new List<FirmAtt ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号