① T-SQL程序設計(用戶自定義函數)
很簡單,但是以後最好能認真點, 首先你問問提至少要帶個請字吧,大學老師留的課題你直接抄過來就完事了?
給你說最後一個
create function f_tableinfo
(
@tableName nvarchar(200)
)
returns @result table (
ColName nvarchar(200),
ColType nvarchar(200),
ColLength int,
ColIsNull bit
)
as
begin
insert into @result(ColName,ColType,ColLength,ColIsNull)
select
c.[name] as ColumnName,
t.[name] as ColumnType,
c.max_length as MaxLength,
c.is_nullable as [IsNull]
from sys.columns c
inner join sys.types t on c.system_type_id=t.system_type_id
where c.[object_id]=object_id(@tableName) and t.[name]<>'sysname'
order by c.column_id
return
end
② T-SQL編程入門經典的內容簡介
《T-SQL編程入門經典(涵蓋SQL Server 2008&2005)》是學習T-SQL編程的最佳入門指南,涵蓋了在SQL Server 2005和2008中使用T-SQL的所有基礎知識,並結合實例較深入地探討了T-SQL最常見的應用。重點介紹了如何使用T-SQL創建管理資料庫的工具、如何使用視圖、用戶自定義函數和存儲過程進行T-SQL編程,如何優化查詢性能以及如何創建資料庫等內容。
幾乎所有的企業應用程序都要讀取、存儲和處理關系資料庫中的數據。只要使用Microsoft SQL Server,就需要學習使用T-SQL,這是Microsoft為ANSI標準的SQL資料庫查詢語言提供的強大的實現方案。
《T-SQL編程入門經典(涵蓋SQL Server 2008&2005)》介紹了在SQL Server 2008和2005中使用T-SQL的所有基礎知識。作者是頂尖的T-SQL專家,他們從SQL Server的本質出發首先介紹了掌握T-SQL所需的內容,接著討論T-SQL本身,包括數據檢索的核心元素、SQL函數、聚合和分組,以及多表查詢,還詳細介紹了事務處理以及使用T-SQL處理數據的方法。
《T-SQL編程入門經典(涵蓋SQL Server 2008&2005)》還描述了如何創建和管理T-SQL編程對象,包括視圖、函數和存儲過程,詳細論述了如何優化T-SQL查詢的性能,如何為實際的企業應用程序設計查詢。《T-SQL編程入門經典(涵蓋SQL Server 2008&2005)》的所有方法和技巧都可用於Microsoft SQL Server 2008和2005資料庫。
另外,《T-SQL編程入門經典(涵蓋SQL Server 2008&2005)》還包含較全面的參考附錄,包括T-SQL命令語法、系統變數和函數、系統存儲過程、信息模式視圖和FileStream對象。
③ T-SQL語言編程
4.create proc G4 @power
as
begin
declare @x int
if @power<=50
set @x=2.6*@power
else
set @x=2.6*50+(@power-50)*5.2
print @x
end
5.create proc G5
as
begin
declare @x int
set @x=1
while @x<=500
begin
if @x%3=2 and @x%5=3 and @x%7=2
print @x
set @x=@x+1
end
end
6.create proc G6
as
begin
declare @y int,@z int,@x int,@n int
select @y=1,@n=0
While @y<=9
begin
Set @z=1
while @z<=12
begin
Set @x=1
while @x<=72
begin
if @y*4+@z*3+@x*0.5=36 and @y+@z+@x=36
begin
set @n=@n+1
print '第'+ltrim(str(@n))+'方法:'
print '男人數:'+ltrim(str(@y))
print '女人數:'+ltrim(str(@z))
print '小孩數:'+ltrim(str(@x))
end
set @x=@x+1
end
set @z=@z+1
end
set @y=@y+1
end
end
④ 編寫一個TSQL程序,該程序完成如下功能:
if (select qty from proctku a,proct b where a.proctno=b.proctno and a.proctno='00002')>0
delete from proct where proctno='00002'
delete from proctku where proctno='00002'
else
select '編號為00002的商品庫存不為0,不能刪除!'