Skip to main content

Posts

Showing posts from December, 2011

Unicode-Why do some SQL strings have an 'N' prefix?

 You may have seen Transact-SQL code that passes strings around using an N prefix. This denotes that the subsequent string is in Unicode (the N actually stands for National language character set). Which means that you are passing an NCHAR, NVARCHAR or NTEXT value, as opposed to CHAR, VARCHAR or TEXT. Unicode is typically used in database applications which are designed to facilitate code pages which extend beyond the English and Western Europe code pages. Example: Chinese.

Trigger command

Trigger command is used to show notification if something is altered in the table like the table could be updated or deleted etc As an example to show how the trigger command works, I made a table and here is the query-- SET NOCOUNT ON /*helps to turn on to notify us  whenever there is update or insert operations done on our table*/ CREATE TABLE Source (Sou_ID int IDENTITY, Sou_Desc varchar(10)) go CREATE TRIGGER tr_Source_INSERT ON Source FOR INSERT AS PRINT GETDATE() go    INSERT Source (Sou_Desc) VALUES ('Test 1')   output::: --------------------- today's date and time

declaring a Variable and using in example

This example shows how to declare a variable and as an example, i have written a code of printing multiples of 2 upto 10 values declare @multi2 integer declare @ans integer set @multi2=0 set @ans=1 while @multi2<11 begin set @ans= @multi2 *2; print '2 *'+cast(@multi2 as varchar)+'='+cast(@ans as varchar) set @multi2= @multi2+1 end