|
-
Mar 3rd, 2004, 12:35 PM
#1
Thread Starter
New Member
Autonumbers in SQL ??
Hi guys,
are there such things as autonumber datatypes in SQL??
I have the following code that create a table from code, but i want the first column to be an autonumber that SQL server can take care of.
Code:
sqlTableConnection = New SqlConnection(strConnectionStr)
sqlTableConnection.Open()
'create table code
sqlTableComm = New SqlCommand("CREATE TABLE Contects (Title VARCHAR(6) NOT NULL, Firstname VARCHAR(20) NOT NULL, Lastname VARCHAR(20) NOT NULL, Created DATETIME NOT NULL, Deleted BIT NOT NULL)", sqlTableConnection)
sqlTableComm.ExecuteNonQuery()
sqlTableConnection.Close()
if there isnt a way to create autonumbers, is it best just to increment a number from the last record in the table??
cheers,
soulcode 
-
Mar 3rd, 2004, 12:48 PM
#2
Thread Starter
New Member
Also... 
What is the best datatype to store phone numbers in?? is it best to store them in a String then validate it on the form, or store it in a number type??
cheers again,
soulcode 
-
Mar 3rd, 2004, 12:55 PM
#3
Frenzied Member
Not sure the exact syntax for SQL Server, but there should be a setting for autoincrement. Check the docs.
Store phone numbers as text. You won't ever perform calculations on them, and if you store them with (), -, etc, that's text anyway.
-
Mar 3rd, 2004, 02:50 PM
#4
Hyperactive Member
Try....
VB Code:
CREATE TABLE Connects (
ConnectsID int IDENTITY (1, 1) NOT NULL , Title VARCHAR(6) NOT NULL, .....
-
Mar 3rd, 2004, 03:42 PM
#5
Frenzied Member
Or use a UniqueIdentifier instead of an Identity.
I would store phone numbers in a varchar(14) field.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 4th, 2004, 10:22 AM
#6
New Member
SQL
Hi folks,
ARPRINCE has posted the correct syntax for an int column with an automatic generated number.
If you prefer a GUID for your PKs try this:
Code:
CREATE TABLE Connects (MyKey uniqueidentifier NOT NULL DEFAULT newid())
Bye
BD
A real hacker never dies. His TTL expires!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|