Using Guids Instead Of Identities

Sep 21, 2005

I'm really sorry if this is too OT but it is related to replication...

View 1 Replies


ADVERTISEMENT

SQL Relationships And Identities

Dec 7, 2005

Can anyone tell me what is best practices to define relationships betweentables and to define their primary key?For example...One table is Orders and other is OrderDetails.For ease of accessing datas from table OrderDetails I have fields copiedfrom Orders like year_of_order, order_number, client_id.Now, is it better to link those tables on this three fields, because theyare already there or define new field in OrderDetails with name OrderID andlink it on ID field from table Orders?In this case I will always access table Orders to check year of order,order number or client id for records in OrderDetails.Which one of these examples have better performace on server?I'm also doubting is it good to define field Id in each table and use itfor relationships to other tables or link tables on fields likeNumber_of_order.Is it enough to define field "Id" set it as PK and Identity Seed 1 forunique mark of record and preserving consistency of data.Is it good practice to link tables on primary key from one table to othercolumn in other table?Thnks.

View 7 Replies View Related

Using Identities And Returning Their Values

Aug 31, 2000

I have a table that contains an identity column. This column is updated in a stored procedure that has a linked trigger that updates another 'backup' table. How can I ensure that the value of the new row added in the table with the identity is passed back to calling client. ?

The value of @@identity is incorrect as it reflects the value in the 'backup table' not the original table. and use select max() on the original table within the stored procedure could be violated by other users attempting the same operation

View 2 Replies View Related

Table Variables And Identities

Feb 16, 2006

Can an identity be created in a table variable?

Can joins be performed between table variables to be inserted into another table variable?

Am I better of using a temporary table?

(I'm working in a stored procedure here)

Thanks in advance

View 10 Replies View Related

Ug! Replicated Tables Missing Default Values And Identities.

Feb 8, 2007

Ok, so I must have screwed something up.

I have several databases set up for transactional replication to another instance of SQL Server 2005 for fail over purposes. Today, I restored one of those replicated databases to my development machine and discovered two surprising problems:

1) The Default Values settings in the replicated tables are missing. They are there in the publishing tables, just as they were before I set up replication. However, they are not in the subscribing tables. Now, this is not such a big issue, since I tend to send all default values in insert queries as necessary.

2) The second problem is a more of an issue, since I use auto-numbered Identity columns in my tables (yes, I know that's just plain lazy...). Anyway, in the replicated tables, €œIs Identity€? is indeed set to yes, but despite that fact that there are thousands of records with incrementally unique IDs, SQL server is trying to insert a record starting with 1. This, of course, throws a PK constraint error.

Obviously, if I am use them for failover purposes, these replicated databases need to be identical in every way.

So, what did I do to cause this situation, and how to I fix it?

Thanks a bunch!

md

View 9 Replies View Related

Sequential Guids

Oct 31, 2007

 Hello,I am creating a new database and I was advised to use Sequential Guids.I was reading some information and, as far as I understood, I can use NEWSEQUENTIALID. This can be used when I have a uniqueidentifier column as the key of a clustered index to avoid fragmentation during insert. Ok, so I use NEWSEQUENTIALID instead of NEWID.But I will use LINQ most of the time instead of Stored Procedures.So can I specify in my tables scripts to use Sequential Guids when, for example, a record is created? And am I right when using Sequential Guids?Here is a part of my code:-- Blogs ...
create table dbo.Blogs
(
BlogID uniqueidentifier not null
constraint PK_Blog primary key clustered,
Title nvarchar(400) null,
Description nvarchar(2000) null,
CreatedDate datetime null
)

-- Posts ...
create table dbo.Posts
(
PostID uniqueidentifier not null
constraint PK_Post primary key clustered,
BlogID uniqueidentifier not null,
AuthorID uniqueidentifier not null,
Title nchar(1000) null,
Body nvarchar(max) null,
UpdatedDate datetime not null,
IsPublished bit not null,
constraint FK_Posts_Blogs
foreign key(BlogID)
references dbo.Blogs(BlogID)
on delete cascade,
constraint FK_Posts_Users
foreign key(AuthorID)
references dbo.Users(UserID)
on delete cascade Thanks,Miguel

View 2 Replies View Related

Frustration With UniqueIdentifiers (GUIDs)

Feb 26, 2004

We're trying to set a new standard at my office, of using GUIDs as database ID fields - all new tables in all databases will have a GUID as the ID field, using the UniqueIdentifier data type.

The problem that we are running into, is that different applications interpret the UniqueIdentifier data type differently - ADO 2.x interprets it with the opening and closing { } braces. ADO.NET does not include the { and } in the GUID structure, SQL Server Query Analyzer does not include the { } braces, and SQL Server Enterprise Manage does include the { }

so we end up with results like this:

ADO 2.x: {012345678-abcd-ef01-2345-6789abcd}
ADO.NET: 012345678-abcd-ef01-2345-6789abcd
Query Analyzer: 012345678-abcd-ef01-2345-6789abcd
Enterprise Manager: {012345678-abcd-ef01-2345-6789abcd}

The problem with this is in two parts:
1) VB6 does not have a GUID structure or data type, so we are treating GUIDs as strings... but VB6 doesn't recognize "{012345678-abcd-ef01-2345-6789abcd}" and "012345678-abcd-ef01-2345-6789abcd" as the same string
2) when sending a URL link through an email, the { } braces break the link - in all email applications that we have tested. This include Groupwise 6, Groupwise 6.5, IPSwitch Web IMail, Outlook 2000, and Outlook Express (IE 6).

We're becoming very frustrated with the problems at hand, and need to know how others have worked around these problems. Please respond with any kind of advice or any real life situations where you have encountered this and found a solution, etc.

Thanks.

View 3 Replies View Related

SqlServer 2005: Importing Data: Idenitity Fields Getting Made Into Non-identities

May 16, 2007

Hi;We just migrated to SqlServer 2005. When I import tables from fromSqlServer database into another the identity fields get switched offfrom being identities.How can I prevent that from happening?Thanks in advance for any informationSteve-------------------------------------------------------------------Microsoft SQL Server Management Studio9.00.1399.00Microsoft Analysis Services Client Tools2005.090.1399.00Microsoft Data Access Components (MDAC)2000.085.1117.00(xpsp_sp2_rtm.040803-2158)Microsoft MSXML2.6 3.0 4.0 6.0Microsoft Internet Explorer7.0.5730.11Microsoft .NET Framework2.0.50727.42Operating System5.1.2600

View 3 Replies View Related

GUIDs Using NEWSEQUENTIALID() On SQL Server Mobile

Feb 28, 2006

Hello,

I've been thinking about using GUIDs as primary keys within my application. One problem I have with this approach is that GUIDs generated with NEWID() are not sequential, and this can have a huge impact on insertion performance due to fragmented indexes. It would seem that NEWSEQUENTIALID() solves this issue, however it doesn't seem very practical to use this on SQL Server Mobile. With SQL Server, you can specify an OUTPUT clause for an INSERT statement, and using this, determine what the last inserted GUID was. There doesn't seem to be such an option in SQL Server Mobile, so how can I get the last generated GUID so that I can attach children records to my parent record? It's been suggested that you could use the MAX() function to get the latest GUID, but there is a problem with this approach - NEWSEQUENTIALID() guarantees that the GUIDs generated will be sequential for the machine generating them, but makes no guarantees about how this will fit in with GUIDs generated by other machines. It is entirely possible that GUIDs generated by a different machine will be larger than the latest one generated on the current machine, so using MAX() to determine the latest value doesn't seem like a valid option to me.

Does anybody have any ideas on tackling this problem? Any thoughts on the suitability of using GUIDs as the primary key for SQL Server Mobile devices in general?

Thanks,
Adrien.

View 1 Replies View Related

PackageID And GUIDs In ExecuteSQL Task

Jan 18, 2006

Am I looking at a potential bug here or do I not understand the feature properly? I have an ExecuteSQL task that inserts into a table for logging and includes the System::PackageID as one of the values. It's stored in my table as a uniqueidentifier. When I set the output variable in Parameter Mappings tab of the Execute SQL task to VarChar, all works great. WHen I set it to GUID as the data type in that tab, it outputs a different GUID than the actual System::PackageID variable.

-- Brian

View 1 Replies View Related

Use Of Guids As Unique Identifiers - Good Or Bad?

Jan 30, 2008

Are Guids good or bad? I've spoken to people who hate them in databases, but the db's I'm using right now all use them, so there must be *some* people out there who like them. I'm interested to know what other people think.

thanks!

View 6 Replies View Related

Seeded(int) Identity Columns Vs. UniqueIdentifiers(GUIDs)

Jul 1, 2003

I need gurus input on the pros and cons of Seeded(int) Identity colums vs. UniqueIdentifier(GUIDs) columns for my db design.

As I understand it, merging the data of 2 independent db's both using IDENTITY columns would be very hairy because of the possibility of overlap. GUIDs are much more likely to be unique across different servers.

What I'd like to hear from others are the other pros and cons of the situation. I of course understand the performance hit suffered at the hands of the GUID.

