Dropping Indexes And Recreating The Same

May 1, 2008

I would like to know if there is a way to drop/ disenable all the indexes in a maintenance plan?
Or is it better to write scripts for dropping indexes and recreatig the same?

Purpose: Need to drop indexes(not the Primary key) before loading data and recreate the same after loading

Looking forward for suggestions/Solutions!

Thanks,
Janani

View 2 Replies


ADVERTISEMENT

T-SQL And Dropping And Recreating A Table

Jun 11, 2008

Hi Guys,

I am trying to DROP a table and recreate the table in a stored procedure and then I am trying to INSERT records into the newly created table in the same stored procedure.

I know I don't have to DROP the table, but I am trying to just get it to work. The process runs without error, but when I refresh the tables, the table I created isn't there. The T-SQL is as follows:


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[ImportFilesPremier]

AS

DROP TABLE dbo.[PremierTest]

CREATE TABLE [PremierTest] (
[AYQ] nvarchar(6) null ,
[CYQ] nvarchar(6) null ,
[Description] nvarchar(50) null,
[PIP] [decimal] (17,2) ,
[BI] [decimal](17,2) Not null,
[PD] [decimal](17,2) Not null,
[COLL] [decimal](17,2) not null,
[COMP] [decimal](17,2) not null,
[DCRAT] [nvarchar](2) null ,
[Agent][nvarchar](3) null ,
) ON [PRIMARY]

begin transaction

insert into [PremierTest]
select *
from dbo.[new agt type tri 0804]
WHERE dir_ceded_ind = 'C'

commit transaction


Any information on how I can tweak my code so it works properly would be greatly appreciated. Thank you.

View 4 Replies View Related

Dropping And Recreating Stored Procedure?

Feb 16, 2015

Due to some SSQL application upgrade, some unnecessary columns have been added to the tables and the stored procedures. The values in these columns are NULL and these columns have been added at the end of the tables and some SP.

As my application doesn't require these columns thereby I have re-created the old tables using other environments where these columns were not present.

Can I do the same thing for stored procedures as well i.e. to drop the SP and recreate using other environment which are not having the unnecessary columns.

View 5 Replies View Related

Recreating Indexes Dynamically

Apr 22, 2003

How to get all the index properties like unique, clustered of an index.

I need to recreate all the indexes in a table dynamically
1) need to get the list of indexes
2) drop them
3) change some properties and recreate the indexes, to do this I need to know the columns, uniqueness, clusteredness in step 1 above. How can I get to that?

In oracle we can depend on tables like index_columns, index_constraints....

thx

View 2 Replies View Related

Recreating Indexes After Restore. Urgent -- Please

Sep 4, 2002

Hi all,
I have created a new database from a backup. When I run the application, it seems like it is not getting the right indexes but it is in Development environment. So, I ran a script to recreate the index by DBCC DBREINDEX(TABLENAME). Still not getting it right. mainly it is not using the primary key index. I believe that dbcc dbrenindex will also reindex primarykey indexes. Any one know, how to overcome this problem. It is a production issue and I would appreciate for your prompt advise. I have also ran the update statistics on all tables but with no luck
Note: Does anyone has any script to drop the primarykey index and to recreate it.
Thanks,
Joe

View 2 Replies View Related

Dropping All Indexes

Jan 3, 2007

Looking for suggestions.

I have a database that is giving me a bad Index error. When I go to drop the necessary Index it is telling me that it either does not exist or cannot be dropped. However when I try to build that index, it tells me one already exists.

Is there any way to drop all of the indexes or at the very least see what the indexes are? This particular database is using 2005 Express.

Any help would be great!
Shawn

View 4 Replies View Related

Dropping Clustered Indexes

Sep 20, 2001

SQL 7 created by default a clustered index on my primary key field. I would like to drop this index and recreate it on another field, but it is not allowing me. Error message states: "An explicit DROP INDEX is not allowed... It is being used for PRIMARY KEY CONSTRAINT enforcement." Can anybody advise how I can solve this? TIA

View 1 Replies View Related

MS SQL Server 7 Dropping Indexes

Mar 2, 2000

