22 Haziran 2010 Salı

A LITTLE MSSQL (TRANSACT SQL)...

I guess I am little out of the purpose of the blog but I am put effort on my internship so I cannot give my all attention to Webing. Also I do not want to stay my blog empty. In that way, I share my today's work. I try to learn SQL in Microsoft way. Here my codes with short explanations just to give little sense about SQL.

SQL is a universal standard language to manage Databases but it has different styles respected to the server systems such as MsSql, MySql ... So now I am talking about "Transact SQL" that work with Microsoft Server system "MSSQL".

FOR MORE INFO.


HERE SOME BASIC EXAMPLE CODES WRITTEN IN THE QUERY FILES



CREATE DATABASE BookDatabase3
GO

DROP DATABASE BookDatabase3 --delete database
GO

USE BookDatabase2; --use database

PRINT 'This is EREN''s experiment on MSSQL';

SELECT (SELECT 448.25); --print on table
GO

SELECT 'Ahmet' AS 'Author Name', '43' AS Age;--AS using to define the column name

DECLARE @Mustafa int, @Ali int, @Ahmet int; --define a variable @ must be added

SELECT @Mustafa = 46;--initialize the variable

SET @Ali = 43;--initialize the variable

DECLARE @IsFamous bit;
SET @IsFamous = 1;
SELECT @IsFamous AS [Is Famuos?];
Go

DECLARE @Distance DEcimal(6,2);
SET @Distance = 208.12;
SELECT @Distance;
GO

DECLARE @Name char(20);--using string as char array
SET @Name = 'Eren';
SELECT @Name AS 'My Name';
GO


--CREATE TYPE shortString FROM nchar(20); --create your own data type

DECLARE @num1 int, @num2 int;

--CONDTITIONAL STATEMENT
SET @num1 = 20;
SET @num2 = 20;
IF (@num1 = @num2)
BEGIN
PRINT 'Numbers are not equal';
PRINT 'Change the code';
END
GO


--SWITCH - CASE of alertnative
DECLARE @num1 int, @num2 int, @Result char(20);
SET @num1 = 20;
SET @num2 = 20;
SET @Result = CASE @num2
WHEN 1 THEN 'It is 1'
WHEN 2 THEN 'It is 2'
WHEN 3 THEN 'It is 3'
ELSE 'It is nothing'
END
PRINT @Result;
Go

--WHILE ITERATION
DECLARE @Number As int
SET @Number = 1
WHILE @Number < 5
BEGIN
SELECT @Number AS Number
SET @Number = @Number + 1
END
GO

Hiç yorum yok:

Yorum Gönder