Showing posts with label property. Show all posts
Showing posts with label property. Show all posts

Sunday, March 11, 2012

Drop Identity property of a column

Is there a way to remove the Identity property of a column in SQL Server 2000?

The statement:

<code>

ALTER TABLE <table name> ALTER COLUMN <column name> DROP IDENTITY

</code>

returns a syntax error.

Thank you,

Jeff

T-SQL's ALTER TABLE statement doesn't support dropping the IDENTITY property in SQL Server2000 or 7.0. Your only option for deleting an IDENTITY column is tocreate a new table structure without the IDENTITY column, then copy thedata into this structure.|||

Thanks Darrell.

Jeff

|||

One more question. Why will SQL Server 2000 allow you to delete the identity property in the designer, but not script the same change?

Jeff

|||you can delete the identity property but you would still have the numbers already generated in the column. New number wouldnt be generated though.|||

Dinakar,

I actually want to do that. I need to turn off the identity property via script, copy data into the table, then turn the identity property back on. I want all the data to stay in the identity column, just not auto-increment during the copy.

Jeff

|||

In that case you can copy all the columns xcept the Identity column into the new table. Then add the Identity column to the new table.

|||In that case you don't really need to drop the column, you're justturning it off. I thought you wanted to remove the IDENTITYcolumn forever.
|||

DarrellNorton wrote:

In that case you don't really need to drop the column, you're justturning it off. I thought you wanted to remove the IDENTITYcolumn forever.


But you can't just turn it off. With SQL Server you would have tocreate a new non-identity column, populate it with the data from theidentity column, then remove the idenitity column. If you need tohave to maintain the same column name then you have to add in somecolumn renaming goodness.

|||

Hello...

from search:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=482&lngWId=5
do test before go to production with big rows table
i just tested with couple of rows in my test table...

-- ----------

USE pubs
GO

EXEC sp_configure 'allow update', '1'
RECONFIGURE WITH OVERRIDE
GO

DECLARE @.col varchar(128), @.table varchar(128)

-- for find identity column (if colstat =1 then identity is on)
SELECT @.col=name
FROM syscolumns
WHERE id=OBJECT_ID('pubs..test') AND (colstat & 1 <> 0)

-- SELECT @.col
IF (@.col IS NOT null) BEGIN

UPDATE syscolumns
SET colstat = colstat ^ 1
WHERE id = OBJECT_ID('pubs..test') and name = @.col

END

EXEC sp_configure 'allow update', '0'
RECONFIGURE WITH OVERRIDE
GO
-- ----------

|||But actually you can just turn the identity property off. You can't just turn it off in code. You can turn it off in the designer but not in the code. This must be a bug in SQL Server 2000 because all functionality in the table designer should be scriptable.
Jeff|||hello...
to set identity column on/off during the insertion.
this is the way,

SET IDENTITY_INSERT [database.[owner.] ] {table} { ON | OFF }
from Books Online:

Remarks

At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft? SQL Server? returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.

If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value.

The setting of SET IDENTITY_INSERT is set at execute or run time and not at parse time.

DROP IDENTITY ?

