For validating mdf files

The scenario assumes that the Adventure Works sample database has been attached.SQL Server sample databases can be found on codeplex.

So let's work through an example scenario to illustrate.

While the code within this tip was developed and tested against a SQL Server 2005 instance, it should function on any version currently in use.

Questions on Stack Overflow are expected to relate to programming within the scope defined by the community.

Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. SQL Server databases use two files - an MDF file, known as the primary database file, which contains the schema and data, and a LDF file, which contains the logs. A database may also use secondary database file, which normally uses a extension. indicates, these file extensions are purely convention - you can use whatever you want, although I can't think of a good reason to do that.

USE [master] GO SELECT DB_NAME([database_id]) [database_name] , [file_id] , [type_desc] [file_type] , [name] [logical_name] , [physical_name]FROM sys.[master_files]WHERE [database_id] IN (DB_ID('Adventure Works'), DB_ID('Adventure Works Copy'))ORDER BY [type], DB_NAME([database_id]); Msg 1834, Level 16, State 1, Line 1The file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Adventure Works_Data.mdf' cannot be overwritten. Msg 3156, Level 16, State 4, Line 1File 'Adventure Works_Data' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Adventure Works_Data.mdf'.

Use WITH MOVE to identify a valid location for the file.

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Sign up to join this community (Incidentally why is the size in the info bar at the bottom of the windows explorer screen vastly different to the 'size' column information? There is no corresponding database by that name (xxx).

Processed 1 pages for database 'Adventure Works Copy', file 'Adventure Works_Log' on file 1.

Tags: , ,