Hi
Has anyone heard of MS SQL Server 7 dropping indexes?
I had created an index on a table. The next day
the index had disappeared. Has anyone expirienced such
a problem?

Thanks in advance

Winston

View 1 Replies View Related

SP To Check For Existing Indexes Before Dropping.

Nov 7, 2000

I need to add syntax to a stored procedure to check for the existence of a specific indexes on a table before dropping it. If they do not exist I need it to NOT through an error message. Performing this on a table is relatively simple:
if exists (select * from sysobjects where id = object_id(N'[dbo].[TABLENAME]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TABLENAME]

Since indexes are not represented in sysobjects how can I do this?

View 5 Replies View Related

Dropping The Indexes On Production Server

Jun 24, 2008

Dear All,
i'm planning to drop all the non clustered indexes (as they are not congigured well) on production database, and run the latest script to create fresh non clustered indexes on specific columns.

now my doubts are
1)will the replication affect with dropping and recreating of indexes?
2)query to drop all the non clustered indexes on that database....
can i use the query delete from sysindexes where indid>1
will the query works for me to drop all the non clustered indexes?
3)is it necessary to generate a snapshot again after creating the new indexes? or can i drop and run at subscriber also?

please guide me in this regard




Arnav
Even you learn 1%, Learn it with 100% confidence.

View 3 Replies View Related

How To Script Off Indexes Prior To Dropping Them?

Oct 10, 2007

This is for SQL 2005 and I know how to right click an index and do a "script index as create to new query window"

Basically, the one of the Microsoft scripts or views will tell us that we have 100+ indexes that exist for a database but that they are not being used by SQL server.

I will probably take them "offline" for a while and then drop them later on.

Before dropping them, I would like to be able to recreate them within minutes if system performance is degraded after this happens.

I was working on a script to pull this info out of the sys. tables like below but was wondering if anyone already has a script or an easier way to do this. (...and I don't want to right click 100 indexes within 137 tables and script to a new window and then compile a big script)



SELECT

'Create ' +

i.type_desc COLLATE SQL_Latin1_General_CP1_CI_AS +

' Index [' +

i.name +

'] ON ' +

t.name +

CHAR(10) +

c.name +

' ASC'

FROM sys.index_columns ic

Join sys.indexes i ON i.index_id = ic.index_id

JOIN sys.tables t ON ic.object_id = t.object_id

Join sys.columns c ON ic.column_id = c.column_id

WHERE

i.name = 'IX_Sellers_StatusID' and

c.object_id = t.object_id and

i.object_id = ic.object_id

Thanks,
Brian

View 3 Replies View Related

Dropping Indexes Before Bulk Insert

Aug 16, 2007

Hi all,


I have a huge table 170 Gb of size. On that table we have 10 indexes
of around 12 GB in size.

The application is designed such that it bulk inserts the file in to
sql server. But , often we are getting time outs and some latching
isssues ( as can be seen in activity monitor).

So, will this be a good idea of dropping those indexes and then
recreating them again for better performance.

1) Its SQL 2005 Standard Edition SP1

2) Databases are in SIMPLE Recovery mode.

3) Database is not OLTP.

Thanks.

//N

View 2 Replies View Related

Recreating DB Log Files

Jul 25, 2004

I would like to be able to regenerate the log files for our SQL databases without impacting the data files. I tried:
- detaching the database,
- saving the datafiles to another drive,
- dropping and recreating the database with the same structure as before,
- detaching the database again,
- overlaying the data files with the ones I saved previously,
- then reattaching the database.

The reattach fails saying that the files can't be used for different databases.
If I try to bring in log files that are the same size as the database log files I'm trying to recreate, I get the same error only the log files are the ones in error.
I've tried recovering/recreating the database with the "for attach" parameter, but I get the same error.

More information... The problem I'm having that requires the log files to be regenerated is realted to an upgrade to Win 2003 EE. We upgraded the server last week and since then, the backups have been failing. I've tried reloading a backup of the database but the only backups we have are prior to the upgrade and I think, because the database logs are operating system files, the logs don't get loaded correctly and I still have the same backup problem. I logged a case with Microsoft, but they haven't been able to help.

View 3 Replies View Related

Recreating A View

Oct 19, 2007



I have some tables that are created as views in a database.
Everytime I modify table structure the view needs to be recreated.

I am developing a simple Stored Procedure which takes table name as parameter and drops teh view first and then cretaes it again.
The statements required would be

drop view viewname
create view viewname as
select * from ffship.dbo.viewname


The error I get is that

'CREATE VIEW' must be the first statement in a query batch

Any help appreciated.

Thanks,
Kiran.

View 4 Replies View Related

Problem Recreating The Database

Mar 25, 2008

Then I deleted an entire database from the "Enterprise Manager". And refreshed the Query Analyzer.
Then I again tried to create the database.  CREATE DATABASE ContactManager ON PRIMARY(NAME = ContactManager,FILENAME ='C:Program FilesMicrosoft SQL ServerMSSQLDataContactManager.mdf',SIZE = 5MB,MAXSIZE = 20MB,FILEGROWTH = 5MB)LOG ON(NAME = ContactManager,FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQLDataContactManager.ldf',SIZE = 2MB,MAXSIZE = 10MB,FILEGROWTH = 2MB)GoNow it says, database already exists.
I used 'EXEC sp_helpdb' to view all the databases, but the database 'ContactManager' was not there.
Where is the problem?

 

View 1 Replies View Related

Recreating Log File For Sql Server 7

Oct 2, 2000

I have a client who was cleaning up his server to free up disk space and actualy deleted de transaction log file for server database. I can't bring back the backup because it was also deleted (smart...). I still have the .mdf file. Is there a way to bring back the database? I tried to detach and reatach database without success, so the database is no longer attached.

Any help would really help.

Thanks in advance,
Stephane Jeffrey

View 2 Replies View Related

Recreating A Corrupt Database!

Nov 3, 1998

Hello all,

I'm in a bit of a bind. We have a database that spits out a classic corruption error message whenever attempting to run scheduled maintenance:

Error:605, Severity: 21, State: 1
Attempt to fetch logical page ### in databbase 'db1' belongs to object 'table1' not object 'table2'

SQL Books Online says to check with DBCC checkDB and CheckAlloc asap, which I did, and CheckAlloc confirmed the corruption. Books Online's only advice at this point is to restore the DB from a clean backup.

Herein lies the problem. One I'm assuming has happened to many a DBA as well.

This particular message has been going on for months, and there is no "clean" backup of the database, because no-one here at the time knew there were any problems to take precautions. Now I'm here with a corrupt database, and no idea how one goes about reconstructing a DB from scratch. Does anybody out there know any good options?

Thanks in Advance

Fenderson

View 4 Replies View Related

Deleting Users And Recreating

May 7, 2006

In my database, I am currently trying to delete a user and recreate it for ownership. I get the following error message

An exception ocurred while executing a Transact-SQL statement or batch. The database principal owns a schema in the database and cannot be dropped. SQL Server Error 15138.

What do I need to do? Thanks

David

View 1 Replies View Related

Removal Of Selected Indexes / Script Index Create For List Of Indexes

Jul 1, 2014

I'm working to improve performance on a database I've inherited, and there are several thousand indexes. I've got a list of ones which should definitely exist within the database, and I'm looking to strip out all the others and start fresh, though this list is still quite large (1000 or so).

Is there a way I can remove all the indexes that are not in my list without too much trouble? I.e. without having to manually go through them all individually. The list is currently in a csv file.

I'm looking to either automate the removal of indexes not in the list, or possibly to generate the Create statements for the indexes on the list and simply remove all indexes and then run these statements.

As an aside, when trying to list all indexes in the database, I've found various scripts to do this, but found they all seem to produce differing results. What is the best script to list all indexes?

View 5 Replies View Related

Recreating Index After Restore--URGENT PLEASE

Sep 4, 2002

Hi all,
I have created a new database from a backup. When I run the application, it seems like it is not getting the right indexes but it is in Development environment. So, I ran a script to recreate the index by DBCC DBREINDEX(TABLENAME). Still not getting it right. mainly it is not using the primary key index. I believe that dbcc dbrenindex will also reindex primarykey indexes. Any one know, how to overcome this problem. It is a production issue and I would appreciate for your prompt advise.
Note: Does anyone has any script to drop the primarykey index and to recreate it.
Thanks,
Joe

View 1 Replies View Related

Recreating ODBC Connection Strings

Jul 11, 2002

Due to some problems, we have to reformat Our Windows NT4.0 Server.
The SQL Server 2000 has several ODBC Configured as
"User DSN" and "System DSN" .

Question: Is there any way that we could copy these User DSN and System DSN
Config Files so that after Rebuilding Server AND Database, we could Re-aaply/
Re-create these ODBC DSN specifically "System DSN" as they are More Number.

Thanks

View 1 Replies View Related

Recreating ODBC Connection Strings

Jul 11, 2002

Due to some problems, we have to reformat Our Windows NT4.0 Server.
The SQL Server 2000 has several ODBC Configured as
"User DSN" and "System DSN" .

Question: Is there any way that we could copy these User DSN and System DSN
Config Files so that after Rebuilding Server AND Database, we could Re-aaply/
Re-create these ODBC DSN specifically "System DSN" as they are More Number.

Thanks

View 1 Replies View Related

Recreating The Data Publishing Wizard

Mar 27, 2008

Hi,
I was wondering if anyone had an idea if it's possible to run a stored procedure that would basically output a .sql file used to recreate the database elsewhere. kinda like the data publishing wizard does.

?
tx

View 1 Replies View Related

Recreating/reloading System Stored Procedures

Jul 21, 2006

A system stored procedure got accidentally deleted, and all backups aresince the stored procedure was deleted (wonderful!)Can the SQL for the stored procedure be extracted from another serverand loaded as opposed to removing everything and then rebuilding theserver?Thanks in advance!

View 1 Replies View Related

Merge Replication Failing After Recreating The Publication

Jun 7, 2006

I am having a problem with merge replication after recreating a publication. It is a simple two-way replication between two servers allowing applications to update data at both ends, i.e. 1 publisher, 1 subscriber for all tables except some junk ones. The problem started after I did the following:

1) I dropped and recreated the publication to allow for some changes to the database schema. These caused problems so I dropped the subscription and publication and restored the databases at each end from backups taken before we started.

