Google Analytics İzleme

18 Nisan 2012

sql server - t-sql ile kodlama ve yardımcı bilgiler


---
Sql prosedürü için hata mesajı verdirmek için kullanılan metod:
raiserror(N'Belirttiğiniz CdcContextId geçersizdir.',0,0)

Sql prosedüründe ara bir yerde bitişi sağlama:
return


declare @countOfContextID int
  select @countOfContextID=count(ContextId) from dbo.AA_Context where ContextId = @AAContextId
  if @countOfContextID=0
  begin
    -- hata atılacak
    raiserror(N'Belirttiğiniz AAContextId geçersizdir.',0,0)
    return
  end

Kaynak:
http://stackoverflow.com/questions/659188/sql-server-stop-or-break-execution-of-a-sql-script
http://msdn.microsoft.com/en-us/library/ms178592(v=sql.90).aspx

SQL Server RAISERROR Kullanım Çeşitleri – Raiserror Using
http://www.sebahattint.com/2011/06/23/sql-server-raiserror-kullanim-cesitleri-raiserror-using/


--

Cursor oluşturma ve kullanma:

declare @CourseID varchar(10),
    @LearningOutcomes1EN varchar(8000)


declare cur_course cursor for
    select CourseID,
    LearningOutcomes1EN
    from dbo.Course




open cur_course
  fetch next from cur_course into @CourseID,
    @LearningOutcomes1EN


while @@fetch_status = 0
begin

-- istenen işlemler yapılır


fetch next from cur_course into @CourseID,
        @LearningOutcomes1EN


end -- end of while

close cur_course
deallocate cur_course





--


Transact-SQL (T-SQL) is Microsoft's and Sybase's proprietary extension to the SQL language. Microsoft's implementation ships in the Microsoft SQL Server product. Sybase uses the language in its Adaptive Server Enterprise, the successor to Sybase SQL Server.


Transact-SQL enhances SQL with these additional features:

* Control-of-flow language
* Local variables
* Various support functions for string processing, date processing, mathematics, etc.
* Improvements to DELETE and UPDATE statements

Transact-SQL User's Guide
http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/40957;pt=41423

--

Try Catch kullanımı:
http://geekswithblogs.net/ram/archive/2006/10/12/93829.aspx

Using @@ERROR
http://msdn.microsoft.com/en-us/library/ms190193(v=sql.90).aspx

--

SQLS*Plus is like an Oracle© SQL*Plus / sqlplus for Microsoft© SQLServer 2008, 2005 and 2000
http://www.memfix.com/





Hiç yorum yok: