Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to autoincrement ID

Author  Topic 

shruthi_R
Starting Member

10 Posts

Posted - 2007-03-26 : 02:04:03
i have a table for storing username and password.
the following are the fields in table
ID -int
UserName-nvarchar(50)
Password-nvarchar(50)

i dont want to have a separate field for id
i want to autincrement them
plz give me an idea
am using SQLServer Express
am new to this field so plz forgive me for this simple question

thanks
Shruthi

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-26 : 02:07:12
You can't change an existing column to autoincrement. Your only way is to do it through EM.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-26 : 02:07:29
create the ID as identity

create table table_name
(
ID int identity,
UserName nvarchar(50),
. . .
)



KH

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-26 : 10:01:20
quote:
Originally posted by harsh_athalye

You can't change an existing column to autoincrement. Your only way is to do it through EM.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"




Excuse me?

In any case, if you don't want to use IDENTITY, you can still do it the old fashion way


http://weblogs.sqlteam.com/brettk/archive/2004/06/29/1687.aspx




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-27 : 01:28:58
"Excuse me?"

Why?
Do you think otherwise? Is there any other way except to create a new table with identity column and copying existing table contents into it? If yes, please enlighten me.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-27 : 09:30:05
quote:
Originally posted by harsh_athalye

"Excuse me?"

Why?
Do you think otherwise? Is there any other way except to create a new table with identity column and copying existing table contents into it? If yes, please enlighten me.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"




??????

EM is the only way?

DDL & DML in osql for one?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-27 : 09:40:35
Yes, that is true. You can always create a new table with identity, copy all existing contents and once done, drop original table and rename new table with original table name.

But that's what EM do behind the scenes, right?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-27 : 09:44:54
I use Enterprise Mangler about 5% of the time I use QA



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-27 : 09:49:11
Same with me...I suggested using EM only looking at the SQL skills of the poster...I am not a great fan of EM, either.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -