Showing posts with label attach. Show all posts
Showing posts with label attach. Show all posts

Wednesday, March 7, 2012

database detach/attach

An original database (eg A.mdf) is imported/exported to a different server as named B.mdf. The detach of A.mdf was unitentionally not done. It seems that both the database were updated.

A.mdf - 123000KB 25/12/2003
A_log.ldf - 14000KB 25/12/2003
B.mdf - 67000KB 25/12/2003
B_log.ldf - 1024KB 25/12/2003

In this case, which mdf & ldf should be the correct database?
If I I remove A.mdf database by "detach", will B.mdf database work?

SQL server 2000 and SP3 installed.

Assistance is appreciatedyou are exporting a database file and getting different sizes .. seems strange

sp_helpdb 'database_name'

on both servers

Copy and paste results over here

That might help|||The original database (eg A.mdf) is export/imported into a different server and the database is named as B.mdf. The 'detach' command from of the original database (A.mdf) was unintentionally
not done. As I have unintentionally did not do a 'detach' of the old database, both the database seems to be updated (as indicated from the date stamp) AFTER I use the application (VB6 business application) a day or two.

Once an import/export is done, is the detach of the old database compulsory?. In SQL Server Enterprise Manager->(Select say, A database)->All Task-> Detach database

A.mdf - 123,000KB, 2/1/2004 1142am
A_log.ldf - 10,000 KB, 2/1/2004 0133pm
B.mdf - 67,000KB, 2/1/2004 0902am
B_log.ldf - 1024KB, 2/1/2004 0902am

Exporting of the database is ok before the I started using the application.

How can I correct this? Advise is appreciated.

Regards,
Brian

Originally posted by Enigma
you are exporting a database file and getting different sizes .. seems strange

sp_helpdb 'database_name'

on both servers

Copy and paste results over here

That might help|||Are both databases supposed to be active - please describe more as to why you have 2 ? Where are you retrieving the database sizes ? Use sp_spaceused and post the results. Is the real question, what has changed between the 2 databases and how to find those records ?|||Originally posted by rnealejr
Are both databases supposed to be active - please describe more as to why you have 2 ? Where are you retrieving the database sizes ? Use sp_spaceused and post the results. Is the real question, what has changed between the 2 databases and how to find those records ?

the A.mdf and its log is the active database. 2 databases are active as 1 is live/production environment and the other is test/QA environment. the database sizes is seen from the window explorer.|||What needs to be corrected ? You keep mentioning detaching the A database - but why ? Is A production or test ? You need to run the stored procedure sp_spaceused to determine actual space used. Are you concerned that there might be activity on both databases - and you are not sure why ? Are you exporting the data from the production to the test periodically ? Since your log file for B does not appear to have grown, it appears that either minimal or no user activity is occuring on the B database (unless you are backing up the database/transaction log for B).|||Originally posted by rnealejr
What needs to be corrected ? You keep mentioning detaching the A database - but why ? Is A production or test ? You need to run the stored procedure sp_spaceused to determine actual space used. Are you concerned that there might be activity on both databases - and you are not sure why ? Are you exporting the data from the production to the test periodically ? Since your log file for B does not appear to have grown, it appears that either minimal or no user activity is occuring on the B database (unless you are backing up the database/transaction log for B).

if I were to remove (detach) the test/QA data (denotes by B.mdf and its log), will this cause any problem with production (denotes by A.mdf and its log) database?. I noted that the date/time has been updated on the same day even though my ODBC (live application) uses production database which is A.mdf.

What happen if a detach is not done after import/export from production to test/QA environment?. Do the production database get updated (by right it should since ODBC points to production) along with the test database?. I am concern that activities may be updated in the test environment - yes, I am not sure and I would like some feedback.|||There should be no connection between your A database and your B database (unless you have triggers/replication between the 2) - other than the fact that you exported the data from A to B. What method did you use to export the data from A to B ? Several activities can cause the date/time to change on B, but since the log is only 1 meg (the minimum) I would suspect that nothing has really changed on B. But if you are really concerned - dump the test database and copy the database from prod back to test.|||Originally posted by rnealejr
There should be no connection between your A database and your B database (unless you have triggers/replication between the 2) - other than the fact that you exported the data from A to B. What method did you use to export the data from A to B ? Several activities can cause the date/time to change on B, but since the log is only 1 meg (the minimum) I would suspect that nothing has really changed on B. But if you are really concerned - dump the test database and copy the database from prod back to test.

