6.12.10

Data Compression in SQL Server 2008

Data compression is a new feature introduced in SQL Server 2008. It enables the DBA’s to effectively manage the MDF files and Backup files. There are two types of compressions,

1. Row Level Compression: This type of compression will work on the row level of the data page.

a. Operations like changing the fixed length datatype to Variable length data type. For instance, Char(10) is a fixed length datatype and If we store “Venkat” as data. The space occupied by this name is 6 and remaining 4 spaces will be wasted in the legacy system. Whereas, In SQL Server 2008, it is utilised effectively. Only 6 spaces will be given to this variable.
b. Removal of Null value and zeros. These values will not be stored in the disk. Instead, they will have a reference in the CI Structure.
c. Reduce the amount of metadata used to store the row.

2. Page Level Compression: This compression will be effective in the page level.

a. This compression follows Row Level Compression. On top of that, Page level compression will work.
b. Prefix Compression - This compression will work on the column level. Repeated data will be removed and a reference will be stored in the Compression information (CI) structure which is located next to the page header.
c. Dictionary Compression – This compression will be implemented as a whole on the page. It will remove all the repeated data and a reference will be placed on the page.

How it works:

Considering, If you a user is requesting for a data. In that case, Relational Engine will take care of getting the request compile, parse and it will request the data from the Storage engine.

Now, our data is in the compressed format. Storage engine will send the compressed data to the Buffer cache which in turn will take care of sending the data to relational engine in uncompressed format. Relational engine will do the modifications on the uncompressed data and it will send the same to buffer cache. Buffer cache will take care of compressing the data and have it for future use. In turn, it will send a copy to the Storage Engine.

Advantages:

1. More data will be stored in the Buffer cache. So, no need to go and search in the disk which inturn reduce the I/O.
2. Disk space is highly reduced.

Disadvantages:

1. More CPU cycles will be used to decompress the data.
2. It will be a negative impact, if the data doesn’t have more null values, zeros and compact/exact data (Equivalent to the declared data type).

Cheers,
Venkatesan Prabu .J

Indexing Table variables in SQL Server

Table variables is a very nice handy tool to store the result set. The major advantage of table variable is that, it will log a very minimal information in the temp database. Initially, I had a thoughts that table variable will reside only in the memory and it won’t interact with any of the database. But, it’s not the case. The data will reside in the temp database but logged very minimally. Index created on the table variables will reside in the tempdb.

Let’s see, how to create indexes on the table variable.

-- Temp table created
DECLARE @VENKAT_VAR TABLE (ID INT)

-- Trying to create an index on the column. It's throwing error.
CREATE CLUSTERED INDEX IDX_VENKAT_VAR ON @VENKAT_VAR(ID)


-- Trying to alter the table variable. It's throwing error.
ALTER TABLE @VENKAT_VAR ADD CONSTRAINT CON_VENKAT_VAR PRIMARY KEY (ID)


-- Here is an option to create the clustered index or primary key on the temp variable.Index on the table variable can be created during table variable creation itself.

DECLARE @VENKAT_VAR TABLE
(ID INT PRIMARY KEY CLUSTERED )

-- We can query on the sys.indexes table to get the index details created on the table variable.

SELECT * FROM TEMPDB.SYS.indexes A INNER JOIN TEMPDB.SYS.tables B
ON A.object_id=B.object_id ORDER BY create_date DESC


Cheers,
Venkatesan Prabu .J

23.10.10

Composite primary key in SQL Server

Primary Key:

A column which is used to identify the records uniquely is referred to as Primary Key.

1. Primary key won't allow Null values.
2. If a Primary key is created, It will automatically create the clustered index on the table. In turn, the data will be sorted based on this column.
3. Only one Primary key can be created for a table.

Composite Primary Key:

1. Multiple columns can participate in the Primary Key which is referred to as composite primary key.

Am creating the table with Composite Primary key on the column ID and Name