Is there a way to drop the Identity property of a column in a table using an
Alter Table?
I would like to do it in Query Analyzer, not EM, and I do not want to have
to create a new table and copy the data to the new table (This is how EM
performs this operation.)
I'm looking for some kind of ALTER TABLE or a system procedure. Is it
possible?
(BTW - I don't like the idea of changing the STATUS bit in syscolumns with
an UPDATE syscolumns T-SQL either.)
Thanksdrop the column and recreate it without identity property.
Ex:
create table i(i int not null identity, ii varchar(6000))
go
alter table i drop column i
go
alter table i add i int
go
Note: you can explicitly insert the values into identity column of a table by doing session level
setting of IDENTITY_INSERT.
Ex:
SET IDENTITY_INSERT <table> ON
- Vishal|||You can drop the column if you don't care about losing the
data, otherwise you may need to use EM.
Edgardo Valdez
MCSD, MCDBA, MCSE, MCP+I
http://www.edgardovaldez.us/
>--Original Message--
>Is there a way to drop the Identity property of a column
in a table using an
>Alter Table?
>I would like to do it in Query Analyzer, not EM, and I do
not want to have
>to create a new table and copy the data to the new table
(This is how EM
>performs this operation.)
>I'm looking for some kind of ALTER TABLE or a system
procedure. Is it
>possible?
>(BTW - I don't like the idea of changing the STATUS bit
in syscolumns with
>an UPDATE syscolumns T-SQL either.)
>Thanks
>
>.
>|||cw3,
There is no option in the ALTER TABLE command to drop an IDENTITY property.
If you want to preserve the data in the identity column, include a copy
step. Here's a slight modification of Vishal's solution:
create table MyTable (i int not null identity, ii varchar(6000))
go
insert MyTable values ('X')
insert MyTable values ('Y')
go
alter table MyTable add i2 int
go
update MyTable set i2 = i
go
alter table MyTable drop column i
go
alter table MyTable add i int
go
update MyTable set i = i2
go
alter table MyTable drop column i2
The main disadvantage of this approach is that the column order may not be
what you wanted, because ALTER TABLE puts new columns at the end.
To control column order, you need to do something like what Enterprise
Manager does. You can get the EM script and tweak it yourself before
applying it.
Ron
--
Ron Talmage
SQL Server MVP
"cw3" <cw@.3mc.com> wrote in message
news:ugM9gSEjDHA.1964@.TK2MSFTNGP12.phx.gbl...
> Is there a way to drop the Identity property of a column in a table using
an
> Alter Table?
> I would like to do it in Query Analyzer, not EM, and I do not want to have
> to create a new table and copy the data to the new table (This is how EM
> performs this operation.)
> I'm looking for some kind of ALTER TABLE or a system procedure. Is it
> possible?
> (BTW - I don't like the idea of changing the STATUS bit in syscolumns with
> an UPDATE syscolumns T-SQL either.)
> Thanks
>

Drop extended property "MS_Description" of ALL tables and ALL columns

Hi,

Is there an easy way (a sql script) to drop the "MS_Description" of all tables and all columns in my database?

Regards,
Alejandroo

These queries will produce a script that you can run to drop these properties. You can automate with a cursor, or you might want to add a GO to the end of each EXEC statement.

--tables

select 'EXEC sp_dropextendedproperty

@.name = ''MS_Description''

,@.level0type = ''schema''

,@.level0name = ' + object_schema_name(extended_properties.major_id) + '

,@.level1type = ''table''

,@.level1name = ' + object_name(extended_properties.major_id)

from sys.extended_properties

where extended_properties.class_desc = 'OBJECT_OR_COLUMN'

and extended_properties.minor_id = 0

and extended_properties.name = 'MS_Description'

--columns

select 'EXEC sp_dropextendedproperty

@.name = ''MS_Description''

,@.level0type = ''schema''

,@.level0name = ' + object_schema_name(extended_properties.major_id) + '

,@.level1type = ''table''

,@.level1name = ' + object_name(extended_properties.major_id) + '

,@.level2type = ''column''

,@.level2name = ' + columns.name

from sys.extended_properties

join sys.columns

on columns.object_id = extended_properties.major_id

and columns.column_id = extended_properties.minor_id

where extended_properties.class_desc = 'OBJECT_OR_COLUMN'

and extended_properties.minor_id > 0

and extended_properties.name = 'MS_Description'

|||Thanks a lot Louis, this works perfectly!

Sunday, February 19, 2012

Drillthrough question - how to return to same report page where drillthrough occurred?

Hello,

I have a master report that uses the "Jump to report" property to drill through to a detail report when the user clicks a report column value. This all works great and the users love it. However, when I click the brower's "Back" button to return to the master report, the master report is rerun and I am returned to page 1. If I drilled through on page 25 of the master report then I have lost my original position and I must navigate back to page 25. The users don't love this "feature"!

