/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP 1000 [staff_no]
,[name]
,[sex]
,[dept_id]
FROM [dtms].[dbo].[employee]
exec sp_tables
exec sp_columns employee
declare @a int
declare @b int
declare @c int
set @a=1
select @b =2
set @c=@a+@b
select @c
declare @desc varchar(30)
set @desc='this is a test.'
print @desc
select * from city
insert into city select 3,1,'Rose'
create procedure sp_cityAll
as
select * from city
exec sp_cityAll
create proc sp_getCityByID(@id int)
as
select * from city where id=@id
exec sp_getCityByID 2
create proc sp_city_add(@id int,@pid int,@name varchar(20))
as
insert into city select @id,@pid,@name
exec sp_city_add 4,2,'Jeni'
create proc sp_city_edit @id int,@pid int,@name varchar(20)
as
begin
update city set pid=@pid,name=@name where id=@id
end
exec sp_city_edit 2,6,'中国人'
create proc sp_city_delete(@id int)
as
delete city where id=@id
exec sp_city_delete 4
select * from city
dbo.S
select *from Score
select * from(
select row_number() over(partition by cno order by score desc) as rowid,t.* from Score t
) temp where rowid<=2
select *from dbo.Card
select * from dbo.Score
select *from dbo.SC
exec('select count(*) from sc')
create proc sp_countByTableName(@tableName varchar(50))
as
begin
declare @sql varchar(max)
set @sql='select * from '+@tableName
exec(@sql)
end
exec sp_countByTableName 'Score'
alter proc sp_countByTableName(@tableName varchar(50),@iCount int output)
as
begin
declare @sql nvarchar(max)
set @sql='select @tempCount=count(*) from '+@tableName
EXEC SP_EXECUTESQL @sql,N'@tempCount INT output',@iCount output
end
declare @temp int
exec sp_countByTableName 'sc',@temp output
print @temp
--外面的sql语句必须按如下格式或准标
select row_number() over(partition by cno order by score desc) as rowid,t.* from Score t
alter proc sp_pape(@sql varchar(max),@curIndex int,@pageSize int,@recordCount int output)
as
begin
declare @sIndex int
declare @eIndex int
declare @_sql varchar(max)
declare @sqlCount nvarchar(max)
set @sIndex=(@curIndex-1)*@pageSize+1
set @eIndex=@sIndex+@pageSize-1
set @_sql='select * from ('+@sql+') t where rowid between '+cast(@sIndex as varchar(10))+' and '+cast(@eIndex as varchar(10))
--print @_sql
set @sqlCount='select @tempCount=count(*) from ('+@sql+') t '
EXEC SP_EXECUTESQL @sqlCount,N'@tempCount INT output',@recordCount output
exec(@_sql)
end
declare @temp varchar(300)
declare @tempCount int
--set @temp='select row_number() over(order by score desc) as rowid,t.* from Score t'
set @temp='select row_number() over(order by score desc) as rowid,a.sno,sname,b.cno,b.score from student a left join score b on a.sno=b.sno'
exec sp_pape @temp,2,2,@tempCount output
select @tempCount
select *from dbo.Score