I agree with you. All I did was to simply import/export. no DTS used.
The strange thing I noted was that after the import/export from production to test (and no "detach" was done on test database), I ran the application and did the update. I found was that the test database time/date was updated AND the data went into production and the mdf and log of production did not change (seen from explorer).

Thanks for your feedback.|||It was probably just coincidence ... or a poltergeist (oooohhhhhh - supposed to be a spooky sound)

Friday, February 24, 2012

Database design need any critic/feedback

Hi,

I would like some critic or feedback on the attach database design.

The one that I am focusing on is : item_id in fr_item table.

I would like to have a central place where from the web it will have id that map to file, posting and map.

I have three tables fr_file, fr_post, fr_geo which map to fr_item.
My question is :
1. Is it good idea to have additional file_id, geo_id, post_id in fr_file, fr_post,fr_geo (as primary key) INSTEAD OF directly put item_id without file_id, geo_id or fr_file.

Thank you in advancesPlease explain more clearly, and the image you posted seems to have cut off one of the tables your refer to.

Are you familiar with the principles of data normalization? You should always start with these, and then break them only when necessary and with good reason.|||Thanks for feedback. I am familiar with data normalization. The table which is cut off is not that important in the question that I refering too.

Usually when I normalize table, it is a trade off, as you mention "to break them only if nescessary".
For example:
1. I have table fr_item and fr_item_cat.
fr_item_cat basically just taking the category out of fr_item, with reason
a. Performances. It is faster to select fr_item.item_cat_id with integer, instead of select comparing it with nvarchar.
b. Data Integrity

Here is another shot on the purpose. Let's say you want to make a site like "Flickr", instead of posting only picture, you are able to post videos, audios, etc. You are able to have comments, etc

Now the "fr_item" is the central id that refering to every things in the site. whether is videos, audios, comments, posting.(fr_item_cat can have value of "posting", "comment","file"). The reason why to choose this layout. It will enable a central id refering to others table.

Now the problems with this method,
a. every insert statement to other table like (for example: fr_file required an insert to fr_item).
b. every update to fr_file might also need to write sql statement update to fr_item.

hopefully, it is more clear

Tuesday, February 14, 2012

Database Corrupted, Need help recovering data from LDF file

A friend of mine called and said that his database was suspect and he detached it and was unable to attach it. The SQL Server Version is 2000 with the latest service packs installed. When I checked it the database (MDF) size was 1MB and the LDF size was 3.8 GB. I was not able to attach the two together and I was not able to attach the database using sp_attach_single_file_db. I did find an old backup of his database and attached that so he can work off of it but it is 1 yr old and he needs recent data. Since the MDF seemed to be blank we cant do much with that, but there seems to be data in the LDF. Is it possible to extract any data from the LDF file?

SunnyThe log file contains low level physical changes that are almost impossible to correlate with user objects without the metadata in the data files.

Database Corrupted, Need help recovering data from LDF file

A friend of mine called and said that his database was suspect and he detached it and was unable to attach it. The SQL Server Version is 2000 with the latest service packs installed. When I checked it the database (MDF) size was 1MB and the LDF size was 3.8 GB. I was not able to attach the two together and I was not able to attach the database using sp_attach_single_file_db. I did find an old backup of his database and attached that so he can work off of it but it is 1 yr old and he needs recent data. Since the MDF seemed to be blank we cant do much with that, but there seems to be data in the LDF. Is it possible to extract any data from the LDF file?

SunnyThe log file contains low level physical changes that are almost impossible to correlate with user objects without the metadata in the data files.

Database Corrupt: error 823

