What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 29172 |  Welcome, Guest!   Register  Login
 Home > Blogs > SQL Server > Unique Identifier in SQL Server ...
Jvprabhusanthi

Unique Identifier in SQL Server

 Blog author: Jvprabhusanthi | Posted on: 5/3/2012 | Category: SQL Server Blogs | Views: 608 | Status: [Member] | Points: 75 | Alert Moderator   


While working with Filestream datatype, I've addressed an issue with Unique Identifier column. Thought of sharing this with you all.

       File stream is a new datatype introduced in SQL Server 2008 to leverage the functionality of storing  the data into the database.

       Below is the syntax to create a table in the database,
 
CREATE TABLE [dbo].[DOC_details2](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [F_Data] [varbinary](max) FILESTREAM  NOT NULL,
    [F_Name] [nvarchar](1000) NULL,
    [F_Date] [datetime] NULL,
    [RowGuid] [uniqueidentifier] ROWGUIDCOL  NOT NULL
)

        While creating the filestream storage table, we need to specify one column as uniqueidentifier and it's a mandatory functionality.

         My question now is, How can we insert the data in a unique identifier column?

Solution 1:   We need to use newid() in SQL Server to generate the GUID

ALTER TABLE [dbo].[DOC_details2] ADD  CONSTRAINT [DF_DOC_details2_RowGuid]  DEFAULT (newid()) FOR [RowGuid]
GO 


Solution 2: From C#, we can make it out the method System.Guid.NewGuid.

Cheers,
Venkatesan Prabu .J 
Head, KaaShiv InfoTech.
http://www.kaashivinfotech.com/



Cheers,
Venkatesan Prabu .J
Head, KaaShiv InfoTech
http://kaashivinfotech.com/Ebooks.aspx
Found interesting? Add this to:


Experience:9 year(s)
Home page:http://www.dotnetfunda.com
Member since:Tuesday, May 01, 2012
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 5:09:58 PM