Archive

Posts Tagged ‘#SQL Server’

How to Implement One-to-One Relationship in SQL Server

Today, we’re going to discuss how to implement One-to-One relationship between two tables in SQL Server. So, what does it mean? That’s pretty simple. We can simply go to Database Diagram option and drag Primary Key from master table and drop that on Foreign Key on child table…and that’s it. What’s the big deal???

Yes. It will definitely implement Foreign Key constraint but the cardinality will be One-to-Many by default. Here we get the problem. I wish to implement One-to-One cardinality rather One-to-Many. I tried a lot with available options but in vain. The SQL Server doesn’t provide any option where you can simply go and change the cardinality between tables.

Let’s discuss how to achieve this in SQL Server.

I’ve got two tables, named 1.) Customer, and 2.) CustomerContact as you can see in below image.

 

Relationship Read more…

SQL Server 2008 R2 Programming Training at Volvo, Bengaluru, Oct 9 – Oct 17, 2013

100_0405

Finished with SQL Server 2008 R2 Programming training at Volvo, Bangalore…Sharing knowledge is always fun…

.NET Training at AQInsights, Bangalore, Jul 02 – Jul 29, 2013

.NET and SQL Server training at AQInsights, Bangalore…

WP_20130704_001

SQL Server Training at Mindtree, Bangalore, Jun 28 – July 01, 2013

WP_20130701_003

SQL Server training at Mindtree, Bangalore. Short but nice training…

MS Business Intelligence Training at HP, Bangalore, Bagmane Tech Park, Jan 7th – Jan 11th, 2013

Enjoyed a lot at MSBI training…Nice participants…

100_0345

 

 

Download SQL Server 2012 Service Pack 1 (SP1)

The Microsoft has released the first service pack (SP1) for the SQL Server 2012 today. Here goes the link to download SQL Server 2012 SP1

http://www.microsoft.com/en-us/download/details.aspx?id=35575

Though, we have got 8 files with this release, we would require following files in order to run the service pack 1:

  • For 64-bit SQL Server, download file: SQLServer2012SP1-KB2674319-x64-ENU.exe
  • For 32-bit SQL Server, download file: SQLServer2012SP1-KB2674319-x86-ENU.exe

Other .exe files in this release is used for special purposes.

Difference Between RAISERROR and THROW in SQL Server

As we all know that both the RAISERROR and THROW statements are used to raise an error in T-SQL block. However, the quesion arises is if both do the same job, why do we have the two different statements?

So, let us take a look at the difference between the two statements.

RAISERROR Statement THROW Statement
Ancient statement supported by the SQL Server. New statement introduced in the SQL Server 2012.
Little complex statement, offers more features. Very simple statement, offers limited features.
Message string offers printf style formatting. Message string does not offer printf style foramtting.
Can generate user-defined i.e. msg_id > 50000 as well as system-defined i.e. msg_id < 50000 errors. Can only generate user-define i.e. msg_id > 50000 errors.
If Message ID is used, it must be defined in sys.messages catalog view. If Message Number is used, it may not be defined in sys.messages catalog view.
Different severity level can be defined with this statement. It does not allow to set different severity level. It always has severity level 16.
It does not require preceding statement to end with semicolon (;) statement terminator. It requires preceding statement to end with semicolon (;) statement terminator.

Hope it helps us out to understand difference between these two statements.