Loading...

Follow SQL Server DBA on Feedspot

Continue with Google
Continue with Facebook
or

Valid
SQL Server DBA by Jack Vamvas - 5d ago

Question: How can I DELETE using OPENQUERY?   Normally for a SELECT from OPENQUERY , I'll do something like :

SELECT col1 ,col2  FROM OPENQUERY (MY_LINKED_SERVER,'SELECT col1,col2  FROM MY_LINKED_TABLE') 

Can a similar method be used but for DELETE?

 

Answer: To use DELETE , it's a similar process to the SELECT but using the DELETE syntax. Taking the SELECT example above - you'll do the following. Note:this example will delete ALL the rows in the  linked server table .  :

DELETE FROM OPENQUERY (MY_LINKED_SERVER,'SELECT col1,col2  FROM MY_LINKED_TABLE')

 

Read more on OPENQUERY,Linked Servers and AS400

SQL Server – Datetime date range , AS400 and OPENQUERY (SQL ...

Connect SQL Servers without using Linked Servers

Import Data from AS400 to SQL Server

 

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Method 1 : Query sys.dm_os_windows 

 

SELECT windows_release, windows_service_pack_level, windows_sku, os_language_version  
FROM sys.dm_os_windows_info; 

Method 2 : Use xp_cmdshell - although this does mean enabling xp_cmdshell , which is in many organisations as security violation 

 

exec master..xp_cmdshell 'systeminfo'

 

Method 3: The @@version returns system and build information for the current SQL Server.

 

SELECT @@version

Method 4: xp_msver returns details about the actual build number of the server and information about the server environment.This can be very useful if you want to integrated as part of stored procedure, batch or other type of t-sql code. 

 

 xp_msver 

 

Sample output

1 ProductName NULL Microsoft SQL Server
2 ProductVersion 917504 14.0.3037.1
3 Language 1033 English (United States)
4 Platform NULL NT x64
5 Comments NULL SQL
6 CompanyName NULL Microsoft Corporation
7 FileDescription NULL SQL Server Windows NT - 64 Bit
8 FileVersion NULL 2017.0140.3037.01 ((SQLServer2017-CU10).180727-1609)
9 InternalName NULL SQLSERVR
10 LegalCopyright NULL Microsoft. All rights reserved.
11 LegalTrademarks NULL Microsoft SQL Server is a registered trademark of Microsoft Corporation.
12 OriginalFilename NULL SQLSERVR.EXE
13 PrivateBuild NULL NULL
14 SpecialBuild 199032833 NULL
15 WindowsVersion 199032833 6.3 (14393)
16 ProcessorCount 2 2
17 ProcessorActiveMask NULL 3
18 ProcessorType 8664 NULL
19 PhysicalMemory 5999 5999 (6290321408)
20 Product ID NULL NULL

 

Read More on other OS information methods

How to check Operating System type with Powershell (SQL Server ...

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Question: What are the powershell commands to create to ASSIGN a drive letter and then create a MOUNT POINT?

Answer: These powershell command  examples   will  assign a drive letter and then  create a mount point. You'll need to first know the Disk ID and also decide on the drive letter you need to assign 

If you want to create a mount point , then  use the MOUNT POINT section  

If the intention is to automate the assigning of drive letters to new partitions , and also dynamically identify the diskid than you'll need to  wrap some extra code around these steps to identify the diskid and also other parameter values, e.g Filesystem or AllocationUnitSize or PartitionStyle

 

=======ASSIGN DRIVE==========
$letterassign = "H"
$diskid = "4"
Get-Disk –Number $diskid | Initialize-Disk –PartitionStyle GPT
New-Partition -DiskNumber $diskid -Driveletter $letterassign -UseMaximumSize
Format-Volume -DriveLetter $letterassign -FileSystem NTFS -AllocationUnitSize 65536 –Confirm:$false

======MOUNT POINT=============
$diskid = "4"
Set-Disk -Number $diskid -IsReadOnly $false
Get-Disk –Number $diskid | Initialize-Disk –PartitionStyle GPT
New-Partition –DiskNumber $diskid –UseMaximumSize
Add-PartitionAccessPath -DiskNumber $diskid -PartitionNumber 2 –AccessPath "F:\mytest"
Get-Partition –Disknumber $diskid –PartitionNumber 2 | Format-Volume –FileSystem NTFS –NewFileSystemLabel MPData -AllocationUnitSize 65536 –Confirm:$false

 

 

 

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Question: What is the difference between High Availability (HA) and  Disaster Recovery (DR)? I often hear these terms being used interchangeably ,and would like to hear some specific definitions .

Answer:  High Availability  and Disaster Recovery  are often interchanged but there is a difference - and once we define the attributes of both High Availability and Disaster Recovery  , you can then use them accordingly.   

HA is a system feature , with an objective to achieve an agreed operational uptime for a higher than normal period

DR refers to procedures and policies to facilitate recovery of critical systems and infrastructure supporting those systems - in reaction to a disaster  . Typically a disaster is "declared" and the DR procedures are enforced.

Both DR and HA can be challenging, it is not always easy to foresee every situation. Organizations invest significant time and money into designing HA and DR systems - repeatedly simulating HA failover and DR scenarios.


SQL Server system redundancy and high availability       is all about identifying the HA stack such as physical locations, electricity, servers, database layer , then agreeing on the level of redundancy you want to build. The level of redundancy you is dependent on factors such as expertise, cost , and service level agreements .

Creating a Disaster Recovery Plan    requires analysis  of typical causes of downtime and then understanding the impact \ consequences of downtime on the organization.

 

 

 

 

 

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Question: I need a powershell script which reports on SQL Server logins with Sysadmin privileges. My aim is to automate the process - so if you could provide a script which provides the sql server name , login and that I can schedule.

 

Answer:  This powershell script will execute across a list of servers - as defined in the file associated with the $instancepath variable.Create a text file and place 1 or more sql server instances in the file e.g 

server1\instance1

server2\instance1

 

 

$isodate=Get-Date -format s 
$isodate=$isodate -replace(":","")
$basepath=(Get-Location -PSProvider FileSystem).ProviderPath


$instancepath=$basepath + "\config\instances_all.txt"
$outputfile="\logs\sql_servers_sysadmin_report" + $isodate + ".html"
$outputfilefull = $basepath + $outputfile

$filePath = ""


#invoke stylesheet
. .\modules\stylesheet.ps1




$dt = new-object "System.Data.DataTable"
foreach ($instance in get-content $instancepath)
{
$instance
$cn = new-object System.Data.SqlClient.SqlConnection "server=$instance;database=msdb;Integrated Security=sspi"
$cn.Open()
$sql = $cn.CreateCommand()
$sql.CommandText = "
SELECT 
@@servername,
mem.name [ID],
rol.[name] [Role]
FROM sys.server_role_members srm
INNER JOIN sys.server_principals rol ON rol.principal_id = srm.role_principal_id
INNER JOIN sys.server_principals mem ON mem.principal_id = srm.member_principal_id
WHERE rol.[name] = 'sysadmin'
GROUP BY mem.[name],rol.[name]
 "
    $rdr = $sql.ExecuteReader()
    $dt.Load($rdr)
    $cn.Close()
 
}

$dt | select * -ExcludeProperty RowError, RowState, HasErrors, Name, Table, ItemArray | ConvertTo-Html -head $reportstyle -body "SQL Servers sysadmin report"  | Set-Content $outputfilefull  



 

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Question: I was looking through Programs installed on a server with SQL Server installed and noticed Visual Studio components installed.

As part of a SQL Server installation , which parts of the  SQL Server install install the Visual Studio components?

 

Answer:   Since the 2016 version , SSMS is now based on the Visual Studio 2015 Shell. You could say SSMS is a Visual Studio Extension. The main reasoning , is the removal of dependency on installing .Net Framework 3.5  and some apparent performance improvements.

Note:SSMS is now a standalone installation

 

Useful reading on SSMS

How to start SSMS as Administrator (SQL Server DBA)

SQL server 2008 R2 – Silent installation for the SSMS and client tools

 

 

 

 

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Question: How can I find the SQL Server Instances on a server using Powershell ? Either the local server or remote SQL Servers.

The script should be based on  reporting the name after the MSSQL$   . For example , if the SQL Server Instance is called MSSQL$MYSERVER1  , than only MYSERVER1 should be returned

 

Answer: You can use this Powershell script as a basis to create a script . Place the  code in a powershell script file , and then execute 

.\Find_SQL_Server_Instances_on_server.ps1 -server MYSERVER1

 

param (
  
     [Parameter(Mandatory=$true)]
     [string]$server
         
)

$SERVER=$server

function getSQLInstanceOnServer ([string]$SERVER) {
    $services = Get-Service -Computer $SERVER
    $services = $services | ? DisplayName -like "SQL Server (*)"
        try {
        $instances = $services.Name | ForEach-Object {($_).Replace("MSSQL`$","")}
    }catch{
        # if no instances are found return 
        return -1
    }
    return $instances
}

getSQLInstanceOnServer $SERVER

 

You can also read these posts for some extra ways to enhance your Powershell scripts or as alternatives to the above . 

Powershell script - Get the SQL Server Instance status with Get-Service

List SQL Server Instances using Powershell and Get-ItemProperty

List SQL Server Instances with Powershell remote registry search

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 
SQL Server DBA by Jack Vamvas - 1M ago

Question: How can I DELETE using OPENQUERY?   Normally for a SELECT from OPENQUERY , I'll do something like :

SELECT col1 ,col2  FROM OPENQUERY (MY_LINKED_SERVER,'SELECT col1,col2  FROM MY_LINKED_TABLE') 

Can a similar method be used but for DELETE?

 

Answer: To use DELETE , it's a similar process to the SELECT but using the DELETE syntax. Taking the SELECT example above - you'll do the following. Note:this example will delete ALL the rows in the  linked server table .  :

DELETE FROM OPENQUERY (MY_LINKED_SERVER,'SELECT col1,col2  FROM MY_LINKED_TABLE')

 

Read more on OPENQUERY,Linked Servers and AS400

SQL Server – Datetime date range , AS400 and OPENQUERY (SQL ...

Connect SQL Servers without using Linked Servers

Import Data from AS400 to SQL Server

 

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Method 1 : Query sys.dm_os_windows 

 

SELECT windows_release, windows_service_pack_level, windows_sku, os_language_version  
FROM sys.dm_os_windows_info; 

Method 2 : Use xp_cmdshell - although this does mean enabling xp_cmdshell , which is in many organisations as security violation 

 

exec master..xp_cmdshell 'systeminfo'

 

Method 3: The @@version returns system and build information for the current SQL Server.

 

SELECT @@version

Method 4: xp_msver returns details about the actual build number of the server and information about the server environment.This can be very useful if you want to integrated as part of stored procedure, batch or other type of t-sql code. 

 

 xp_msver 

 

Sample output

1 ProductName NULL Microsoft SQL Server
2 ProductVersion 917504 14.0.3037.1
3 Language 1033 English (United States)
4 Platform NULL NT x64
5 Comments NULL SQL
6 CompanyName NULL Microsoft Corporation
7 FileDescription NULL SQL Server Windows NT - 64 Bit
8 FileVersion NULL 2017.0140.3037.01 ((SQLServer2017-CU10).180727-1609)
9 InternalName NULL SQLSERVR
10 LegalCopyright NULL Microsoft. All rights reserved.
11 LegalTrademarks NULL Microsoft SQL Server is a registered trademark of Microsoft Corporation.
12 OriginalFilename NULL SQLSERVR.EXE
13 PrivateBuild NULL NULL
14 SpecialBuild 199032833 NULL
15 WindowsVersion 199032833 6.3 (14393)
16 ProcessorCount 2 2
17 ProcessorActiveMask NULL 3
18 ProcessorType 8664 NULL
19 PhysicalMemory 5999 5999 (6290321408)
20 Product ID NULL NULL

 

Read More on other OS information methods

How to check Operating System type with Powershell (SQL Server ...

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Question: What are the powershell commands to create to ASSIGN a drive letter and then create a MOUNT POINT?

Answer: These powershell command  examples   will  assign a drive letter and then  create a mount point. You'll need to first know the Disk ID and also decide on the drive letter you need to assign 

If you want to create a mount point , then  use the MOUNT POINT section  

If the intention is to automate the assigning of drive letters to new partitions , and also dynamically identify the diskid than you'll need to  wrap some extra code around these steps to identify the diskid and also other parameter values, e.g Filesystem or AllocationUnitSize or PartitionStyle

 

=======ASSIGN DRIVE==========
$letterassign = "H"
$diskid = "4"
Get-Disk –Number $diskid | Initialize-Disk –PartitionStyle GPT
New-Partition -DiskNumber $diskid -Driveletter $letterassign -UseMaximumSize
Format-Volume -DriveLetter $letterassign -FileSystem NTFS -AllocationUnitSize 65536 –Confirm:$false

======MOUNT POINT=============
$diskid = "4"
Set-Disk -Number $diskid -IsReadOnly $false
Get-Disk –Number $diskid | Initialize-Disk –PartitionStyle GPT
New-Partition –DiskNumber $diskid –UseMaximumSize
Add-PartitionAccessPath -DiskNumber $diskid -PartitionNumber 2 –AccessPath "F:\mytest"
Get-Partition –Disknumber $diskid –PartitionNumber 2 | Format-Volume –FileSystem NTFS –NewFileSystemLabel MPData -AllocationUnitSize 65536 –Confirm:$false

 

 

 

Read Full Article

Read for later

Articles marked as Favorite are saved for later viewing.
close
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview