using sys.dm_db_index_physical_stats

  • I've been researching the DMV 'sys.dm_db_index_physical_stats' over the past couple days, and in the process of trying to use it to capture data, I've come up with two questions that don't even specifically relate to it. I've been working with SQL Server in a professional environment for about a year now, but these are rather noob questions...please forgive me:

    1) I want to schedule this DMV to run as a job at a certain time. I want to capture the data returned in a table so i can refer back to it a t a later time. Is there a way to do this without having to create a table ahead of time, and define all of the columns appropriately? I.e, can I create a table on the fly that will capture all the data returned by the DMV?

    2) I've just started using MSDN alot, and I can't figure out why the letter 'N' gets passed to some funtions/DMVs, etc. For example, I can run this:

    SELECT OBJECT_ID('AdventureWorks.Production.WorkOrder')

    to return the object ID of the WorkOrder table, but on MSDN they show this:

    SELECT OBJECT_ID(N'AdventureWorks.Production.WorkOrder')

    what does the 'N' in front of the object parameter do?

    Thanks in advance!

  • SELECT *

    INTO NewTable

    From yourTable

    Will create a new table with all of the column definitions taken from the '*'. On the other hand it will not work if NewTable already exists.

    The "N" before a quoted string indicates that it is a NVarchar literal instead of just a Varchar literal.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Thanks!

  • Glad I could help.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply