Showing posts with label old. Show all posts
Showing posts with label old. Show all posts

Tuesday, March 27, 2012

Dropping an old foreign key restraint?

This forum looked like the only one where I may get an answer to this question.

I built a database with a set of tables in Sql Server 2005 sp2.

I later had to refactor the data which led to removing one table, renaming another table, and moving some data around.

Now when I attempt to write my test code and execute my initialization logic (which clears data out of the tables) I get a foreign key restraint error when trying to delete one of my records. However the FK restraint is an old one that refers to a table that no longer exists. I have looked at all of my tables in the current design and the constraint referenced in the exception does not show up on any of the tables.

How things changed: I had DesktopItems tie to a DataEntry table with a foreign key constraint. I now have DesktopItems point to WorkItem ( the orgininal table renamed ) and it is on the delete of items from DesktopItems that I get the old FK constraint. The really odd part about this is if I go into the table and manually delete the record, I do NOT get the constraint error!!!

In the database that I'm getting the error, I implemented the changes by deleting all tables and SPROCS and then executing scripts to rebuild the new design.

Is there a system SPROC that I can execute to show and delete this item?

Dear Michael,

Try this code:

IF EXISTS (SELECT * from sysconstraints WHERE constid = OBJECT_ID (N'[FK_DesktopItems_TO_DataEntry]'))
IF OBJECT_ID (N'[DesktopItems]') IS NOT NULL
EXEC ('ALTER TABLE [DesktopItems] DROP CONSTRAINT FK_DesktopItems_TO_DataEntry')

HTH,

Suprotim Agarwal

Dropping an old foreign key restraint?

This forum looked like the only one where I may get an answer to this question.

I built a database with a set of tables in Sql Server 2005 sp2.

I later had to refactor the data which led to removing one table, renaming another table, and moving some data around.

Now when I attempt to write my test code and execute my initialization logic (which clears data out of the tables) I get a foreign key restraint error when trying to delete one of my records. However the FK restraint is an old one that refers to a table that no longer exists. I have looked at all of my tables in the current design and the constraint referenced in the exception does not show up on any of the tables.

How things changed: I had DesktopItems tie to a DataEntry table with a foreign key constraint. I now have DesktopItems point to WorkItem ( the orgininal table renamed ) and it is on the delete of items from DesktopItems that I get the old FK constraint. The really odd part about this is if I go into the table and manually delete the record, I do NOT get the constraint error!!!

In the database that I'm getting the error, I implemented the changes by deleting all tables and SPROCS and then executing scripts to rebuild the new design.

Is there a system SPROC that I can execute to show and delete this item?

Dear Michael,

Try this code:

IF EXISTS (SELECT * from sysconstraints WHERE constid = OBJECT_ID (N'[FK_DesktopItems_TO_DataEntry]'))
IF OBJECT_ID (N'[DesktopItems]') IS NOT NULL
EXEC ('ALTER TABLE [DesktopItems] DROP CONSTRAINT FK_DesktopItems_TO_DataEntry')

HTH,

Suprotim Agarwal

Wednesday, March 21, 2012

DROP TABLE BY MISTAKE

I have just dropped a table in Sql Server By mistake
Is there a way to tr retieve this without pulling up an old backup?
TIA
None that I can think of.
Your backup is probably the best bet.
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:O7EE91v1EHA.3408@.tk2msftngp13.phx.gbl...
> I have just dropped a table in Sql Server By mistake
> Is there a way to tr retieve this without pulling up an old backup?
> TIA
>
|||http://www.aspfaq.com/2449
http://www.aspfaq.com/
(Reverse address to reply.)
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:O7EE91v1EHA.3408@.tk2msftngp13.phx.gbl...
> I have just dropped a table in Sql Server By mistake
> Is there a way to tr retieve this without pulling up an old backup?
> TIA
>

DROP TABLE BY MISTAKE

I have just dropped a table in Sql Server By mistake
Is there a way to tr retieve this without pulling up an old backup?
TIANone that I can think of.
Your backup is probably the best bet.
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:O7EE91v1EHA.3408@.tk2msftngp13.phx.gbl...
> I have just dropped a table in Sql Server By mistake
> Is there a way to tr retieve this without pulling up an old backup?
> TIA
>|||http://www.aspfaq.com/2449
http://www.aspfaq.com/
(Reverse address to reply.)
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:O7EE91v1EHA.3408@.tk2msftngp13.phx.gbl...
> I have just dropped a table in Sql Server By mistake
> Is there a way to tr retieve this without pulling up an old backup?
> TIA
>

DROP TABLE BY MISTAKE

I have just dropped a table in Sql Server By mistake
Is there a way to tr retieve this without pulling up an old backup?
TIANone that I can think of.
Your backup is probably the best bet.
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:O7EE91v1EHA.3408@.tk2msftngp13.phx.gbl...
> I have just dropped a table in Sql Server By mistake
> Is there a way to tr retieve this without pulling up an old backup?
> TIA
>|||http://www.aspfaq.com/2449
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:O7EE91v1EHA.3408@.tk2msftngp13.phx.gbl...
> I have just dropped a table in Sql Server By mistake
> Is there a way to tr retieve this without pulling up an old backup?
> TIA
>

Sunday, February 26, 2012

Drop a Database

We are running SQL Server 2000 with SP3.
We would like to remove an old database which is not used
anymore.
I intend to do
1) Delete DB in Enterprise Manager
2) Remove Server Login for that particular database in
Enterprise Manager
Is there any step missed ?
ThanksHi,
You can just delete it . also if u don't want amy roles or logins u can
delete it also
--
Shaju Thomas
"Roger Lee" <anonymous@.discussions.microsoft.com> wrote in message
news:037d01c39c3f$10375400$a601280a@.phx.gbl...
> We are running SQL Server 2000 with SP3.
> We would like to remove an old database which is not used
> anymore.
> I intend to do
> 1) Delete DB in Enterprise Manager
> 2) Remove Server Login for that particular database in
> Enterprise Manager
> Is there any step missed ?
> Thanks
>|||Roles are inside the database, no need to delete any roles. (As you can't create any server
roles...)
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Shaju" <answer@.hotmail.com> wrote in message news:uzHpoSEnDHA.3288@.tk2msftngp13.phx.gbl...
> Hi,
> You can just delete it . also if u don't want amy roles or logins u can
> delete it also
> --
> Shaju Thomas
> "Roger Lee" <anonymous@.discussions.microsoft.com> wrote in message
> news:037d01c39c3f$10375400$a601280a@.phx.gbl...
> > We are running SQL Server 2000 with SP3.
> >
> > We would like to remove an old database which is not used
> > anymore.
> >
> > I intend to do
> > 1) Delete DB in Enterprise Manager
> > 2) Remove Server Login for that particular database in
> > Enterprise Manager
> >
> > Is there any step missed ?
> >
> > Thanks
> >
> >
>|||Roger,
watch out DTS packages and jobs referencing the db. They are outside the
db.
Quentin
"Roger Lee" <anonymous@.discussions.microsoft.com> wrote in message
news:037d01c39c3f$10375400$a601280a@.phx.gbl...
> We are running SQL Server 2000 with SP3.
> We would like to remove an old database which is not used
> anymore.
> I intend to do
> 1) Delete DB in Enterprise Manager
> 2) Remove Server Login for that particular database in
> Enterprise Manager
> Is there any step missed ?
> Thanks
>

drop / create new database with old name

Hi,
Is it possible to drop and then create a new, fresh
database with the same name as the database just dropped
or would this cause problems? I don't want to recreate
this database from backups as there are concerns.
Thanks,
Diana
That should cause no problems... is there some reason you would expect it
to?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"DianaR" <anonymous@.discussions.microsoft.com> wrote in message
news:0b7f01c51837$db2c5230$a401280a@.phx.gbl...
> Hi,
> Is it possible to drop and then create a new, fresh
> database with the same name as the database just dropped
> or would this cause problems? I don't want to recreate
> this database from backups as there are concerns.
> Thanks,
> Diana
|||Hi Adam,
No, no reason... just wanted to make sure.
Thanks for your reply.
Diana

>--Original Message--
>That should cause no problems... is there some reason
you would expect it
>to?
>
>--
>Adam Machanic
>SQL Server MVP
>http://www.sqljunkies.com/weblog/amachanic
>--
>
>"DianaR" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:0b7f01c51837$db2c5230$a401280a@.phx.gbl...
dropped
>
>.
>

drop / create new database with old name

Hi,
Is it possible to drop and then create a new, fresh
database with the same name as the database just dropped
or would this cause problems? I don't want to recreate
this database from backups as there are concerns.
Thanks,
DianaThat should cause no problems... is there some reason you would expect it
to?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"DianaR" <anonymous@.discussions.microsoft.com> wrote in message
news:0b7f01c51837$db2c5230$a401280a@.phx.gbl...
> Hi,
> Is it possible to drop and then create a new, fresh
> database with the same name as the database just dropped
> or would this cause problems? I don't want to recreate
> this database from backups as there are concerns.
> Thanks,
> Diana|||Hi Adam,
No, no reason... just wanted to make sure.
Thanks for your reply.
Diana

>--Original Message--
>That should cause no problems... is there some reason
you would expect it
>to?
>
>--
>Adam Machanic
>SQL Server MVP
>http://www.sqljunkies.com/weblog/amachanic
>--
>
>"DianaR" <anonymous@.discussions.microsoft.com> wrote in
message
>news:0b7f01c51837$db2c5230$a401280a@.phx.gbl...
dropped[vbcol=seagreen]
>
>.
>

drop / create new database with old name

Hi,
Is it possible to drop and then create a new, fresh
database with the same name as the database just dropped
or would this cause problems? I don't want to recreate
this database from backups as there are concerns.
Thanks,
DianaThe only problem I can think of is to do with the table
sysdatabases in the master database.
If you refer to the database by its dbid anywhere then
there is a good chance it might change when you re-create
it.
Peter
"The best minds are not in government. If any were,
business would steal them away."
Ronald Reagan
>--Original Message--
>Hi,
>Is it possible to drop and then create a new, fresh
>database with the same name as the database just dropped
>or would this cause problems? I don't want to recreate
>this database from backups as there are concerns.
>Thanks,
>Diana
>.
>|||That should cause no problems... is there some reason you would expect it
to?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"DianaR" <anonymous@.discussions.microsoft.com> wrote in message
news:0b7f01c51837$db2c5230$a401280a@.phx.gbl...
> Hi,
> Is it possible to drop and then create a new, fresh
> database with the same name as the database just dropped
> or would this cause problems? I don't want to recreate
> this database from backups as there are concerns.
> Thanks,
> Diana|||Hi Adam,
No, no reason... just wanted to make sure.
Thanks for your reply.
Diana
>--Original Message--
>That should cause no problems... is there some reason
you would expect it
>to?
>
>--
>Adam Machanic
>SQL Server MVP
>http://www.sqljunkies.com/weblog/amachanic
>--
>
>"DianaR" <anonymous@.discussions.microsoft.com> wrote in
message
>news:0b7f01c51837$db2c5230$a401280a@.phx.gbl...
>> Hi,
>> Is it possible to drop and then create a new, fresh
>> database with the same name as the database just
dropped
>> or would this cause problems? I don't want to recreate
>> this database from backups as there are concerns.
>> Thanks,
>> Diana
>
>.
>