Removing Replication If Db Exists Using T-SQL

Jan 21, 2008

Hi,

I'm trying to write a create database script for a test database and I need to check if the database exists before dropping and recreating it. The problem I'm having is that the test database is also merge replicating so if the db exists I need to remove the replication and then drop the database. I'm running the script using osql from a NAnt build script. The script goes something like this:

USE master
GO
if exists (select * from sysdatabases where name = N'@INITIAL_CATALOG@')
BEGIN
USE [N'@INITIAL_CATALOG@']
EXEC sp_dropmergepublication @publication = N'@PUBLICATION@'
USE master
EXEC sp_replicationdboption @dbname = N'@INITIAL_CATALOG@', @optname = N'merge publish', @value = N'false'
DROP DATABASE @INITIAL_CATALOG@
END
GO
CREATE DATABASE ...

Where the NAnt script replaces the @PARAMETER@ fields before running the script. Running the script using osql when the database doesn't exists appears to fail on parsing the line "USE [N'@INITIAL_CATALOG@']" with the error "Could not locate entry in sysdatabases for database '[DatabaseName]' ..." and does not create the database. If I run the same script in SQL Management Studio I get the same error but it does create the database.

The script should only execute the USE [N'@INITIAL_CATALOG@'] statement if the database exists, but the parser isn't able to see this and returns an error. If anyone can see an error in this script syntax, or see a different way of doing the same function without getting errors I would greatly appreciate it.

Regards,

Greg

View 4 Replies


ADVERTISEMENT

Removing Replication

May 8, 2003

Hi,

We had transactional replication set up by a consultant with remote distributer, push subscription to the publisher (main production database). However, the subscriber machine had fatal crash and is unrecoverable. Now, replication jobs have been failing on distributor and we immediately need to disable and remove replication as it has started causing problems with transaction log backups on production database.

How can I completely remove this whole replication from publisher and distributor?

Please help.

Thanks,
Shaili

View 5 Replies View Related

Suspect Db - Removing Replication

Jun 28, 2001

Hi all,

I have a db (with replication enabled) which was marked as suspect. As per the logs it is the Hardware crash that caused this db to become suspect.
Tried with sp_resetstatus to recover the db. But it is still in suspect mode. Changed the db into emercengy mode to recover the data thru' bcp which was succesful. Since there is no other way to recover the db, now I want to drop the db and create / restore the db from backup.
I am unable to drop the db becasue it is having a publication. I am also unable to drop publication becasue now the db is in emergency mode.
Kindly help and inform how I can drop the db and create it again from the backup without reinstalling SQL Server again.

TIA.

Ravi

View 1 Replies View Related

Removing Replication Triggers.

Jan 13, 2005

Does anyone know how to remove 'Replication Triggers'?

I have a database created by export of data object. This process does not export any system tables to do with replication but there still seems to be something in the database which references them. There is no poblem if I backup and restore the dataabse.

Any advice?

Thanks Ed

View 1 Replies View Related

Removing Merge Replication

May 22, 2007

Several years ago I set up Merge Replication on a SQL 2000 database and an MSDE Client on a Laptop. The Laptop frequently travelled out of the country and would "synch" up when it came back in.

Well the Laptop received some Viruses that we cannot get to remove so putting it on the network is not possible. Also, the owner of the laptop received a new one. He wants the database set up on the new laptop but it is not a priority at the moment and we plan to wait till the "Yemen" project is finished.

In the mean time, I want to remove the old laptop out of the Merge Replication scenario. We are not concerned about losing the data in the database on the laptop.

Does anyone know the steps I need to perform to "unreplicate" my database without being able to connect them?

View 3 Replies View Related

Removing Replication Table

Oct 12, 2005

Hi all,

View 10 Replies View Related

Issues With Removing Replication

Jan 17, 2007

SQL Server 2005 Standard replicating to an identical server.

My issue:

When we go into the database to remove a large number of rows, it says we are unable to delete since the database is in replication. Is there a way to pause, or stop replication temporarily? I stopped the log reader but it still gave me the same error.