Is there a way I can return from the drill through detail report to the master report without using the browser's back button and losing my original position in the master report?

Thanks,

BCB

I forgot to mention that I am using Report Manager and not the .NET report viewer control. Also, I don't see any navigational control on the drillthrough report that allows me to "back up" to the master - that is why I have used the browser's "Back" button.

Thanks,

BCB

Drillthrough question - how to return to same page?

Hello,

I have a master report that uses the "Jump to report" property to drill through to a detail report when the user clicks a report column value. This all works great and the users love it. However, when I click the brower's "Back" button to return to the master report, the master report is rerun and I am returned to page 1. If I drilled through on page 25 of the master report then I have lost my original position and I must navigate back to page 25. The users sure don't love this "feature"!

I am using Report Manager and not the .NET report viewer control. Also, I don't see any navigational control on the drillthrough report that allows me to "back up" to the master - that is why I have used the browser's "Back" button.

Is there a way I can return from the drill through detail report to the master report without using the browser's back button and losing my original position in the master report?

Thanks,

BCB

Hi BCB,
sorry I haven't the answer, but can you just explain me how you do to drill through to a detail report with the option "jump to report"... I have a post here : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1455055&SiteID=1

Thank you to take few minutes...
please
|||

Hi Alineo,

You open the properties window for the report field that you want to turn into a drillthrough link. On the "Navigation" tab you select the drillthrough report. Finally, you click the "Parameters" button to add all parameters that the drillthrough report requires. That's all it takes.

BCB

|||

I've had the opportunity to investigate this a little more and I believe it has something to do with report parameters that do not have default values. I'm convinced that a report with no parameters will return to the same page when you click the brower's Back button. In other words, the report won't be run again before you see it.

Reports that have parameters without defaults always seem to be rerun when the user clicks the Back button even though the previously entered values are used when the report is generated.

My results with reports that have parameters with default values have varied. Some reports seem to return to the last-viewed page when the Back button is clicked and other reports are rerun.

I'm still looking for an answer to this so if anyone has a theory I'd appreciate hearing it.

Thanks.

BCB

|||

After spending several hours decomposing a report that suffers from this problem, it appears that a report with a parameter of multi-value type will be always run when the user returns to it by using the browser's Back button. This causes the original report to display page #1 again. Not very nice if you happened to viewing page #39 when you clicked the drillthrough link! I can't be sure there is no other way to cause this problem but the multi-value property is guaranteed to do the trick. I'm assuming this is a bug.

We are running SP2 on our servers.

If anyone has experience working around this problem I'd appreciate hearing your solution. Multi-value parms are a requirement for us.

Thanks,

BCB

Friday, February 17, 2012

drilldown values

When you use the action property of a text box for drill down, how do you
pass the selected value to the report? or is sql reporting smart enough to
know?
--
Thanks,
CGWNever mind... found the button for parameters.
"CGW" wrote:
> When you use the action property of a text box for drill down, how do you
> pass the selected value to the report? or is sql reporting smart enough to
> know?
> --
> Thanks,
> CGW

drilldown newbie

Please excuse me if this double posts. Thought I posted earlier but do not
see it.)
When I use the action property of a text box to bring up a chart, how do i
tell it to chart only that row's values. For example, I want to chart manager
sales over months. I list the managers and their sales as rows and have set
the manager's name text box to jump to my chart. What displays are the sums
for all managers. (all data rows). What do I need to do?
--
Thanks,
CGWNever mind... found the button for parameters.
"CGW" wrote:
> Please excuse me if this double posts. Thought I posted earlier but do not
> see it.)
> When I use the action property of a text box to bring up a chart, how do i
> tell it to chart only that row's values. For example, I want to chart manager
> sales over months. I list the managers and their sales as rows and have set
> the manager's name text box to jump to my chart. What displays are the sums
> for all managers. (all data rows). What do I need to do?
> --
> Thanks,
> CGW