2) When I created the publication again, it wouldn't let me use the same name as it thought the publication already existed. It let me use a different name instead.

3) Most things work OK but one of the tables is not replicating inserts from the subscriber to the publisher. There are no errors and no conflicts, other similar tables replicate OK. Inserts go across the other way OK.

4) I am getting replication conflicts on another table that says 'Unable to synchronize the row because the row was updated by a different process outside of replication'

I believe the problem is to do with the original publication details still being in the restored databases, so am looking to drop the publication & subscription, remove the remnants of the old publication, fix the data and recreate pub & sub. What do I need to do to get rid of the old replication data in the database?

Any help much appreciated.



View 4 Replies View Related

How To Add Tabls To Published Article Without Recreating Snapshot?

Jan 26, 2007

Hi experts:

We have 4 SQL SERVER 2000 servers linked via replication, and due to business changes we have to add one table to the published databases. And the existed database has more than 20g, recreating the snapshot and re-init replication is not allowed as the business cannot be stopped more than 1 hour. So my question is how to add tables to the published article without recreating the snapshot?

By that is not possilbe, can we publish one new article on the same database?



Thanks in advance!

Ron

View 1 Replies View Related

Altering (or Recreating) A Stored Procedure Header

May 30, 2006

We are using SQL Server 2005 to develop a simple SP. We started by including an output parameter which would report back the identity of the record being inserted or updated. We have since been trying to drop and recreate the SP without the output parameter, or alter the SP with the same outcome in mind. Neither has been succeeding, as confirmed by inspection of the sys.objects and sys.parameters tables. What might we be missing? We are using the Developer Edition, which may or may not be adequate to the task. Or maybe earlier versions of SQL Server are more robust and would be more successful to help us succeed? Please advise. Thank you.

View 5 Replies View Related

Recreating The Functionality Of A Extended Stored Procedure That Uses Srv_impersonate_client

Mar 1, 2006

I need help rewriting an extended stored procedure as a CLR.