CREATE TABLE VENKAT_SAMPLE_TABLE ( ID INT, NAME VARCHAR(100),BIRTHDATE DATETIME
,PRIMARY KEY(ID,NAME))


To get the information about your Primary key on the columns.You can use the below system view.

SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE


In one of the popular forum, I have seen a query. How to achieve it your designer window. Right click on the table and you will get the columns. Press control or Shift key and select the columns -> Right click and you can set the primary key.


Cheers,
Venkatesan Prabu .J

17.10.10

Specifying the schema Name in the Table designer

I have seen a query in a popular forum and I would like to answer the query,

When I create a table, it creates under dbo.
I would like to create it under a different schema, but when I use the 'New Table' dialog, I can never find the field where to specify this.

The answer is,
You need to specify the schema name in the Properties window of the table.


Cheers,
Venkatesan Prabu .J

Grant vs With Grant option in SQL Server

What's the difference between grant and with grant option in SQL Server?

Grant will allow the current user to access the object or provide access to the specified user.

CREATE TABLE venkat_Table (ID INT)
GRANT SELECT ON venkat_Table TOVenkatFriend

With grant option is nothing but a higher level of access provider. This will inform the database that, this user will have access to the particular object and he is having necessary previlege to provide access to other users on the object.

GRANT SELECT ON venkat_Table TO VenkatFriend WITH GRANT OPTION



You can see this option in the schema properties window.
Cheers,
Venkatesan Prabu .J

9.10.10

Sparse Columns in SQL Server 2008

Memory handling on NULL values using sparse columns:

It's a new feature in SQL Server 2008. It enables us to store the null values effectively. Ideally, if the column is NULL. Then, the data won't be stored in the database and it's cost effective solution to save the space. If your table has more Null values, we can opt this solution.

Sparse column is associated with two specialised sub-features:

1. Column Sets - This will provide you the consolidated report of all the sparse columns. We will see this one in our example below.

2. Filtered index - Index will be created on the not null data in the sparse columns.

Limitations and conditions to use Sparse column:

1. We can create index on the sparse column.
2. Sparse column cannot be added on certain column types like text, filestream datatype, geography, image, ntext etc..,
3. Sparse column could not be bounded with default value or rule cannot be applied on it.

Let's see an example,

drop table Venkat_Sparse_ColumnCheck
go
-- created a table to check the sparse column
CREATE TABLE dbo.Venkat_Sparse_ColumnCheck
(
ID INT IDENTITY(1,1) NOT NULL,
FIRST_NAME NVARCHAR(50) NOT NULL,
LAST_NAME NVARCHAR(50) NOT NULL,
ADDRESS1 NVARCHAR(20) SPARSE NULL, -- Sparse columns
ADDRESS2 NVARCHAR(20) SPARSE NULL, -- Sparse columns
CITY NVARCHAR(20) SPARSE NULL, -- Sparse columns
STATE NVARCHAR(2) SPARSE NULL, -- Sparse columns
COUNTRY NVARCHAR(10) SPARSE NULL, -- Sparse columns
ZIP_CODE NVARCHAR(20) SPARSE NULL, -- Sparse columns
CONSTRAINT PK_Venkat_Sparse_ColumnCheck PRIMARY KEY (ID)
)

GO
set nocount on
go

insert into dbo.Venkat_Sparse_ColumnCheck (first_name, last_name, ADDRESS1, ADDRESS2, city, STATE, country, zip_code)
values ('Venkatesan', 'Prabu', '1, first raod', null, 'Dharmapuri', 'TN', 'India', NULL);
insert into dbo.Venkat_Sparse_ColumnCheck (first_name, last_name, ADDRESS1, ADDRESS2, city, STATE, country, zip_code)
values ('Subs', 'subs', '2 Second road', null, 'trichy', 'tr', 'india', '636701');
insert into dbo.Venkat_Sparse_ColumnCheck (first_name, last_name, ADDRESS1, ADDRESS2, city, STATE, country, zip_code)
values ('Janu', 'C', '3 Third road', null, 'trichy', 'tr', 'india', '636701');

