Showing posts with label indentity. Show all posts
Showing posts with label indentity. Show all posts

Thursday, March 8, 2012

alter indentity field

Hi Guys,
I'm using SQL server 2000.

How do I alter column/field from type int (with Identity = Yes Not For Replication) to just normail int field. No more identity. I want it to be done using SQL script( sql query analyzer).

Please help me on this, thx

Regards,
ShaffiqHi Guys,
I'm using SQL server 2000.

How do I alter column/field from type int (with Identity = Yes Not For Replication) to just normail int field. No more identity. I want it to be done using SQL script( sql query analyzer).

Please help me on this, thx

Regards,
Shaffiq

alter table table_name
alter column column_Name int not null


that should solve your problem.|||Hi Enigma,
I'd tried it before but it not work. Even query analyzer return success message "The command(s) completed successfully." but when I open the table it still the same. And the identity field still ON

Regards,
Shaffiq|||do alteration in Enterprise Manager( dont save it) and click on 'save change script'(3 rd button from second row).copy and run that script in query analyser|||or

Alter Table MyTable ADD NewColumn int
GO
UPDATE MyTAble SET NewColumn = OldColumn
GO
ALTER TABLE MyTable DROP COLUMN MyCOlumn
GO
sp_rename 'MyTable.NewColumn','OldColumn',COLUMN

Wednesday, March 7, 2012

Alter column to Identity

Is it possible to alter the column of integer type as indentity field
through query?
MadhivananSort of. You have to create a new table, insert the rows from the old
table, then drop the original table.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Madhivanan" <madhivanan2001@.gmail.com> wrote in message
news:1124967989.632225.140630@.o13g2000cwo.googlegroups.com...
Is it possible to alter the column of integer type as indentity field
through query?
Madhivanan|||Well
If it is possible to do this from EnterPrise Manager, then I wonder why
there is no query to do this?
Madhivanan|||Hi, Tom
I think , there is no need to create a new table , we can just add a new
column.
create table #t
(
col int
)
insert into #t values (10)
insert into #t values (100)
go
alter table #t add col1 int identity(1,1)
go
select * from #t
go
alter table #t drop column col
go
select * from #t
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
news:ucmrsVWqFHA.3540@.TK2MSFTNGP14.phx.gbl...
> Sort of. You have to create a new table, insert the rows from the old
> table, then drop the original table.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "Madhivanan" <madhivanan2001@.gmail.com> wrote in message
> news:1124967989.632225.140630@.o13g2000cwo.googlegroups.com...
> Is it possible to alter the column of integer type as indentity field
> through query?
> Madhivanan
>|||Enterprise Manager actually does it the way I described.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Madhivanan" <madhivanan2001@.gmail.com> wrote in message
news:1124968780.394543.215750@.o13g2000cwo.googlegroups.com...
Well
If it is possible to do this from EnterPrise Manager, then I wonder why
there is no query to do this?
Madhivanan|||True, though the ordinal positions have to change. Also, the original
values aren't preserved.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:eU1%23afWqFHA.3192@.TK2MSFTNGP10.phx.gbl...
Hi, Tom
I think , there is no need to create a new table , we can just add a new
column.
create table #t
(
col int
)
insert into #t values (10)
insert into #t values (100)
go
alter table #t add col1 int identity(1,1)
go
select * from #t
go
alter table #t drop column col
go
select * from #t
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
news:ucmrsVWqFHA.3540@.TK2MSFTNGP14.phx.gbl...
> Sort of. You have to create a new table, insert the rows from the old
> table, then drop the original table.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "Madhivanan" <madhivanan2001@.gmail.com> wrote in message
> news:1124967989.632225.140630@.o13g2000cwo.googlegroups.com...
> Is it possible to alter the column of integer type as indentity field
> through query?
> Madhivanan
>|||In your query
1.create a temp table
2.insert all rows to the tepm table
3.drop your table
4.create it with an IDENTITY property on that column
5.Set IDENTITY_INSERT yuor_table_name ON
6.insert all rows into your table
7.Set IDENTITY_INSERT yuor_table_name OFF
If the table has dependencies then it is more complicated...
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
news:OJAVmkWqFHA.3064@.TK2MSFTNGP15.phx.gbl...
> True, though the ordinal positions have to change. Also, the original
> values aren't preserved.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:eU1%23afWqFHA.3192@.TK2MSFTNGP10.phx.gbl...
> Hi, Tom
> I think , there is no need to create a new table , we can just add a new
> column.
> create table #t
> (
> col int
> )
> insert into #t values (10)
> insert into #t values (100)
> go
> alter table #t add col1 int identity(1,1)
> go
> select * from #t
> go
> alter table #t drop column col
> go
> select * from #t
>
>
> "Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
> news:ucmrsVWqFHA.3540@.TK2MSFTNGP14.phx.gbl...
>|||> If it is possible to do this from EnterPrise Manager, then I wonder why
> there is no query to do this?
Why don't you start up profiler, and watch what happens when you do this in
Enterprise Manager. You will see that there is no query to do this, the
system actually does what Tom described.|||Try this in EM:
Open a table in desig mode
Change a column to Identity
Before saving the change, lick on the icon Save Change Script
You will see the script EM generates to make the change.
Try to choose a table that has at lease one foreign key reference.
On one of my base tables, this generates 285 lines of code.
"Madhivanan" <madhivanan2001@.gmail.com> wrote in message
news:1124968780.394543.215750@.o13g2000cwo.googlegroups.com...
> Well
> If it is possible to do this from EnterPrise Manager, then I wonder why
> there is no query to do this?
> Madhivanan
>|||Thanks Raymond
Now I clearly understand
Madhivanan