About Me

My photo
Mumbai, Maharastra, India
He has more than 7.6 years of experience in the software development. He has spent most of the times in web/desktop application development. He has sound knowledge in various database concepts. You can reach him at viki.keshari@gmail.com https://www.linkedin.com/in/vikrammahapatra/ https://twitter.com/VikramMahapatra http://www.facebook.com/viki.keshari

Search This Blog

Sunday, December 14, 2014

The media set has 2 media families but only 1 are provided.



Msg 3132, Level 16, State 1, Line 1
The media set has 2 media families but only 1 are provided. All members must be provided.
Msg 3013, Level 16, State 1, Line 1
VERIFY DATABASE is terminating abnormally.

This is very common error, which generally comes with Restore and Backup. To dig into the problem lets stimulate this error.

Here I have a bakup file stored in D:\ drive, I want to use RESOTE common to verify the bak file.

RESTORE VERIFYONLY FROM
Disk ='C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER2014\MSSQL\Backup\TestDB.bak'

Msg 3132, Level 16, State 1, Line 1
The media set has 2 media families but only 1 are provided. All members must be provided.
Msg 3013, Level 16, State 1, Line 1
VERIFY DATABASE is terminating abnormally.

As I hit F5, I got this error, the error clearly specify, that the backup of the database wrote its data to two files, not one.   Therefore, you need both files in order to do a successful restore.

To locate the missing part you can use the following query.

SELECT b.physical_device_name
FROM msdb..backupmediaset a
INNER JOIN msdb..backupmediafamily b ON a.media_set_id = b.media_set_id
WHERE a.media_uuid = '<Media_UUID>'

Now Media_UUID you can get from

RESTORE LABELONLY FROM
disk = 'D:\SQL Server\myBakup.bak'

MediaName MediaSetId                          
----------------------------------------------
NULL      A335C850-4788-4A6B-BAE0-984AF5F4E6CC

Now here we have MediaSetId, we can use this mediaSetId to the above query to find the missing bak file location.

SELECT b.physical_device_name
FROM msdb..backupmediaset a
INNER JOIN msdb..backupmediafamily b ON a.media_set_id = b.media_set_id
WHERE a.media_uuid = 'A335C850-4788-4A6B-BAE0-984AF5F4E6CC''

physical_device_name
--------------------------------------------------------------------------------------
C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER2014\MSSQL\Backup\TestDB.bak
D:\SQL Server\myBakup.bak

So here we found that the bakup was splited into two different file.  Now we can use both the RESTORE Command to use both the

RESTORE VERIFYONLY FROM
disk = 'D:\SQL Server\myBakup.bak',
Disk ='C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER2014\MSSQL\Backup\TestDB.bak'

The backup set on file 1 is valid.

Conclusion: You can msdb..backupmediaset and msdb..backupmediafamily table to find the missing file location.

The only gears that loom in coders dream are their love to code. Love you dear SQL Server  :)


Post Reference: Vikram Aristocratic Elfin Share

Tuesday, December 9, 2014

Changing the color of status bar depending upon the server you are connected to


I remember last year, when I was sitting with my colleague, I saw something very interesting on his SSMS, when he was connecting to production environment, the status bar changes its color to red and when he was connecting to UAT, it gets converted to green.

I came to my n desk and google it out. I found it really a simple but great feature roll out by SSMS. These are such small feature that really makes our life more meaningful, colorful and simple.

Let me show you how we can change the color of status bar. When you try to connect to any database server, expand login screen by pressing OPTION button.


 Here for the 2014 server “ATOSHI\MSSQLSERVER2014”, we set the color to Red. Lets try to set the color of another server say “ATOSHI\SQLEXPRESS” to green.
 

Now since we have set one server to Red and another one to green, lets see whether it is reflecting on status bar.
First I am connecting to “ATOSHI\SQLEXPRESS” whose status bar we set to green.

 
That’s great, we can see status bar color changes to color Green, lets try to connect to server2014.


 Here we can see status bar color changes to color Red.

Conclusion: You can change the status bar color to the environment you are connected to.

The season of cold bring hotness, when you are with me SQL Server  :)


Post Reference: Vikram Aristocratic Elfin Share

Cannot create default constraint with sequence object on global temporary table


I was toying with SQL sequence object and all of sudden I was surprise to find that we cannot create default constraint with sequence object on Global temporary table. Let me demonstrate my finding with an example.

Here we are creating a global temporary table with two fields

create table ##temoAddSequence
(id int,
name varchar(20))
Command(s) completed successfully.

Lets insert few records in it.

insert into ##temoAddSequence values(2,'Amrapali')
insert into ##temoAddSequence values(5,'Mahin')

lets create a sequence object

create sequence seq_IdCounter
as int
       minvalue 1
       no maxvalue
       start with 4
       increment by 1
       ;
go
Command(s) completed successfully.

Lets try to associate this sequence object to Id column of ##temoAddSequence table

alter table ##temoAddSequence
add constraint id_default_sequence
default (next value for seq_Counter) for id;
Msg 208, Level 16, State 1, Line 19
Invalid object name 'seq_Counter'.

Conclusion: We cannot create default constraint with sequence object on Global temporary table.

When you are on my head SQL, I abscond from all tasks, to shower my love to you  :)


Post Reference: Vikram Aristocratic Elfin Share

Changing Column to use Default as sequence object


Here we are going to check, how we can create default constraint, as a sequence to an existing column on a table object. For our demonstration we are creating a small table with just two column id and name. ID is the field on which we will create default constraint later in this article.

create table tempAddSequence
(id int,
name varchar(20))
Command(s) completed successfully.

Lets insert few rows into tempAddSequence table object.

insert into tempAddSequence values(2,'Amrapali')
insert into tempAddSequence values(5,'Mahin')

select * from tempAddSequence
id          name
----------- --------------------
2           Amrapali
5           Mahin

(2 row(s) affected)

Now our table is populated with some rows, lets create a sequence object starts with 4 and increment by 1.

create sequence seq_Counter
as int
       minvalue 1
       no maxvalue
       start with 4
       increment by 1
       ;
go
Command(s) completed successfully.

Our Sequence object is ready to consume, its now turn to create default constraint on ID column of tempAddSequence table.

alter table tempAddSequence
add constraint id_default_sequence
default (next value for seq_Counter) for id;
Command(s) completed successfully.

Our Default constraint is now in place, associated with column ID. Now we are ready to insert few more records in tempAddSequence table, here won’t insert explicit value for Id field of table.

insert into tempAddSequence(name)
select 'Aashiyana' union all
select 'Anvi'
(2 row(s) affected)

Lets check out the insertion by querying the table

select * from tempAddSequence
id          name
----------- --------------------
2           Amrapali
5           Mahin
4           Aashiyana
5           Anvi

(4 row(s) affected)

Conclusion: we can create default constraint with sequence object on existing table with existing data.

Go Go, its your SQL soul calling :)
  
Post Reference: Vikram Aristocratic Elfin Share