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.
I have come across the same problem many times and thought I should share my solution (notwithstanding the already provided answers):

So I have two SQL instances (SQL 2008 and SQL 2017). The error does Not manifest in my SQL08 Instance but on SQl17. This is caused by the "account Credentials" provided during Installation/setup of each SQL instance:

[![enter image description here](https://i.stack.imgur.com/ld3f7.jpg)](https://i.stack.imgur.com/ld3f7.jpg)

This can be seen under Windows Services. The SQL08 was set to use the "Local System Account" whilst the failing SQL17 was set to "NETWORK ACCOUNT" during setup.
So just change that and restart the SQL service here (or restart instance in SQL browser).

The second part to this problem is unique to SQL Server 2017 CTP 2.0 when using SQL Server Management Studio V17 in which case the SMO switched to using "*sys.dm\_os\_enumerate\_fixed\_drives*" instead of the old "*xp\_fixeddrives*" to get free space information of your local disk.
To workaround this, go to the DEVICE MANAGER and temporarily disable the cited drive (in my case was drive "G" which is just my DVD-ROM drive).