The only way I have found around this is to delete the publication and re-create it when I'm ready. Now though, I'm unable to delete the publication. SQL Server Management Studio will freeze if I either try to delete something from the UI or command line. This happens with objects in SQL Server as well as rows and such. It will just freeze and I have to kill the process.

Please Help!

View 16 Replies View Related

Removing System Replication Tables.

Jul 23, 2005

Hi, i restored a backup from a database thas has replication configured.When i restored it the system tables that the merge replication createsare restored too. I was investigating on internet and I found that i candelete it using this query:sp_configure 'allow updates', 1goreconfigure with overridegoDROP TABLE aonflict_SiacDataEEC_security_info...sp_configure 'allow updates', 0goreconfigure with overridegoDo somebody know if i use this queries to delete this tables i candamage the database or is correct to use it.Thanks a lot for your help.*** Sent via Developersdex http://www.developersdex.com ***

View 1 Replies View Related

Removing Replication Monitor In Enterprise Manager

Mar 16, 2006

Hi guys does anyone know of a quick solution to remove the replication monitor icon within Enterprise Manager please I have tried all sorts but it is still appearing and starting to irritate me as I don't use replication on this server.
cheers

Jim

View 8 Replies View Related

Enterprise Manager Hanging When Removing Replication

Aug 29, 2007



I'm trying to remove replication from my database so that I can run some update scripts on it but SQL Enterprise Manager just keeps hanging on me. I've searched the web an no-one seems to have had this problem.

Does anyone know of this problem or have they experienced it? If so, can you help?

Am I doing something wrong trying to remove the replication (deleting the publication)?

Thanks.

View 2 Replies View Related

