Is symmetric key used for security purpose? If I just want a unique identifier for a table, what are the possible options and their pros and cons? The table will be accessed thru dataset created in Visual Basic 2005.
Yes, symmetric key is used for security purpose, refer BOL for more and http://www.sqlservercentral.com/columnists/mcoles/sql2005symmetricencryption.asp If you want to have unique identifier for a table their could be more then one way to achieve this based on the design/requirement, you may create identity column or you may have unique constraint or guid column.
Symmetric keys are recommended for data encryption by Books Online as they provide better performance when encrypting and/or decrypting data in SQL Server 2005 compared to asymmetric keys and certificates (at least according to Microsoft). As explained Symmetric key is used for data encryption: http://www.sql-server-performance.com/articles/dev/encryption_2005_2_p1.aspx and I'm not clear about whether you want to create this uniqueidentier in such data encryption.
Hi Satya, I just simply want a unique column and its value is generated automatically by SQL Server. It seems that Identity column is the one that I should use. I have also read about uniqueidentifier and I think it does not mean that it is unique within the column unless it has unique constraint or primary key constraint. I'm little bit confused when one should use uniqueidentifier. Also, when a uniqueidentifier column has the unique constraint, how does sql server generate the value and whether it will have performance issue?
Uniqueidentifier is a GUID (Globally Unique IDentifier) which consumes more space than typical identity column (an example of a formatted GUID:B85E62C3-DC56-40C0-852A-49F759AC68FB). Generally, you need to try avoiding this key as your primary key on the table. I am already having hardtime spelling this word. [] Unlike an Identity column, a uniqueidentifier column doesn't automatically get an assigned value when a row is inserted into a table. You either need to place a default on the uniqueidentifier column (DEFAULT NEWID()) or place some logic in your insert stored procedure. You can find many advantages and disadvantages of UniqueIdentifier in BOL or online.
Hi DilliGrg, If I understand correctly, uniquenidentifier does not mean that it is unique within the column unless it has unique constraint or primary key constraint. If this is true, can I say that its uniqueness only applies among machines but not within same machine?
Hi Hemantgiri and Dilli, I have also read that section of BOL. The following part is the one I don't quite understand: uniqueidentifier columns may contain multiple occurrences of an individual uniqueidentifier value, unless the UNIQUE or PRIMARY KEY constraints are also specified for the column. A foreign key column that references a uniqueidentifier primary key in another table will have multiple occurrences of individual uniqueidentifier values when multiple rows reference the same primary key in the source table. It sounds like the uniqueidentifier won't be unique "WITHIN" a column unless UNIQUE or PRIMARY KEY constraint is also specified for the column. Is my interpretation correct? Peter
http://www.sql-server-performance.com/faq/unique_identifier_column_p1.aspx FAQ fyi. Unless you need a globally unique identifier, you're probably better off sticking with an IDENTITY. Now, unlike an IDENTITY column, a uniqueidentifier column doesn't automagically get an assigned value when a row is inserted into a table. You either need to place a default on the uniqueidentifier column (DEFAULT NEWID()). The major advantage of using GUIDs is that they are unique across all space and time.
Hi Satya, Thanks for the link. For my current issue, using IDENTITY column seems to be the better choice. However, I will still like to get a better understanding of uniqueidentifier since I'm sure that I also need to deal with transferring rows from one table of a database to a corresponding table of another database. I hope you can explain the following paragraph: uniqueidentifier columns may contain multiple occurrences of an individual uniqueidentifier value, unless the UNIQUE or PRIMARY KEY constraints are also specified for the column. A foreign key column that references a uniqueidentifier primary key in another table will have multiple occurrences of individual uniqueidentifier values when multiple rows reference the same primary key in the source table.
[quote user="pcsql"] uniqueidentifier columns may contain multiple occurrences of an individual uniqueidentifier value, unless the UNIQUE or PRIMARY KEY constraints are also specified for the column. A foreign key column that references a uniqueidentifier primary key in another table will have multiple occurrences of individual uniqueidentifier values when multiple rows reference the same primary key in the source table. [/quote] I am assuming that you know what is One-to-Many relationship means. Of course, you have to define this column as PK which itself is unique if you want to refer to other column as FK. In this case, you will have One source table PK value and multiple references to this value from other tables. I think it's better to read more on BOL or google it if you need more info.