Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2005, 08:50 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Server Primary key

How would I do with sql server a Decimal Primary key that would be table identifier.

ie. Table name: Product
PID, PK and I want PID in database in form 1.1 and next product would be 2.1
NAME CHAR

How can I do this

Please help.

 
Old September 23rd, 2005, 08:56 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Change it to an int and make it an identity

or do it with a trigger manually


http://sqlservercode.blogspot.com/
 
Old September 23rd, 2005, 09:34 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But I Want it to be a decimal int can't take number lik 1.1 or 2.1
I need to have identity key in decimal form.


 
Old September 23rd, 2005, 09:37 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can't do that
What you can do is maintain this yourself with triggers, stored procedures and transactions

http://sqlservercode.blogspot.com/
 
Old September 23rd, 2005, 09:48 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

why can't I do it. Why must the identifier key be a int why can't it be decimal

 
Old September 23rd, 2005, 09:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

While it is possible to assign the IDENTITY property to a column defined as a decimal (or numeric) type, you are forced to define the identity increment using a size value of 0, meaning that only integer values of this decimal column will be assigned as identity values.

You are making a big mistake attempting to assign meaning to an identity column beyond the fact that the identity property guarantees unique values automatically assigned by the system when a row is inserted. I think you are attempting to attach some other meaning to this key by assigning fractional values. Perhaps something like a version number or assembly part or something?

Create instead a separate column for this part number/product assembly identifier or whatever it is and don't confuse it with an identity value. Manage it in your code or via a trigger as others have suggested.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old September 23rd, 2005, 09:57 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would use it to transfear it to a shopping cart. But problem is that I have two tables (products and table for productpackages) . Both tables have products that should be able to add in shopping cart. But if I put them like I have them now , so in some moment the would have same identity key and then crash

 
Old September 23rd, 2005, 10:04 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create a lookup table
with an identity and store all the combinations in 2 other fields

ID prodid packageid
1 1 1
2 2 1
3 1 2
4 2 2
5 3 2
6 1 1

etc etc etc
Then use that identity in your cart

http://sqlservercode.blogspot.com/
 
Old September 23rd, 2005, 10:18 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how can I do in database that the identity number should always have number 6 or anohter number as prefix

 
Old September 23rd, 2005, 10:24 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use DBCC CHECKIDENT and reseed to 60000000 (600 million)
every insert after that will start with 6 (assuming you don't ship over 100 million products)

Like this
DBCC CHECKIDENT (TableName, RESEED, 60000000 )



http://sqlservercode.blogspot.com/





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Design: Foreign Key to Multiple Primary Keys? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 May 8th, 2008 04:14 PM
SQL to identify the primary key in a table? dbayona SQL Server 2005 1 October 24th, 2007 02:33 AM
SQL Server Primary Key Incrementer tclancy SQL Server 2000 13 March 23rd, 2006 09:44 AM
How to Auto Generate ID (Primary Key) SQL database havering SQL Server 2000 9 December 1st, 2004 10:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.