Thanks for your help!

View 29 Replies View Related

SSIS 2000 To 2005 Database Transfer Lost All Primary Keys, Identities And Indexes

Mar 25, 2008

Hi everyone, I am trying to upgrade a 2000 DB to 2005 with SSIS Database Transfer.

I finally got it to work with an online transfer but the destination database has no primary keys, indexes or identity columns from the source DB.

What am I missing?

What other ways are there to upgrade a SS2000 DB to 2005?

Thank you.

View 4 Replies View Related

Can I Update GUIDS In Sysmergepubliction And SysmergeAricles In Sqlserver 2005 ?

Dec 14, 2006

Hi fellows ,

there is a senerio where i want to  update GUIDS in columns "pubid" and "artid" generate in sysmergepubliction and sysmergeAricles respectivly  in sqlserver 2005 ?

2nd is there any easy way to generate scripts of  triggers of all replicated tables in subscriber at one .

View 1 Replies View Related

Complex Copy Routine, Mulitple Tables And Changing GUIDs

Dec 11, 2007

hello,
I have several tables that have guids as their primary keys and the tables are related as follows:
Table1 - primary key = ServiceNo (Guid), Filter Key = CampaignNo
Table2 - primary key = CostBasisNo (Guid), Foreign Key = ServiceNo (from Table1)
Table3 - primary key = UserId, Foreign Key = ServiceNo (from table1)
Table4 - primary key = SourceServiceNo (Foreign Key from Table1), MemberServiceNo(Foreign Key from Table1)
what I need to do is copy all records from Table1 where CampaignNo = @CampaignNo and insert them into table1, this I can do easily but I will generate a new ServiceNo for each one and associated a new CampaigNo which is fine.
The problem comes in that I need to also copy the contents of Table2 = Table3 for all ServiceNos that have been copied from Table1 but insert the new Guid that will have been created when copying the rows in Table1
This is further compounded when I need to do the same to Table4 but this time I need to insert the newid's for SourceServiceNo and the related MemberServiceNo which all would have changed.
I haven't the first clue where to start with this task, do I need to use temporary tables, cursors? any help gratefully received, even if it's a pointer to the most efficient approach.
 regards
 
 
 

View 4 Replies View Related

Guids Are Not Very Guid! Updating In DetailsView,FormView (Object Must Implement IConvertible)

Dec 1, 2005

I've been playing around with the new data controls (DetailsView,FormView) and have been having problems when attempting to update a record that has a uniqueidentifier as its primary key.I get the error message:
Object must implement IConvertible. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object must implement IConvertible.I gather this is because there is a bug that has propagated from the beta version.One suggested work around is from http://64.233.183.104/search?q=cache:GDjA62POtgcJ:scottonwriting.net/sowBlog/archive/11162005.aspx+Implicit+conversion+from+data+type+sql_variant+to+uniqueidentifier+is+not+allowed.+Use+the+CONVERT+function+to+run+this+query.&hl=en
The crux of the problem, it appears, is that the <asp:Parameter> value for the uniqueidentifier field is, by default, set to Type=�Object�. To fix this, simply remove the Type property altogether. That is, change the SqlDataSource parameter setting from something like:
<asp:SqlDataSource ...>  <InsertParameters>    <asp:Parameter Name=â€?UserIdâ€? Type=â€?Objectâ€? />    ...  </InsertParameters></asp:SqlDataSource>
to:
<asp:SqlDataSource ...>  <InsertParameters>    <asp:Parameter Name=â€?UserIdâ€?  />    ...  </InsertParameters></asp:SqlDataSource>
This change worked for me; once the Type was removed the exception ceased and the updates/inserts worked as expected.Unfortunately this only partially worked for me as while it is fine for deletes it won't work for updates.If anyone can help shed any light on this I would greatly appreciate it.CheersMark

View 28 Replies View Related

Using Membership UserId Guids With SqlParameters (Membership UserId Guid)

May 7, 2008

In my site, when a user registers, I need to create rows in additional tables besides aspnet_Users. So, I need to be able to pass the generated userId guid to subsequent SqlCommands. I'm having a terrible time with this. What's the correct way to set up a SqlParameter so that it will accept a guid? I keep getting this error: "Conversion failed when converting from a character string to uniqueidentifier."
I've tried creating the parameter both with and without a SqlDbType.
cmd.Parameters.AddWithValue(paramName, guid);
and
SqlParameter p = new SqlParameter(paramName);p.SqlDbType = SqlDbType.Guid;cmd.Parameters.Add(p);
and I get the same error either way.
Driving me nuts! Any help appreciated.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved