?
Solved

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

Posted on 2003-02-28
2
Medium Priority
?
269 Views
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 :)
0
Comment
Question by:schatz
2 Comments
 
LVL 2

Accepted Solution

by:
wiseguy_2112 earned 400 total points
ID: 8044832
"(SettlementID INTEGER CONSTRAINT PKeyMyId PRIMARY KEY IDENTITY(1,1)

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"

jeff
0
 

Author Comment

by:schatz
ID: 8045295
Thanks Jeff, works great!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

615 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