Hello there
After i tried to run DBCC CheckDb and it gave error, i has made to detach
the database.
When i tried to attach i got error 823: error (Bad page id).
What i can do now to fix the MDF file?You would want to restore from a backup. If you do not have a backup, the
following might help you recover what left of your data. Any doubt, contact
MS support.
1. make a backup of your *.mdf, *.ldf
2. set the db in emergency mode
exec sp_configure 'update','1'
reconfigure with override
go
update sysdatabases
set status=32768
where name='your_db'
go
--stop sqlserver
shutdown
--now restart sqlserver
go
3. rebuild log
dbcc rebuild_log('your_db','<fullpath_log_filename>')
go
4. attempt to fix with loss of data
exec sp_dboption 'your_db', 'single user', 'true'
dbcc checkdb('your_db',repair_allow_data_loss
)
go
5. reset db status
update sysdatabases
set status=0
where name='your_db'
go
6. turn off update
exec sp_configure 'update','0'
reconfigure with override
go
7. restart sqlserver
-oj
"Roy Goldhammer" <roy@.hotmail.com> wrote in message
news:u%23YeqpKiGHA.3496@.TK2MSFTNGP04.phx.gbl...
> Hello there
> After i tried to run DBCC CheckDb and it gave error, i has made to detach
> the database.
> When i tried to attach i got error 823: error (Bad page id).
> What i can do now to fix the MDF file?
>|||... and some additional thoughts about corrupt or suspect databases:
http://www.karaszi.com/SQLServer/in..._suspect_db.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"oj" <nospam_ojngo@.home.com> wrote in message news:OtA57zTiGHA.3848@.TK2MSFTNGP04.phx.gbl...

> You would want to restore from a backup. If you do not have a backup, the
> following might help you recover what left of your data. Any doubt, contac
t
> MS support.
> 1. make a backup of your *.mdf, *.ldf
> 2. set the db in emergency mode
> exec sp_configure 'update','1'
> reconfigure with override
> go
> update sysdatabases
> set status=32768
> where name='your_db'
> go
> --stop sqlserver
> shutdown
> --now restart sqlserver
> go
> 3. rebuild log
> dbcc rebuild_log('your_db','<fullpath_log_filename>')
> go
> 4. attempt to fix with loss of data
> exec sp_dboption 'your_db', 'single user', 'true'
> dbcc checkdb('your_db',repair_allow_data_loss
)
> go
> 5. reset db status
> update sysdatabases
> set status=0
> where name='your_db'
> go
> 6. turn off update
> exec sp_configure 'update','0'
> reconfigure with override
> go
> 7. restart sqlserver
>
>
> --
> -oj
>
> "Roy Goldhammer" <roy@.hotmail.com> wrote in message
> news:u%23YeqpKiGHA.3496@.TK2MSFTNGP04.phx.gbl...
>

database corrupt

What can I do if I failed to attach a database by EM?
If the database is corrupted, any method to recover the
database?
hi Tony,
"Tony" <anonymous@.discussions.microsoft.com> ha scritto nel messaggio
news:06b901c4a073$d7dd8a40$a401280a@.phx.gbl
> What can I do if I failed to attach a database by EM?
> If the database is corrupted, any method to recover the
> database?
if you have a clean backup, this usually is the best solution to go but, if
the database can be saved, perhaps the advices by Jasper as per
http://tinyurl.com/3pxhv can be helpfull
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.9.1 - DbaMgr ver 0.55.1
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||Hi,
What is the error you are getting while attaching?
Best option after a corrruption will be restoring from a good backup. If you
do not have the backup try below:-
1. Execute DBCC CHECKDB('db_name','REPAIR_REBUILD') , this will corrupt
minor issues.
If you do not have any options try with Jaspers suggestion
http://www.google.it/groups?q=+%22sp...ftngp09&rnum=1
Thanks
Hari
MCDBA
"Andrea Montanari" <andrea.sqlDMO@.virgilio.it> wrote in message
news:2re0b2F18k52cU1@.uni-berlin.de...
> hi Tony,
> "Tony" <anonymous@.discussions.microsoft.com> ha scritto nel messaggio
> news:06b901c4a073$d7dd8a40$a401280a@.phx.gbl
> if you have a clean backup, this usually is the best solution to go but,
> if
> the database can be saved, perhaps the advices by Jasper as per
> http://tinyurl.com/3pxhv can be helpfull
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
> http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
> DbaMgr2k ver 0.9.1 - DbaMgr ver 0.55.1
> (my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
> interface)
> -- remove DMO to reply
>