Create a table with default value in a field and autonumber in primary key.

Posted on 2003-02-28
Medium Priority
Last Modified: 2008-02-26
Hi folks,

I'm using a C# program to create tables in MS SQL 2000 server database. This code is as follows:

Insert.CommandText = "CREATE TABLE " + test +
                    "(SettlementID INTEGER CONSTRAINT PKeyMyId PRIMARY KEY,"+
                    "RecordNumber INTEGER, TerminalNumber INTEGER, MerchantRegion INTEGER,"+
                    "MerchantOfferNumber INTEGER, TransactionDateTime DATETIME,"+
                    "TransactionSequenceNumber INTEGER, TransactionType VARCHAR(1),"+
                    "CardAccountNumber VARCHAR(14), TransactionAmount MONEY)" ;

               object count = Insert.ExecuteNonQuery();

I need to be able to programatically set Identity:Yes for the primary key to make it autonumber and also I need to set the defaut value of MerchantRegion a certain number.

Does anyone has ideas?

Thanks, Schatz

PS Those are actually two questions, therefore you get more points :)
Question by:schatz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

wiseguy_2112 earned 400 total points
ID: 8044832

IDENTITY(1,1) makes it autonumber, the 1,1 is starting identity and increment amount (for example you want to start at 1000 and increment by 10...IDENTITY(1000, 10)

MerchantRegion INTEGER DEFAULT 222

DEFAULT 222 would make it default to "222"


Author Comment

ID: 8045295
Thanks Jeff, works great!!!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question