IF NOT EXISTS (... - EXISTS TABLE : Nested Iteration. Table Scan.Forward Scan.

Sep 20, 2006

Hi,

This is on Sybase but I'm guessing that the same situation would happen on SQL Server. (Please confirm if you know).

I'm looking at these new databases and I'm seeing code similar to this all over the place:

if not exists (select 1 from dbo.t1 where f1 = @p1)
begin
select @errno = @errno | 1
end

There's a unique clustered in dex on t1.f1.

The execution plan shows this for this statement:

FROM TABLE
dbo.t1
EXISTS TABLE : nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.

It's not using my index!!!!!

It seems to be the case with EXISTS statements. Can anybody confirm?

I also hinted to use the index but it still didn't use it.

If the existence check really doesn't use the index, what's a good code alternative to this check?

I did this and it's working great but I wonder if there's a better alternative. I don't really like doing the SET ROWCOUNT 1 and then SET ROWCOUNT 0 thing. SELECT TOP 1 won't work on Sybase, :-(.

SET ROWCOUNT 1
SELECT @cnt = (SELECT 1 FROM dbo.t1 (index ix01)
WHERE f1 = @p1
)
SET ROWCOUNT 0

Appreciate your help.

View 3 Replies View Related

Removing *

Aug 18, 2005

Hi! I am trying to remove an "*" I used to transfer a file from Excel to SQL. I put the "*" in the NULL values so that I would not get an error. Now that I have the file in SQL, I need to remove the :*" from some columns in my table. How can I select all of those in a column and delete them without deleting each individual one. Any ideas?

Thanks for your help.

Scott

View 6 Replies View Related

Removing Old Bak

Jan 15, 2008

Started with maintenance cleanup task set up bak and directory did not delete the files.

Then found this http://blog.solidsoft.com/blogs/richards_infrastructure_blog/archive/2007/07/12/369.aspx

Copy script

use master
declare @dt datetime
select @dt=getdate()-2
EXECUTE master.dbo.xp_delete_file 0,N'D:BackupAcctDB',N'BAK',@dt

Get message

Msg 22049, Level 16, State 1, Line 0
xp_delete_file() returned error 2, 'The system cannot find the file specified.'

Anyone else get problem with removing BAK files

View 4 Replies View Related

Removing Padding From Var

Feb 7, 2008

I have a search box to look up using a number as an identifier. Currently my query is where x = @enteredNumber, but some place where a user might get the number it is padded with zeros. We can have them just see the number and retype it.
 EG: 000000123  would be entered as 123.
 But, I would like to let them copy and paste, but then strip the zeros (left padding only).
EG:
@num = stripPadding(@enteredNumber)
IE:
@num = stripPadding(000000123)
@num = 123
 

View 2 Replies View Related

Removing A Default...

Sep 4, 2002

Hi,

I'm using SQL Server 7.0 SP3. I added a column to a table like so:

ALTER TABLE T704_RELATIONSHIP_INDEX_CLIENT_REPORT_STORE
ADD Universe_Member_Set_cd INT NOT NULL DEFAULT 1

What is the syntax for dropping the 'DEFAULT' from this column once it has been created? I've looked in BOL but can't seem to get the syntax correct.

Thanks in advance,
Darrin

View 1 Replies View Related

Removing The Duplicates

Aug 2, 2000

I need to remove the duplicates from a table. If a record exits 4 times in a
table I need to delete 3 records and retain only one occurance of that.

I need a query to do this.

Can anybody help.

-Rajesh

View 3 Replies View Related

Removing BuiltinAdministrators

Mar 20, 2002

Hi all,

I am using SQL 2k SP2 on Win 2K Advance server Cluster. My problem is how to remove builtinAdministrators login. Earlier when I tried it was doing failovers from one node to another and not stopping. I was not able to do anything. Any help is appriciated

thanks,
Minesh.

View 3 Replies View Related

Removing DB Suspect

Aug 31, 2000

I wonder if one can give a hint on remove a DB suspect,
Mind you I have used SP_dbremove still did not remove the DB
This is on SQL 7.0 box

Any idea welcomed

Saad

View 2 Replies View Related

Removing A Filegroup

Apr 25, 2000

Hello,

A few days ago one our database's default filegroup filled up. To solve the problem one of my colleagues created a new filegroup. This didn't solve the problem as no objects were placed on this filegroup and the initial one is still full. The idea was to expand the original filegroup over a new physical disk, not to create a new filegroup on that disk. Unfortunately, this is what happened.
To solve this I want to delete the new filegroup, but when I issue the command 'alter database PvgOmcsOds remove filegroup ternary' I get the message 'Server: Msg 5042, Level 16, State 7, Line 1 The filegroup 'ternary' cannot be removed because it is not empty.' Yet there're no objects placed on this filegroup.
How can I get rid of this filegroup?

Stef

View 2 Replies View Related

Removing Transaction Log From SQL 7 DB

Apr 7, 1999

I am trying to remove a transaction log that has grown too large for its databse and server. I have truncated the log and have run dbcc shrinkfile with the EmptyFile Option, but when I try to use alter database remove file and am I told that the object is not empty and cannot be removed. The server is in dbo use only.

What am I missing?

View 1 Replies View Related

Removing Filegroup

Mar 8, 2001

Hi all,

I am trying to remove one of the filegroups in the development database to shrink its size down. I started with emptying and removing its files and ran:
dbcc shrinkfile
(pubs_data_1,emptyfile)
go

and it ran fine, with 'DBCC execution completed' message

but when I tried :

alter database pubs
remove file pubs_data_1
go

I got 'pubs_data_1 cannot be removed because it is not empty'.
I even tried to go to each of the tables and delete from them first which didn't work, then drop all tables in that filegroup (I knew which tables are located on that filegroup), that didn't work either.

Any ideas? Is there a way to check what else sits on that filegroup?

Thanks

View 2 Replies View Related

Removing SQL 6.5 Software

May 28, 1999

Dear Concerned DBAs,

I am wanting to pick someones brain and find out if there is anything I can do to successfully remove and reinstall SQL Server Version 6.5? I have already removed the software from the SQL Setup icon in ProgramsMSSQL Server 6.5 and went and removed the setup.exe and mssql files associated with the software from the server. Now when I attempt to reinstall the software back onto the server after a hard reboot, I do not get the option once the SQL Server Version 6.5 disk is placed into the CD-Rom to install SQL Server. The only options I get are upgrade, server configurations, etc.

Can anyone or everyone give me a hand as to where to take this dilemma other than rebuilding the server from the ground up?

Anticipatorily Yours,
Daimon Russell

View 3 Replies View Related

Removing Certain Characters

Aug 18, 2006

Hello all,

I have a table named users. It consists of user names, user ids, etc... The problem is that whoever designed the ASP code before me allowed people to enter info in any format they want. This poses a problem because now the name can have 1, 2, or sometimes 3 spaces in between the last and first names. And sometimes the middle initial is used with a period following it. This creates problems when I am trying to execute a Select statement since it won't match if there are an unknown number of spaces in the string and throws an error when a period is used.

Is there a SQL query I can execute to change all the user_names into a format such as the following:
LastName, FirstName MiddleInitial

Like I said, it is already almost the same, just has too many spaces and some have periods after the middle initial

View 5 Replies View Related

Removing Duplicates

Jan 27, 2005

I have a members table and have added an extra few thoushand members to it. Now I need to remove the duplicates.

It doesnt matter which duplicate i remove as long as there are unique email addresses.

so here is the format of the table:

id
email
firstname
lastname
datebirth

if i do a:

SELECT COUNT(DISTINCT Email) AS Expr1
FROM Customer

it returns 21345

and

SELECT Count(Email)
FROM Customer

returns 28987

I can get the unique email addresses into another table by going:

SELECT DISTINCT emailaddress INTO DistinctCustomer
FROM Customer

but this will only return unique email addresses. How do i select distinct email address and all other fields into a new table? or just remove duplicates where email address appears more then once?

Thanks in advance

Tom the SQL beginner

View 5 Replies View Related

Removing A Paratiotion

Jun 24, 2008

i want to build a paratiotin which the key of the paratition will be a datre in this structure :
20080101235959
20080102235959
20080103235959
20080104235959
20080105235959
and so on.....
and i want that when there is a paration that it's "date" is more then 30 days to delete it (and that its data will be deleted too)
how do i do that?
thnaks in advance
peleg





Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

View 5 Replies View Related

Removing Primary Key

Nov 27, 2005

Hi How do i remove the primary key for this table


create table table2
(col1 int,
col2 int,
primary key(col2))


Thanks
Vic

View 2 Replies View Related

Removing Last Two Char

Apr 25, 2007

Afternoon all

What is the quickest way to remove the last two char from a colunm and leaving the rest of the colunm intact.

cheers

View 4 Replies View Related

Removing Data

Jul 23, 2005

I have a table that I need to delete some data from and put the deleteddata into a different table.How do I script the following.If Field1 in Table1 is null, remove that row from Table1 and put it ina new table called Table2Regards,Ciarán

View 5 Replies View Related

Removing Duplicates

Jul 20, 2005

HiI have inherited a web app with the following table structure, and need toproduce a table without any duplicates. Email seems like the best uniqueidentifier - so only one of each e-mail address should be in the table.Following http://www.sqlteam.com/item.asp?ItemID=3331 I have been able toget a duplicate count working:select Email, count(*) as UserCountfrom dbo.Membersgroup by Emailhaving count(*) > 1order by UserCount descBut the methods for create a new table without duplicates fail. My code forthe 2nd method is:sp_rename 'Members', 'temp_Members'select distinct *into Membersfrom temp_MembersTable....CREATE TABLE [dbo].[Members] ([MemberID] [int] IDENTITY (1, 1) NOT NULL ,[Username] [varchar] (10) COLLATE Latin1_General_CI_AS NOT NULL ,[Password] [varchar] (10) COLLATE Latin1_General_CI_AS NOT NULL ,[Email] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL ,[Title] [varchar] (10) COLLATE Latin1_General_CI_AS NOT NULL ,[FirstName] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL ,[Surname] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL ,[Address1] [varchar] (35) COLLATE Latin1_General_CI_AS NOT NULL ,[Address2] [varchar] (35) COLLATE Latin1_General_CI_AS NOT NULL ,[City] [varchar] (25) COLLATE Latin1_General_CI_AS NOT NULL ,[Country] [varchar] (25) COLLATE Latin1_General_CI_AS NOT NULL ,[Profession] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL ,[Publication] [varchar] (40) COLLATE Latin1_General_CI_AS NOT NULL ,[DateAdded] [smalldatetime] NOT NULL ,[SendMail] [smallint] NOT NULL) ON [PRIMARY]GOThanks B.

View 2 Replies View Related

Removing Zeros

Sep 24, 2007

Hi,
I have a column cost with sample record as '00003433' . how can i remove all zeros in left side alone?.

Out put : 3433.

Thanks
Raj

View 4 Replies View Related

Removing A Server Name

Mar 31, 2007

SQL
Upgrading to VS05 Pro SP1/SqlExpress (from VS03 Pro/SQL MSDE)

Question 1) €“ is there a way to tell which version of the SQL Express was installed? I think it is €œSQL Server 2005 Express Edition With Advance Services€?, but don€™t know how to confirm that.

Question 2) - SQL Server Management Studio Express, Registered Servers, it shows :
Database Engine
sqlexpress (note the lower case)
If I right click and choose €œPreviously Registered Servers€?, it shows a message that I will be displaying SQL Server 2000 (i.e. MSDE) server names, and it shows
SQL Server Group
SQLEXPRESS (note the upper case)
CSOLUTION

