1、純量值函式 1)、建立create function fun_max(@x int, @y int)--純量涵式returns int asbegin if @x<@y set @x = @y return @xenddeclare @x int, @y int set @x=1set @y=2print 'max= ' +cast(dbo.fun_max(@x,@y) as char) create function fun_max(@x int, @y int)--純量涵式
1. 顯示所有的使用者資料庫:select dbid, name, filename from master.dbo.sysdatabases where dbid>42. 顯示資料庫中所有的表:當前資料庫:select name from {DB_NAME}..sysobjects where xtype='u'制定資料庫:select name from {DB_NAME}..sysobjects where xtype='u'3. 顯示資料庫中所有預存程序:select
1.“俄羅斯預存程序”的改良版CREATE procedure pagination1(@pagesize int, --頁面大小,如每頁儲存20條記錄@pageindex int --當前頁碼)as set nocount onbegindeclare @indextable table(id int identity(1,1),nid int) --定義表變數declare @PageLowerBound int --定義此頁的底碼declare @PageUpperBound int --
項目需求:在我的預存程序中要調用組內其它人寫的預存程序,取得它返回的資料集與我自己的資料做聯集查詢。 該預存程序是帶輸入和輸出參數的,並且預存程序裡有插入暫存資料表的操作。 我嘗試了網上的幾種解決辦法,都不能奏效:1.insert into #tmpTable exec Pro 【insert語句不能嵌套】2.insert into #tmpTable select * from openrowset('SQLNCLI','DRIVER={SQL
CASE 可能是 SQL 中被誤用最多的關鍵字之一。雖然可能以前用過這個關鍵字來建立欄位,但是它還具有更多用法。例如,可以在 WHERE 子句中使用 CASE。首先讓我們看一下 CASE 的文法。在一般的 SELECT 中,其文法如下:以下為引用的內容:SELECT <myColumnSpec> = CASE WHEN <A> THEN <somethingA> WHEN <B> THEN <somethingB> ELSE
有時我們要用到大量操作時都會對字串進行拆分,可是SQL Server中卻沒有內建Split函數,所以要自己來實現了。沒什麼好說的,需要的朋友直接拿去用吧 SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO/*by kudychen 2011-9-28 */CREATE function [dbo].[SplitString](@Input nvarchar(max), --input string to be separated
Type是在6.0就有的,XType在7.0才出現: Type 物件類型。可以是下列值之一: C = CHECK 約束 D = 預設值或 DEFAULT 約束 F = FOREIGN KEY 約束 FN = 純量涵式 IF = 內嵌表函數 K = PRIMARY KEY 或 UNIQUE 約束 L = 日誌 P = 預存程序 R = 規則 RF =
if object_id('tb') is not nulldrop table tbgocreate table tb(name varchar(25))insert into tbselect 'z,y,w,c' union allselect '1,2,3,4' select name=substring(a.name,b.number,(charindex(',',a.name+',',b.number))-b.number) from tb a,master..spt_values
在改進SQL Server 7.0系列所實現的安全機制的過程中,Microsoft建立了一種既靈活又強大的安全管理機制,它能夠對使用者訪問SQL Server伺服器系統和資料庫的安全進行全面地管理。按照本文介紹的步驟,你可以為SQL Server 7.0(或2000)構造出一個靈活的、可管理的安全性原則,而且它的安全性經得起考驗。 一、驗證方法選擇