2019 | VirtualSpecies

SQL Check Database Restore Start Date

We have seen the behavior in SSMS that nothing happen when we go to Tasks/Restore/Database. It means that the backup/restore history for the database is very long, and the wizard will take longer to come up since it reads the entire history first. We need to truncate the history. We can run the script below to determine the backup start date.

1
2
3
SELECT TOP 1 backup_start_date AS 'BackUp Start Date'
FROM msdb.dbo.backupset WITH (NOLOCK)
ORDER BY backup_set_id ASC

SQL Column Names From Table

Below is the effective query to get column names from a SQL table. We will use INFORMATION_SCHEMA to get the task done.

1
2
3
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'TableName'
In the alternate example below, we will use sys.columns to get the task done.

SQL Retrieve Email Domains

If we need to retrieve all the email domains from a SQL table, we can easily pull up result using below script. The SUBSTRING function is used to extract and display the part of a string. In this case, we have retrieved email domains after the @ symbol in each record.

1
2
3
SELECT DISTINCT 
SUBSTRING(Email, CHARINDEX('@',Email) + 1, LEN(Email) - CHARINDEX('@',Email)) 
FROM dbo.EmailRecord
Even better with the script below, we will be able to count how many of each domains are existed in the given table.

Essential Keyboard Functions

Keyboard functions have a great impact on our productivity, greatly speed up the outcome and save a whole lot of time. It also can reduce wrist strain. Remembering these functions can be overwhelming at first but you will get used to it. Below are some most frequently used keyboard functions_

KeyBoard on virtualspecies.com
_F1: It is help key. It is used to get help with the computer or with any software. It displays or hides the ribbon menu bar in Word and Excel.

How to Edit the Hosts File on Windows

In many cases, we will need to edit the hosts file on our machine. It is used to resolve hosts names before DNS. We can control access to websites and network traffic with this, in case of attack or any other reasons. Follow these simple steps to edit hosts file on your Windows machine_

_Open up the run command with the Win+R key combo.

_Press the Windows key and type Notepad in the search field.

_In the search results, right-click Notepad and select Run as administrator.

_From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts

How to Switch Terminal as Administrator on Mac

In many cases, we need to run Terminal as an administrator. To switch the user to root to be able to execute with high privileges as an admin, we can use following command instead of using sudo each time before each commands, and then provide the password on prompting. Once we do that, we will remain as an administrator.

$ sudo -i
The user will get admin privilege and remain root until the terminal is closed. If we don't want to close the terminal, we can execute exit command to change back to the normal user state.