I wish to completely remove CSOLUTION (in MSDE you would uninstall it from the Control Panel), but right clicking and choosing the delete option does nothing (it does not delete it). Deleting SQL Server Group also has no affect either. How do I remove CSOLUTION ?

Question 3) - In the VS05 program, the SQL connection string includes €œData Source=.SQLEXPRESS€¦.€? (NOTE UPPER CASE) Why do I have a lower case and an upper case listed above? Starting/stopping one sqlexpress/ SQLEXPRESS does the same to the other. Don€™t I wan€™t to complete delete anything under SQL Server Group since it represents SQL Server 2000 (i.e. MSDE) server names? SQL Server 2000 and CSOLUTION have been uninstalled from this machine.

Thanks!
bob

View 1 Replies View Related

Removing BUILTINAdministrators

May 1, 2007

We need to remove the BUILTINAdministrators from reporting services. I.T. personnel do not want to be able to see restricted reports. We have two department users that have been added as Content Managers and we are running reporting services under a created domain user account that we created and not a system service. I have removed BUILTINAdministrators from the Home folder and when I check, it comes right back. Do I need to deny access to BUILTINAdministrator on SQL Server 2005 itself? I would apprecate any suggestions.

View 1 Replies View Related

Removing A Certificate

Apr 28, 2008



Hi i'm having issues removing this certificate

select * from sys.certificates





I see


cert_xp_cmdshell_enabler 257 1 NA NO_PRIVATE_KEY 1 Enable xp_cmdshell c5 30 7d 58 ba 8e 96 a6 48 48 df ca 87 bc 91 44 0x010600000000000901000000BEC4CB23E7994CFF1E71403F906BB1EFFDDEAF9A S-1-9-1-600556734-4283210215-1061187870-4021382032-2595217149 Enable xp_cmdshell 2009-04-28 10:31:31.000 2007-04-28 10:31:31.000 0xBEC4CB23E7994CFF1E71403F906BB1EFFDDEAF9A NULL


DROP CERTIFICATE cert_xp_cmdshell_enabler


he certificate cannot be dropped because one or more entities are either signed or encrypted using it.


Is there any way I can drop this as I would like to recreated it and add a whole host of sps that I need to use the xp_cmdshell.


Thanks in advance.







View 4 Replies View Related







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