Thursday, May 10, 2018

How to set SQL Server database Online/Offline

Database is made offline to move its physical files. There can be many ways to make a database offline. But there are three main methods which are used frequently to make the database offline. These methods are given below:-
1) With the help of Alter database Command
We can make the database offline or online with the help of the Alter database command. The Alter Database command to make the database offline is:
ALTER DATABASE database name SET Offline
If we want to make the database online we can use the following Alter Database command:
ALTER DATABASE database name SET Online
2) With the help of the Db_options
We can also use the db_options command to make a database offline or online.To make a database offline we can use the following command:
sp_dboption databasename ,'offline',true
To make the database online we can use the following command:
sp_dboption databasename ,'offline',false
3) With the help of Sql server management studio
We can also use the Sql server management studio to make a database offline / online.

Tuesday, April 10, 2018

SQL Server - Find table in multiple databases

To find a table in one specific database run the following query.

SELECT *
FROM sys.Tables
WHERE name LIKE '%Address%'
To search through multiple databases query can be enhanced as follows.

DECLARE @TableName VARCHAR(256)
DECLARE @DBName VARCHAR(256)
DECLARE @varSQL VARCHAR(512)

SET @TableName = 'Address'
DECLARE @getDBName CURSOR
SET @getDBName = CURSOR FOR
SELECT name
FROM sys.databases
CREATE TABLE #TmpTable (DBName VARCHAR(256),
SchemaName VARCHAR(256),
TableName VARCHAR(256))
OPEN @getDBName
FETCH NEXT
FROM @getDBName INTO @DBName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @varSQL = 'USE ' + @DBName + ';
INSERT INTO #TmpTable
SELECT '''+ @DBName + ''' AS DBName,
SCHEMA_NAME(schema_id) AS SchemaName,
name AS TableName
FROM sys.tables
WHERE name LIKE ''%' + @TableName + '%'''
EXEC (@varSQL)
FETCH NEXT
FROM @getDBName INTO @DBName
END
CLOSE @getDBName
DEALLOCATE @getDBName
SELECT *
FROM #TmpTable
DROP TABLE #TmpTable

Wednesday, April 4, 2018

List of Microsoft Windows key codes


Comparing date objects in Javascript

The Date object will do what you want - construct one for each date, then compare them using the ><<= or >=.
The ==!====, and !== operators require you to use date.getTime() as in
var d1 = new Date();
var d2 = new Date(d1);
var same = d1.getTime() === d2.getTime();
var notSame = d1.getTime() !== d2.getTime();
to be clear just checking for equality directly with the data objects won't work
var d1 = new Date();
var d2 = new Date(d1);

console.log(d1 == d2);   // prints false (wrong!) 
console.log(d1 === d2);  // prints false (wrong!)
console.log(d1 != d2);   // prints true  (wrong!)
console.log(d1 !== d2);  // prints true  (wrong!)
console.log(d1.getTime() === d2.getTime()); // prints true (correct)