-- Here, we are getting a very ordinary output.
Select * from dbo.Venkat_Sparse_ColumnCheck


To see the exact data storage, we need to use the column sets functionality.
Column Set should be defined with datatype as XML and it should be given the condition as ALL_SPARSE_COLUMNS

drop table Venkat_Sparse_ColumnCheck
go

-- created a table to check the sparse column
CREATE TABLE dbo.Venkat_Sparse_ColumnCheck
(
ID INT IDENTITY(1,1) NOT NULL,
FIRST_NAME NVARCHAR(50) NOT NULL,
LAST_NAME NVARCHAR(50) NOT NULL,
ADDRESS1 NVARCHAR(20) SPARSE NULL, -- Sparse columns
ADDRESS2 NVARCHAR(20) SPARSE NULL, -- Sparse columns
CITY NVARCHAR(20) SPARSE NULL, -- Sparse columns
STATE NVARCHAR(2) SPARSE NULL, -- Sparse columns
COUNTRY NVARCHAR(10) SPARSE NULL, -- Sparse columns
ZIP_CODE NVARCHAR(20) SPARSE NULL, -- Sparse columns
ADDRESS_SET XML COLUMN_SET FOR ALL_SPARSE_COLUMNS, -- Column Set to get all the details of the sparse columns
CONSTRAINT PK_Venkat_Sparse_ColumnCheck PRIMARY KEY (ID)
)
GO

set nocount on
go

insert into dbo.Venkat_Sparse_ColumnCheck (first_name, last_name, ADDRESS1, ADDRESS2, city, STATE, country, zip_code)
values ('Venkatesan', 'Prabu', '1, first raod', null, 'Dharmapuri', 'TN', 'India', NULL);
insert into dbo.Venkat_Sparse_ColumnCheck (first_name, last_name, ADDRESS1, ADDRESS2, city, STATE, country, zip_code)
values ('Subs', 'subs', '2 Second road', null, 'trichy', 'tr', 'india', '636701');
insert into dbo.Venkat_Sparse_ColumnCheck (first_name, last_name, ADDRESS1, ADDRESS2, city, STATE, country, zip_code)
values ('Janu', 'C', '3 Third road', null, 'trichy', 'tr', 'india', '636701');

-- Here, we are getting a very ordinary output.
Select * from dbo.Venkat_Sparse_ColumnCheck


Output for the first record,

1, first raod
Dharmapuri
TN
India

Output for the Second record,

2 Second road
trichy
tr
india
636701

Output for the Third record,

3 Third road
trichy
tr
india
636701

Cheers,

Venkatesan Prabu .J

3.10.10

Replication and autonumber generation issue

Sent: 30 September 2010 22:22
To: jvprabhusanthi@gmail.com
Subject: Invoice Number Generation in offline/online database

Hi Venkatesan Prabu


I would like to get your suggestions in regards to invoice number generation in an application that work offline and online

We have a inventory application developed in .net and sql server ,that can work in a LAN by connecting to the server database

Now we need to provide the offline feature for the application, a counter can work independenly without connecting to the server database.i.e, by connecting
to a local copy of the server database

Before the enter any sales data in the counter ,the sales person has to synchronize the data with the server database .to get the stock details and all
Once synchronistation is done,sales bills can be entered from the counter.and in the end of the day or before starting next days work the sales person has to
synchronise the data with the server again.so the Sales details will be available in the server.

The problem here is that the invcoice number generation.Currently the Automatic invoice number is generated using the query

select isNull(Max(BillNumber),0)+1 from PurchaseHeader

If there is more one sales counters that work on local copy of the server database ,the sales billnumber will be duplicated.
because the billNumber is generated from the local database only. when this is uploaded to server there will be duplicate billnumbers

Could you please suggest me some possible solutions to this problem

--
Thanks,
Bijith

Check my Reply for the above problem. Share your thoughts and post some more solutions
Hi Bijith,

Very good practical problem. We can provide multiple solution for your problem.

Below is the best solution for your problem.

1. You need to use Replication for updating your data from local database to master database.
2. In the local database, generate a unique id (Your Invoice number) and amend another unique number (Local counter number). (Your invoice number is 120 and counter id is 20, then the actual invoice number is 12020. The last two number will be unique for your counter).
3. While pushing this data to the master database, generate unique id in the master database and another column will hold the invoice number generated in the local database.

Let me know for any other details needed.
Cheers,
Venkatesan Prabu .J
MVP / MVM / MCITP / MCTS / MCAD / CCNA / QAI
Microsoft SQL Server MVP / Mind Cracker MVP
http://venkattechnicalblog.blogspot.com/

20.9.10

My session at Sydney Microsoft Office

"Presenting a session in Microsoft" It's my greates dream in my life.

In one word, “It’s a Marvellous evening”. Interesting part is, Adam Cogan is my fellow speaker. Working in Microsoft as a Technical Architect and as a Microsoft Regional Director too :-)

Presented my session in Microsoft office, Attended Adam’s session, Techie talks with hard core developers and finally my session is recorded and it will published soon in Microsoft portal.

To be frank, No words to express my joy…. In presenting an evening session to the techie experts in Microsoft, Sydney office.

Sydney Microsoft Office


Speaker’s desk


Preparing my laptop for the presentation

Oops, very big screen…


Started my session with the query, “How a DBA can achieve Enterprise wide Compliance standard?”

Practical demos

Adam cogan’s session on Sharepoint 2010 Wiki Vs Sharepoint 2010 Blog


My kid playing in Microsoft office

My wife and Kid…in MS office

Front row : My wife, Myself, Adam Cogan and a 22 year experienced Microsoft developer
Back row : Hard core techies

Cheers,
Venkatesan Prabu .J

19.9.10

My Session in Sydney SQL User group

My presentation @ Greater Sydney.....

At last, it’s my dream evening. I gave a presentation to the SQL Server Gurus in Sydney…
Almost most of the attendees were having more than 15 years of experience in SQL Server :-)

They live with SQL Server technology. It was a pleasant moments and I have learnt a lot on meeting those technology Gurus.

Intro about me by Grant paisley (SQL Server MVP and Director of Angry Koala pty ltd)


My presentations starts with the query…. Can a DBA manage 100 Servers in One go???????


Discussion on Policy Creation and deployment Strategies

Practical demo on Microsoft in-built policies


My favourite pic (With my 2009 MVP Award)… Query section..


Thank You slide



My Fellow speaker Darren Geros (22 years in IT, Director of NSI Technology Pty Ltd, Director AVOGA Pty Ltd)


Got a fantastic response from the audience and it’s too nice to see some smile faces


Thanks and Regards,
Venkatesan Prabu .J

17.9.10

Dotnet and SQL Job in Hyderabad

I got this from one of my email... May be useful to some one... who really need it...

Urgent requirement for ASP.Net professionals with a minimum experience of 3yrs in relevant field in Hyderabad.

Skills
ASP.Net 35 frame work, Ajax, sql.server 2005/2008, WCSF, classic ASP

Package: 2.4L - 3.0L
Location: Hyderabad

If anybody is interested Send your resumes to bobby.simson13@gmail.com

Cheers,
Venkatesan Prabu .J

16.9.10

Steps in loading your web contents - About browsers


Have you questioned yourself, why my browser is too slow ?????

To load the web page, your browser will traverse 11 sub systems or steps to display your web content :-) Interesting right !!! Let’s see,

