Showing posts with label increment. Show all posts
Showing posts with label increment. Show all posts

Friday, February 24, 2012

data types in SQL Server

I'm new to SQL Server, but could someone explain how to set up a field with an auto number/increment that can be used within an Access DB?Go to Books OnLine. Lookup IDENTITY. Read. Create DDL. Try it, you'll like it :) .|||Do you have SQL Server Client Tools Installed?

Do you know what Books Online is?

How about Enterprise Manager or Query Analyzer?

Do you know what DDL is?|||In reply to your questions:

Yes :)
No :confused:
Yes :)
No :confused:

I've found all that and read about it but that's what I've already done. What I wanted to do was set up a system in Access using forms etc but link the tables to SQL Server instead.
Usually when you create the tables in Access and set up an autonumber field, create a form, run it, when you change part of the form it automatically displays the number when you add a record, I take it when doing it through SQL Server it doesn't do that?|||First, I recommend that you create and Access Data Project rather than an Access MDB with linked tables, if you have not already taken this route.

Second, why are you displaying the auto-generated ID on your form anyway? Identity values are surrogate keys, and on principle should not be exposed to the users.

Third, create your auto-incrementing ID value in your table using Enterprise Manager. The identity value is not assigned, however, until the record is saved, so it will not be able to display it on your form until the transaction is committed.

Sunday, February 19, 2012

Data Type Range

Hi,

When I set a tinyint field as identity, it automatically sets the identity seed as 1. I wonder whether the increment is set to go around in loop. Say, I have the range of 256 numbers for a tinybit. So, an identifier should go from 1 to 255 and then to 0 and then back to 1. Is that right?

Not quite.

Once the limit is reached...crash

An identity column creates a constraint that does not allow duplicates and also an index to remember the last number generated.

Use int not tinyint and drop the field and recreate it if you need to.

Adamus

|||

As Adam alluded, an error will occur WHEN there is an attempt to add a 256th row to the table (since the tinyint ranges from 0 to 255, and the IDENTITY column started at 1).

This code will help demonstrate the consequences:

Code Snippet

SET NOCOUNT ON

DECLARE @.MyTable table
( RowId tinyint IDENTITY,
Name varchar(20)
)

DECLARE @.Counter int

SET @.Counter = 1

WHILE @.Counter <= 260

BEGIN
PRINT @.Counter
INSERT INTO @.MyTable VALUES ( @.Counter )
SET @.Counter = ( @.Counter + 1 )
END

|||Thanks