Pages

Thursday, April 9, 2009

60 seconds with Abhishek Kant


60 seconds with Abhishek Kant
MVPs are champions of community.

VJ caught up with Abhishek Kant, India MVP Lead, to get his view on the Microsoft Most Valuable Professional Program(MVP).

VJ: Please tell us about yourself.
Abhishek:
I work with the Microsoft Technical communities in India to support and encourage them. I am employed by Microsoft and designated as Community Program Manager. I have been a techie part of my life after being trained as a banker in management school.
I blog about technology at: http://www.abhishekkant.net/
I am a gadget freak, enjoy programming in my spare time and love playing on my XBOX360 (gamertag: chints).

VJ: Please tell us about MVP Program and Its importance.
Abhishek:
Microsoft community in India has a large presence in form of user groups, forums and blogs. MVP Award recognizes the top community contributors for Microsoft technologies. MVP is a globally recognized award and one that Steve Ballmer, CEO himself keeps a close contact with. MVPs are conscience of Microsoft and provide valuable neutral feedback on all our products. Their feedback (bugs and feature suggestions) is highly regarded by the development teams.
MVPs are champions of community and Microsoft relies on them to guide us in determining what community needs from us. To know about the great work Indian MVPs have been doing, visit:http://blogs.technet.com/southasiamvp

VJ: Please tell us about how to become an MVP.
Abhishek: You can’t take a certification to be an MVP! You have to earn it by working hard in the community and getting recognized as a leader there. The only way one can take the leadership position in the community is by being the most prolific contributor in the community.
You can self nominate yourself for the MVP award by visiting: www.microsoft.com/india/mvp
Make no mistake it is very difficult to become an MVP. We have only 125 MVPs in India and over 4000 world over.

VJ: Please tell us about benefits of becoming an MVP
Abhishek:
MVPs enjoy recognition, technical and relationship benefits from Microsoft. Some important benefits are:
The most important benefit to the MVPs is access to all existing and upcoming (betas/ alphas) Microsoft products for free. Microsoft facilitates interactions between product teams and MVPs where they can participate in determining the future of the products.
Access to the wide network of MVPs worldwide provide for excellent networking and learning opportunities that is rare to find in professional world.

VJ: Please tell us about your MVP Summit experience
Abhishek:
MVP Summit is a very different experience from regular conferences. Presence of MVPs from over 35 countries under one roof provides valuable learning and networking moments. Personal interactions with Microsoft product teams and candid exchange of ideas are unique features of MVP Summit that make it very valuable. The high point of every MVP Summit is the Steve Ballmer keynote. He is the best speaker I know of in the world.

VJ: Any message to the Technologists
Abhishek:
Learning from books is something that we all learnt growing up. What I wish I knew in college was that a person learns more from participating in the community. Community challenges you with real world problems and encourages you to think of real world solutions. I wish I had participated in technical forums early on so that my knowledge would have grown exponentially.
If there is one thing that I would urge all technologists, whatever stage of career you are in at, to do is to start participating in community of interest to you. If you are a Microsoft technologist you definitely want to check out Microsoft Forums.
Communities are where you find the best and brightest of people engaged in world over. An interesting by product of community participation is the global recognition you would gain for yourself.

Monday, April 6, 2009

Difference between Primary and Unique Key Constraint

Do you know what is the difference between Primary Key and Unique Key Constraint?

If YES then You can display your name on my Blog.

Hurry-up post your reply by adding your comments on or before 08-APR-2009 (Last Day)

If you need any reference or help on this please check out my March and April Articles in Archive Section.

NOTE: Please do not copy the content from any other site.

I have got over 20 responses in my mail-box due to issues in posting the answers in the comment section and out of that selected "Aashish" as the winner of contest.

According to Aashish the Differences are:
1.Primary Key by definition cannot be null, where as unique key can accept null values but if the unique key is defined on a column which is not null , then this unique key can also be used as an alternate primary key functionality to identify unique rows in a table.
2.By definition you can have only one primary key defined on a table where as you can have multiple unique keys defined on a table
3.Also by default Primary key is created as clustured index and unique key is created as non clustered index.

This is the perfect answer to this question.

Unique Constraint in SQL Server

In this post I would like to summarize the different articles on Unique Constraint in SQL Server.
Constraints are one of the key factors in designing a table. When you are opening a bank account, bank says that you can not have more than one account in the same branch or location. This is a business rule and this can be implemented using Unique Constraints.

Unique Constraints can be defined at the Column level or Table Level.

Below are the list of articles related to Unique Constraints:
.. Unique Constraints Introduction and Defining at the Table Level
.. Defining Unique Constraints at the Column Level or on Single Column
.. How to find Unique Constraints definition and how to drop them

Unique Constraint in SQL Server -- Part 3

In this article I would like to show you on how to find the Unique constraints defined on a table.



In my previous articles I explained about Unique Constraint creation at the Table Level and also at the Column Level.


How to query Unique Key Constraints Definition?

The below script will give you Constraint definition along with the constraint name.


SELECT TC.TABLE_NAME,CC.CONSTRAINT_NAME,CC.COLUMN_NAME
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CC,
INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
WHERE TC.CONSTRAINT_TYPE = 'UNIQUE'
AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME
AND TC.TABLE_NAME = CC.TABLE_NAME




How to Drop Unique Constraints?

As always, to drop any object you need to find out the object name.

In this case ,I want to drop UC_ACCOUNT01 constraint defined on a ACCOUNT table.

ALTER TABLE ACCOUNT DROP CONSTRAINT UC_ACCOUNT01;

That’s it. It’s very simple.

Saturday, April 4, 2009

Unique Constraint in SQL Server -- Part 2

In this article I will talk about Column Level unqiue Constraints in SQL Server. These are very useful if you want to have rules based on one single column within a table.

Please check my article on Creating Unique constraint at the table Level.


This can be created in two different ways i.e. CREATE TABLE/ALTER TABLE

Let’s go with an example.

Business rule which I want to set is Customer SSN should be unqiue.

Lets create CUSTOMER table and insert few records.

CREATE TABLE CUSTOMER
(CUSTOMER_ID INT, CUSTOMER_NAME VARCHAR(50),
CUSTOMER_LOCATION VARCHAR(10),SSN VARCHAR(12))

INSERT INTO CUSTOMER VALUES(1,'SAMY','NY','111-11-1111');
INSERT INTO CUSTOMER VALUES(2,'BECK','NJ','222-22-2222');
INSERT INTO CUSTOMER VALUES(3,'STAN','TX','333-33-3333');
INSERT INTO CUSTOMER VALUES(4,'NICK','FL','444-44-4444');


ALTER TABLE:

alter table CUSTOMER
add constraint UC_Customer01 unique(SSN);


CREATE TABLE:

CREATE TABLE CUSTOMER
(CUSTOMER_ID INT, CUSTOMER_NAME VARCHAR(50),
CUSTOMER_LOCATION VARCHAR(10),SSN VARCHAR(12),CONSTRAINT UC_Customer01 unique(SSN))

Now lets try to insert one record with a new customer and existing SSN.

INSERT INTO CUSTOMER VALUES(5,'VINCE','FL','444-44-4444');

Msg 2627, Level 14, State 1, Line 1
Violation of UNIQUE KEY constraint 'UC_Customer01'. Cannot insert duplicate key in object 'dbo.CUSTOMER'.
The statement has been terminated.

It’s very simple isn’t it?How do you find list of Unique constraints in a database defined on a table? Is there any way I can drop these constraints?? To find the answers to these questions you need to check my next article.

Unique Constraint in SQL Server -- Part 1

In this article I would like to explain about “Unique Constraints”. Constraints are one of the key factors in designing a table. Before I explain what is the use of constraints lets take one real world example. When you are opening a bank account, there is a bank rule that says, you can not have more than one account with in same branch or location. This is a business rule.

To implement this kind of rule either we can use UNIQUE Constraint or Primary Key Constraint. This article will implement this business rule using UNIQUE KEY constraint.

The way I see is, implementing this in Back-end gives more flexibility. For now I will explain about how to implement this business rule in back-end.

There are total six types of constraints in SQL Server to implement different types of business rules and they are:

1) Check Constraints.
2) Rules
3) Default Constraints
4) Unique Constraints
5) Primary Key Constraints.
6) Foreign Key Constraints.

Other Relevant articles related to Constraints:
.. List all the Primary Keys in SQL Server Database
.. List all the Foreign Keys in a SQL Server
.. Foreign Key and Primary Key in SQL Server


Unqiue Constraint can be created in two different ways i.e. CREATE TABLE/ALTER TABLE and also at the two levels i.e. Table Level or Column Level. When the constraint is defined at the table level or on multiple columns it is also called as Composite constraint.

In my previous articles we did talk about Default,Check, Primary and Foreign Key Constraints. In this article we will talk about Unique Constraint.

Lets create ACCOUNT table and insert few records.

CREATE TABLE ACCOUNT(ACCOUNT_ID INT,ACCOUNT_LOCATION VARCHAR(10),
CUSTOMER_ID INT,CHECK_IN_AMT INT,SAVINGS_AMT INT);

INSERT INTO ACCOUNT VALUES (10001,'NY',100010,1000,0);
INSERT INTO ACCOUNT VALUES (10002,'NJ',100020,800,0);
INSERT INTO ACCOUNT VALUES (10003,'LA',100030,0,800);

Table Level:

Business rule says “you can not have more than one account with in same branch or location”. This can be implemented by placing unique constraint on ACCOUNT_LOCATION and CUSTOMER_ID.

ALTER TABLE:

alter table ACCOUNT
add constraint UC_account01 unique(CUSTOMER_ID,ACCOUNT_LOCATION)

Let's try to insert below record.

INSERT INTO ACCOUNT VALUES(10004,'NJ',100020,1000,100);

SQL Server will throw below error
Msg 2627, Level 14, State 1, Line 1
Violation of UNIQUE KEY constraint 'UC_ACCOUNT01'. Cannot insert duplicate key in object 'dbo.ACCOUNT'.
The statement has been terminated.


CREATE TABLE:

CREATE TABLE ACCOUNT(ACCOUNT_ID INT,ACCOUNT_LOCATION VARCHAR(10),
CUSTOMER_ID INT,CHECK_IN_AMT INT,SAVINGS_AMT INT, CONSTRAINT UC_ACCOUNT01 UNIQUE(CUSTOMER_ID,ACCOUNT_LOCATION));

Couple of points on Unique Constraints:

1) UNIQUE constraints are to make sure that no duplicate values are entered in specific columns that do not participate in a primary key.
2) When you are placing an unique constraint it will automatically create Unique Index to maintain the integrity.
3) Unique Allows one Null value per column where as Primary key doesn’t allow null values.
4) There is no limit on having number of unqiue constraints on a table.
5) Unique Key constraint can be referenced in Foreign Key Column.