1. Network – First subsystem which is responsible for client / server interaction. This relies on the hosted server’s performance and individual user’s network traffic.
2. HTML – Followed by the HTML – sub system. This allows you to download the HTML content from the server and structured it back to the client machine.
3. CSS – Cascade Style sheet, this will provide you the customised colouring and structure to the content. The details will be collected and it will be used later (In point 8).
4. Collections – Accessing metadata information related to your HTML. This guy will take care of Segregating your head and body contents separately.
5. Java script – Client side scripts which will execute based on the user’s action.
6. Marshalling – Java script engine can’t directly interact with the browser. Marshalling is a special communication layer between JavaScript engine and your browser.
7. DOM API – Special API’s responsible for interaction between JavaScript engine and your browser.
8. Formatting – All your objects will be formatted based on the CSS information collected.
9. Block building – Your objects will be segregated as separate blocks
10. Lay out formation – Now, depends on your Web parts or Frames or div tag or Table. Your layouts will be formed.
11. Image Rendering – Rendering of images (or) drawing to the screen through CPU or GPU.

Cheers,
Venkatesan Prabu .J

8.9.10

SQL Profiler InputBuffer events in SQL Server

As a DBA, sometimes you need to identify the last execution happened or happening in your server. What you will exactly do?
1. Start your profiler and check it.
2. Check the process info for the server processes running.
3. In SQL Server 2008, you can opt Activity Monitor.

What else?????????

Here is another method using queries? If you got the spid then DBCC Inputbuffer command will provide you the last execution command of your user. Let's see how?????


Get the current session id

SELECT @@SPID
The output is, 51

Let's execute the below query now,

CREATE TABLE VENKAT_TABLE (Col1 int)
GO
DECLARE @i int;
SELECT @i = 0
BEGIN TRAN
SELECT @i = 0
WHILE (@i < i =" @i">



Now, open another session or connection, and execute the command

DBCC INPUTBUFFER (51);

You will get the last statement executed by the particular session user.

Usually, we will get confused on seeing the sequence of below statements in our profiler.

create table #tmpDBCCinputbuffer ([Event Type] nvarchar(512), [Parameters] int, [Event Info] nvarchar(512))
insert into #tmpDBCCinputbuffer exec ('DBCC INPUTBUFFER(51)')
select [Event Info] from #tmpDBCCinputbuffer


It's nothing but the in-house or profiler query itself. The above statements were used to fetch the latest statements of your server processes.

Cheers,
Venkatesan Prabu .J

Like operator on a column name in SQL Server

To: jvprabhusanthi@gmail.comSubject: Help...Urgent
Hi Prabhu,

i need urgent help from you for sql script.
i have field called "Notes" in table ABC and have another table called XYZ.
XYZ table has five fields 1,2,3,4,5
the requirement is :

select * from abc
where 1=1
and abc.notes like '%xyz.1%'
and abc.notes like '%xyz.2%'
and abc.notes like '%xyz.3%'
and abc.notes like '%xyz.4%'
and abc.notes like '%xyz.5%'

did you understand?
notes field has some long strings... xyz table clumns string should match with that notes from the abc table.
how do i write the sql script.
becoz i have nearly 2000 records in the table.. can you help out plz....
its urgent.
thanks in advance
pinky


----------------------------------------------------------------------------------

It's a very usual question. How to use "Like operator on a column" -> We should use inner join on TableA.Column_Name like TableB.Column_Name


Let's see a small example to understand a little bit.


DROP TABLE PINKY1
DROP TABLE PINKY2

GO
CREATE TABLE PINKY1(NOTES VARCHAR(100))
INSERT INTO PINKY1 VALUES('VENKAT')
INSERT INTO PINKY1 VALUES('VENKATESAN PRABU')
INSERT INTO PINKY1 VALUES('rENKAT')
INSERT INTO PINKY1 VALUES('AENKAT')
INSERT INTO PINKY1 VALUES('AENKAT')
INSERT INTO PINKY1 VALUES('zxNKAT')
INSERT INTO PINKY1 VALUES('zxNKAT')
INSERT INTO PINKY1 VALUES('zxNKAT')
INSERT INTO PINKY1 VALUES('VERESEAEz')

GO
CREATE TABLE PINKY2(VAL1 VARCHAR(100),VAL2 VARCHAR(100),VAL3 VARCHAR(100),VAL4 VARCHAR(100),VAL5 VARCHAR(100))
INSERT INTO PINKY2 VALUES('VE%','%RE%','%SE%','%AE%','%E_')
INSERT INTO PINKY2 VALUES('BE%','%RE%','%SE%','%AE%','%E_')
INSERT INTO PINKY2 VALUES('SE%','%RE%','%SE%','%AE%','%E_')
INSERT INTO PINKY2 VALUES('DE%','%RE%','%SE%','%AE%','%E_')

GO

SELECT * FROM PINKY1 INNER JOIN PINKY2 ON NOTES LIKE VAL1
WHERE NOTES LIKE VAL2 AND NOTES LIKE VAL3 AND NOTES LIKE VAL4 AND NOTES LIKE VAL5


Cheers,

Venkatesan Prabu .J

7.9.10

All about user creation in SQL Server

Creating a new user in SQL Server:


Goto SSMS -> New User. Provide your user name, in my case its sample_user

Choose the authentication and choose the default database.



Default database indicates the database to which the user is having the access. In the next page, you can specify the level of access to the user. The next drop down is Default language -> I have made it as default and it's English.

Arabic, Brazilian, British English, Bulgarian, Croatian, Czech, Danish are some of the languages listed.




In the next window, you can specify the role of the user and it's server role. I have informed that, this person is a sysadmin and public too.


Next option is "User Mapping", here all the database will be listed. You can specify the level of access to be provided to this user for each database.


I do not want to provide any other access to this user except "VenkatDB".
Next screen is securables, you will have list of objects like Server, Endpoints and Logins.
You can choose the object on which you want to provide or deny access.
For example, I have selected Server -> Select an option "Create any database" and -> Select deny option. Here, we have restricted the user to create any database. Still, he is a sysadmin but he can't create any database.
The final page is status. It will define the current state of the user.

Now, let's move to our actual topic.
How to prevent access to a database for a particular SQL Login user????
Consider am having a user who is having access to multiple databases? I want to restrict the user not to use "VenkatDB" - > A specific database.
Now, you need to first make the user as public.



Provide necessary access level in the database level. Make the user as public for that specific database. Now click "OK". Reopen the login page for that particular user. "VenkatDB" is disappeared.

Now, I am trying to access the objects in the database. Below is the message received.
" The server principal "venkat" is not able to access the database "VenkatDB" under the current security context. "
Cheers,
Venkatesan Prabu .J

Database size in Express editions

SQL Server 2005 Express editions - Database size is 4 GB
SQL Server 2008 Express editions - Database size is 4 GB
SQL Server 2008 R2 Express editions - Database size is 10 GB

Cheers,

Venkatesan Prabu .J

http://venkattechnicalblog.blogspot.com/

Check the Updates in our machine

This one is pretty interesting findings, I found the check box "Show Updates" in the Add or Remove Program.

On selecting the check box, you will see a fantastic difference in listing the installed softwares.
It's a tree nature display which will give the information like which one is the master one and what all the patches applied on it.


It's a fantastic feature and I found it today!!!!! Eurekhaaaaaaaaaaaaaaaa
Cheers,
Venkatesan Prabu .J

Select Statements to access stored procedures

Is it possible to use the select statement to access stored procedures?????

In one of the difference between functions and stored procedures is, we can use the "select"
statement in functions whereas we can't use the same in stored procedures.

Can we make this statement false????? Not completely but a little bit.

Before that, am trying to create a Linked server.

Goto SSMS -> Your DB Server -> ServerObjects -> Linked Server - > Create new Linked Server.


You will get a message box to type your Linked server. You need to provide the servername.

Specify whether it's SQL Server or not. If it's not SQL Server, provide necessary details to connect it.

The second window is authentication, you need to specify the credentials used to access the Linked Server.


The third window specifies the options to be provided for the Linked server. If everything is good. Click "Ok" button.

Now, your Linked Server is created.

Now, you can see your catalogs listed under the Linked Server.

Now, am trying to access the Linked Server's table,
SELECT * FROM LinkedServer.VENKATDB.dbo.VENKAT_TABLE
Awesome,

Am able to see my data.


Goto your Linked Server query window and create a procedure (use the below code)

DROP TABLE VENKAT_TABLE_LINKED
CREATE TABLE VENKAT_TABLE_LINKED (ID INT)
INSERT INTO VENKAT_TABLE_LINKED VALUES (1)
INSERT INTO VENKAT_TABLE_LINKED VALUES (2)
INSERT INTO VENKAT_TABLE_LINKED VALUES (3)
INSERT INTO VENKAT_TABLE_LINKED VALUES (4)
GO

DROP PROCEDURE VENKAT_PROCEDURE
GO
CREATE PROCEDURE VENKAT_PROCEDURE
AS
BEGIN
SELECT * FROM VENKAT_TABLE_LINKED
END
GO
EXEC VENKAT_PROCEDURE
GO

Now, your procedure is created in the Linked server and am trying to access that procedure from the actual server using select statement. Le's see how to do it.

This can be achieved using OpenQuery statement.

SELECT * FROM OPENQUERY ([LinkedServerName],'MASTER.DBO.VENKAT_PROCEDURE')

So, the statement is wrong :-)
The actual statement is, "Stored procedures can't use Select statement in it's own server"
Hope, you all agree with my statement.
Cheers,
Venkatesan Prabu .J

6.9.10

Linked servers in SQL Server

Linked Server -

It's quite a different area, which I would like to concentrate more. What's this???? linked server......

Accessing the resource in the other server can be achieved using Linked server. Considering am having a server named "ServerA" and I would like to grab some data from the remote server named "ServerB". In that case, we need to create a linked server. In our scenario, the linked server is "ServerB".

Let's see, How to link it? How to access the data?

Goto SSMS -> Your DB Server -> ServerObjects -> Linked Server - > Create new Linked Server.

You will get a message box to type your Linked server. You need to provide the servername.

Specify whether it's SQL Server or not. If it's not SQL Server, provide necessary details to connect it.

The second window is authentication, you need to specify the credentials used to access the Linked Server.



The third window specifies the options to be provided for the Linked server. If everything is good. Click "Ok" button.


Now, your Linked Server is created.


Now, you can see your catalogs listed under the Linked Server.




Now, am trying to access the Linked Server's table,
SELECT * FROM LinkedServer.VENKATDB.dbo.VENKAT_TABLE

Awesome,
Am able to see my data.


Cheers,
Venkatesan Prabu .J

My T-SQL Gallery @code.msdn.microsoft


Created my own T-SQL Gallery in Microsoft site. Do visit the same and share your feedback,

http://code.msdn.microsoft.com/VenkatSQLSample/Thread/List.aspx

Thanks and Regards,
Venkatesan Prabu .J

SQL Server Interview questions - Part 1

What is the significance of NULL value and why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.

What is SQL whats its uses and its component ?
The Structured Query Language (SQL) is foundation for all relational database systems. Most of the large-scale databases use the SQL to define all user and administrator interactions. It enable us to retrieve the data from based on our exact requirement. We will be given a flexibility to store the data in our own format.


The DML component of SQL comprises four basic statements:
* SELECT to get rows from tables
* UPDATE to update the rows of tables
* DELETE to remove rows from tables
* INSERT to add new rows to tables


What is DTS in SQL Server ?
Data Transformation Services is used to transfer the data from one source to our required destination. Considering am having some data in sql server and I need to transfer the data to Excel destination. Its highly possible with dialogue based tool called Data Transformation services. More customization can be achieved using SSIS. A specialized tool used to do such migration works.


What is the difference between SQL and Pl/Sql ?

Straight forward. SQL is a single statement to finish up our work.Considering, I need some data from a particular table. “Select * from table” will fetch the necessary information. Where as I need to do some row by row processing. In that case, we need to go for Procedural Logic / SQL.

