473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Prefix A_I field with number in sql server 2008?

228 100+
Is it possible to prefix A_I field with a number like 301? My initial approach was to check if data exists in table. If no data exists, i would turn on auto increment insertion, insert 3011 then turn off insertion. Would this approach make the operation slow since everytime a row is added, it will do the check, on n off then insert the record?

2ND approach is to fetch the numbers (which could be stored in a table) and have them appended to the A_I automatically during insertion? That is something in my head but i donno how to do it. Is it even possible?

How about using default value? Like we can do convert(date,getdate()) to insert current date to a date field. Would it be possible to do something like this to the default value of the A_I? The 3 attempts i tried failed with errors.

Any idea would be helpful.
Mar 5 '13 #1
5 2675
Rabbit
12,516 Expert Mod 8TB
I have no idea what an A_I field is, it sounds like you're talking about an auto increment?

Why would you need to prefix it with 301? If everything's going to have 301 in front of it, what's the point?

I don't understand why you would need to turn on and off the auto increment. There's no reason to do that.

I'm not sure how you're checking the table for existing data.

All in all, I'm very confused about what you're actually trying to do.
Mar 5 '13 #2
samvb
228 100+
The cause is this basically:

a single design db will be used by offices there n there. Each office got a code like 301 which is unique and already built in in the db when distribution. The offices will export their work/data to us and the problem is that the offices can produce the same A_I values [auto increment]. I just want to b able to identify each row since they all will be merged into the master office's database [which is an exact db the offices use]. Hope i am clear on that area.

From the Stored Procedure that adds rows, i wanted to do something like this:

IF EXISTS (SELECT * FROM tbl)
or SELECT @b=isnull(colname,0) from tbl

that will be done each time a row is going to be added. It works well expect am concerned about the speed and all.

In short, i just want to be able to merge all the data from 11 offices to the master database without a problem. the db does have A_I fields in 4 tables.
Mar 6 '13 #3
Auto increment values cannot be prefixed. Maybe you have to think about a unique location specific id. Together with the A_I value it could be used to form your unique key value. Otherwise how will you keep apart the data from all the different offices if they will have the same A_I value?
What is your deployment architecture? Have you considered to use replication?
Mar 6 '13 #4
samvb
228 100+
The major tables have unique location ids. E.g. order tables have orderid [AI],locationid while orderdetails just refers to orders table and contains primary key without location id.

Even with that, hw i merge the datas in master table? In one blog, i saw away to add an alpahebet but i couldn't find anywhere. Anyway, thanks for ur time guyz.
Mar 7 '13 #5
Rabbit
12,516 Expert Mod 8TB
Just store location ID as a separate field in the table. There's no need to store it separately, in fact, it would be poor design and break the rules of normalization to store it in one field. You can always display it together for reporting purposes but you should store it separately.
Mar 7 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: =?Utf-8?B?S2luZXRpYyBKdW1wIEFwcGxpZmUgZm9yIC5ORVQg | last post by:
Do want to attend the Microsoft SQL Server 2008 and Visual Studio 2008 sessions at your home PC?. Yes now it is possible. Microsoft has scheduled a Webcasts for you on SQL Server 2008 and Visual...
0
by: Gokul | last post by:
Find the latest updates in SQL server 2008 technology and have more details about the latest trends in the IT field. A one shop site for all your IT needs
1
by: =?Utf-8?B?bWFzYWtpeQ==?= | last post by:
Hello, I'm trying to develop 32-bit Windows Native C/C++ application using Visual Studio 2008, on 64-bit Windows Server 2008. Q1. Is it possible to develop 32-bit C/C++ application using VS 2008...
1
by: Chris O'C | last post by:
See: http://blogs.zdnet.com/microsoft/?p=1519 "Microsoft officials announced at TechEd South Africa on August 6 that SQL Server 2008 has been released to manufacturing. "Microsoft officials...
1
by: =?Utf-8?B?QW50amU=?= | last post by:
I need product keys for Terminal Server Windows Server 2008 access (CALs) under MSDN - TSLM Service said they cannot provide product keys for the access.
6
by: AAaron123 | last post by:
I need to move a database from sql server 2008 to sql express 2008. Will backing up the sql server 2008 database to a file and then using that file to restore to sql express 2008 work? I don't...
2
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a server 2008 IIS 7.0 with indexing service installed. I have created the catalog and have a test page using these posts:...
1
by: BobLewiston | last post by:
I installed SQL Server 2008 Express, basic edition (SQLEXPR32_x86_ENU_Bootstrapper.exe, version 9.0.30729.1) without any problem. Then I attempted to install AdventureWorks Sample Databases for...
0
by: Orbie | last post by:
Hi Guys, I need some help with pivoting or converting some rows on a Table into columns using SQL Server 2008! I have a Table which contains the same Products in 4 different Stores. I'm only...
0
by: bkernan | last post by:
I upsized my Asset Template .accdb to SQL Server 2008. Every field except the Attachments works as expected. I tried changing the datatype of the Attachments field in the SQL Server table, no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.