Question: I have one master and one detail table as following

```
Master:-
   BatchID
   BatchStatus
Detail
   DetailID
   BatchID
   DetailRecordStatus (Possible values 1,2,3)

```

I am trying to write a single a query that can update the Batch Status in Master based on `detailRecordStatus` values equal to 2 or 3

Answer: 
> 
> Every time I reboot windows, for some databases comes out this error. (OS Error 21 - Device not ready)
> 
> 
> 

This is due to a disk being offline or not being online either at the time SQL Server started, or had transitioned states after SQL Server has been online.

> 
> 3.If I restart SQL Server the errors disappears
> 
> 
> 

Yes, because the databases have been remounted inside of SQL Server. You could also offline->online the database as well and it would work, assuming the disk device has been fixed.

This can easily be reproduced in a test environment by putting a database on a disk, disabling the disk, running a select query (to get the error), bringing the disk back online and noticing that the select still fails with the same error. The database will need to be remounted in order to work again and not get OS Error 21.

What should you do?

Have someone do some windows tracing to figure out why it isn't coming online initially or why it is going offline (any state transition) or why it is showing ready to windows but really isn't (maybe other drivers need to be loaded for it).

Additionally check any disk filter drivers are up to date for things like anti-virus, host intrusion protections, etc., as those may also be blocking the service/startup/state.
These are my observations and how I solved the problem (for the benefit of others who may have the same problem)

* I was using amazon ec2 instance running Sql server.
* I had an EBS Block device attached to the ec2 instance, that mapped to the D: drive.
* My data and logs were in the D: drive.
* When I stop the ec2 instance and bring it up later, I always experienced the error of "device not ready" and the databases would not come up.
* I tried setting the MSSQLSERVER service with "Delayed startup".
* However, from the sql server logs I found that the delay was not honored and MSSQLSERVER started up right along with the boot.
* From the eventviewer I observed the time at which the D: drive becomes healthy.
* From the sql server logs, I noted the time at which SQL Server is starting up my user database.
* I observed that, D: drive is only available after 6 seconds later; and obviously the "Device not ready" error shows up.
* I also noted that that the "Delayed start" was not honored because there was another service named "SQL SERVER LaunchPad" which startups up "MSSQLSERVER".
* I don't need the Analytics capability of the "Launchpad". So I disabled that service.
* **Now "MSSQLSERVER" starts up with a delay and can find the D: drive files.**