What is the significance of NULL value and why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.

Difference between primary key and Unique key?
Both constraints will share a common property called uniqueness. The data in the column should be unique. The basic difference is,
· Primary key won’t allow null value. Whereas, unique key will accept null value but only one null value.
· On creating primary key, it will automatically format the data inturn creates clustered index on the table. Whereas, this characteristics is not associated with unique key.
· Only one primary key can be created for the table. Any number of Unique key can be created for the table.

Select Statement in SQL Server

Select Statement in SQL Server

String Functions in sql server

String Functions in sql server
Substring/Len/replace/Ltrim/Rtrim

SQL Server Interview Question - Part 2

What is normalization?

Normalization is the basic concept used in designing a database. Its nothing but, an advise given to the database to have minimal repetition of data, highly structured, highly secured, easy to retrieve. In high level definition, the Process of organizing data into tables is referred to as normalization.


What is a stored procedure:
Stored procedures are precompiled T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements. As, its precompiled statement, execution of Stored procedure is compatatively high when compared to an ordinary T-SQL statement.


What is the difference between UNION ALL Statement and UNION ?
The main difference between UNION ALL statement and UNION is UNION All statement is much faster than UNION,the reason behind this is that because UNION ALL statement does not look for duplicate rows, but on the other hand UNION statement does look for duplicate rows, whether or not they exist.

Example for Stored Procedure?
They are three kinds of stored procedures,1.System stored procedure – Start with sp_2. User defined stored procedure – SP created by the user.3. Extended stored procedure – SP used to invoke a process in the external systems.Example for system stored proceduresp_helpdb - Database and its propertiessp_who2 – Gives details about the current user connected to your system. sp_renamedb – Enable you to rename your database


What is a trigger?

Triggers are precompiled statements similar to Stored Procedure. It will automatically invoke for a particular operation. Triggers are basically used to implement business rules.


What is a view?
If we have several tables in a db and we want to view only specific columns from specific tables we can go for views. It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. Views also reduce the effort that is required for writing queries to access specific columns every time.


What is an Index?
When queries are run against a db, an index on that db basically helps in the way the data is sorted to process the query for faster and data retrievals are much faster when we have an index.


What are the types of indexes available with SQL Server?

There are basically two types of indexes that we use with the SQL ServerClustered -

1. It will format the entire table, inturn physically sort the table.

2. Only one clustered index can be created for a table.

3. Data will be located in the leaf level.

4. By default, primary key will create clustered index on the table.

Non-Clustered Index

1. It wont touch the structure of the table.

2. It forms an index table as reference to the exact data.

3. A reference to the data will be located in the leaf level.

4. For a table, we can create 249 non clustered index.

Happy Learning!!!
Regards,
Venkatesan Prabu .J

SQL Interview question

Extent Vs Page?

Pages are low level unit to store the exact data in sql server. Basically, the data will be stored in the mdf, ldf, ndf files. Inturn, pages are logical units available in sql server.The size of the page is 8KB.

Eight consecutive pages will form an extent 8 * 8KB = 64KB.

Thus I/O level operation will be happening at pages level.The pages will hold a template information at the start of each page (header of the page).

They are,

1. page number,

2. page type,

3. the amount of free space on the page,

4. the allocation unit ID of the object that owns the page.

Extents will be classifed into two types,

1. Uniform extents

2. Mixed extents

Uniform Extents:It occupied or used by a single object. Inturn, a single object will hold the entire 8 pages.Mixed

Extents:Mulitple objects will use the same extent. SQL Server will allow a max of eight objects to use a shared extent.

Property of SQL Server :Initally if an object is created, sql server will allocate the object to the mixed extent and once if the size reaches 8 pages and more... immediately, a new uniform extent will be provided for that particular object.

Herecomes, our fragmentation and reindexing concepts.

Best Joke - Enjoy it

Best Joke - Enjoy it