What this extended stored procedure does is to return the domain username of the person connected via named pipes.

This is accomplished by using the srv_impersonate_client and GetUserName functions from opends60.lib. I have tried rewriting this in CLR using Microsoft.SQLServer.Server.SQLContext.WindowsIdentity but have been unable to replicate the functionality to return the same values as the srv_impersonate_client.

If anyone knows how I can rewrite this as CLR, let me know, Also I am looking for where I can get a 64bit version of opends60.lib to run on an amd64

Thanks
Darryl

View 6 Replies View Related

A Question About Clustered Indexes Forcing Rebuild Of Non-clustered Indexes.

Sep 18, 2007

So I'm reading http://www.sql-server-performance.com/tips/clustered_indexes_p2.aspx and I come across this:
When selecting a column to base your clustered index on, try to avoid columns that are frequently updated. Every time that a column used for a clustered index is modified, all of the non-clustered indexes must also be updated, creating additional overhead. [6.5, 7.0, 2000, 2005] Updated 3-5-2004
Does this mean if I have say a table called Item with a clustered index on a column in it called itemaddeddate, and several non-clustered indexes associated with that table, that if a record gets modified and it's itemaddeddate value changes, that ALL my indexes on that table will get rebuilt? Or is it referring to the table structure changing?
If so does this "pseudocode" example also cause this to occur:
sqlstring="select * from item where itemid=12345"
rs.open sqlstring, etc, etc, etc
rs.Fields("ItemName")="My New Item Name"
rs.Fields("ItemPrice")=1.00
rs.Update
Note I didn't explicitly change the value of rs.fields("ItemAddedDate")...does rs.Fields("ItemAddedDate")=rs.Fields("ItemAddedDate") occur implicitly, which would force the rebuild of all the non-clustered indexes?

View 4 Replies View Related

How To Alter The Table With Delete/update Cascade Without Recreating The Table

Jul 26, 2004

I have contract table which has built in foreign key constrains. How can I alter this table for delete/ update cascade without recreating the table so whenever studentId/ contactId is modified, the change is effected to the contract table.

Thanks


************************************************** ******
Contract table DDL is

create table contract(
contractNum int identity(1,1) primary key,
contractDate smalldatetime not null,
tuition money not null,
studentId char(4) not null foreign key references student (studentId),
contactId int not null foreign key references contact (contactId)
);

View 3 Replies View Related

Regarding ReCreating Catalog In SQL Server 2005 Which Was Existing In SQL Server 2000

Feb 24, 2008



Hello

I was using SQL SERVER 2000 ... In one table I've created FULL TEXT SEARCHING ( Full text catalog along with full text indexing)

Now we had to install our db in SQL SERVER 2005 standard edition. But while taking script it gave me two lines like:


if (select DATABASEPROPERTY(DB_NAME(), N'IsFullTextEnabled')) <> 1
exec sp_fulltext_database N'enable'
GO
if not exists (select * from dbo.sysfulltextcatalogs where name = N'DEV_CAS_DiagnosisCatalog')
exec sp_fulltext_catalog N'DEV_CAS_DiagnosisCatalog', N'create'
GO

so I used this in the new db creation script...

But I couldn't get where it actually is in SQL SERVER 2005 standard edition.

and also plz help how should we create if it doesn't exist...

What could be the problem....

Thanks In advance

View 3 Replies View Related

SQL Server 2008 :: Logic To Rebuild Only Clustered Indexes / Skipping To Rebuild Non Clustered Indexes In Same Table

Jun 25, 2015

I have a requirement to only rebuild the Clustered Indexes in the table ignoring the non clustered indexes as those are taken care of by the Clustered indexes.

In order to do that, I have taken the records based on the fragmentation %.

But unable to come up with a logic to only consider rebuilding the clustered indexes in the table.

create table #fragmentation
(
FragIndexId BigInt Identity(1,1),
--IDENTITY(int, 1, 1) AS FragIndexId,
DBNAME nvarchar(4000),
TableName nvarchar(4000),

[Code] ....

View 5 Replies View Related

Indexes Vs Clustered Indexes

Sep 17, 2006

What is the difference please?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved