Best way to build LDF   Leave a comment

Generally, when the log file size become very huge and even after shrinking the same still we face file size issue in that case we take an action to regenerate the new LDF file for our database. There are different ways to achieve the same, but the best way to achieve it is as follow:

  1. use sp_helpdb yourdbname and note down the path where .mdf and .ldf files are stored.
  2. execute the sp_detach_dp yourdbname command to detach the database Syntax
    sp_detach_db [ @dbname = ] 'dbname' 
                 [ , [ @skipchecks = ] 'skipchecks' ]


    EXEC sp_detach_db 'youdbname', 'false'
  3. Move the original database files to some other location or rename them.
  4. Create database with same name using CREATE DATABASE yourdbname command.
  5. Stop SQL server and replace the .mdf file.
  6. Start SQL server.
  7. Database will be shown in pending recovery mode.
  8. Issue below list of commands to bring the database online

Use Master


Alter Database yourdbname Set Emergency


Alter Database yourdbname Set Single_User


DBCC CheckDB(yourdbname, Repair_Allow_Data_Loss)


Alter Database yourdbname Set Multi_User


Alter Database yourdbname Set Online



Note*: You will receive error messages but database will be online.



Posted March 13, 2018 by Izharuddin Shaikh in SQL

Tagged with

Data types   Leave a comment

Data Types:

String, Boolean, Null, Object, Integer, Double, Min/Max Keys, Arrays, TimeStamps, Symbol, Date, Binary Data, ObjectID, RegularExpression etc.

Posted March 11, 2018 by Izharuddin Shaikh in MongoDB

Tagged with

Aggregate Functions   Leave a comment

Below are the aggregate functions:









Posted March 11, 2018 by Izharuddin Shaikh in MongoDB

Tagged with

Useful Functions   Leave a comment

Below are some of the useful functions

Limit(n): To limit the number of records.

Skip(n): Skip the number of records.

Sort({key:1}): Sort the data.

ensureIndex(): To create index.


Posted March 11, 2018 by Izharuddin Shaikh in MongoDB

Tagged with

Collection   Leave a comment

Collection is similar to table.

Below are some basic commands for collection related operations:

db.createCollection(“name”): Create the collection.

db.collectionname.insert(“”): Insert the data in collection.

db.collectionname.drop(): Drop the collection.

db.collectionname.find(): Search the record in collection.

db.collectionname.findone(): Top one in collection.

db.collectionname.find().pretty(): Return the formatted data.

show collections: Return all the collections.

db.collectionname.remove(criteria, 1): Delete record. Replace the data.

db.collectionname.update(): Update data.




Posted March 11, 2018 by Izharuddin Shaikh in MongoDB

Tagged with

Create / Drop Database Commands   Leave a comment

  1. MongoDB use DATABASE_NAME is used to create database. The command will create a new database if it doesn’t exist, otherwise it will return the existing database.   Example: use DATABASE_NAME
  2. To drop the database use db.dropDatabase() command. Make sure you have selected correct database using use Database_Name command.

Posted March 10, 2018 by Izharuddin Shaikh in MongoDB

Tagged with ,

MongoDB Basic   Leave a comment

MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.


Database is a physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.

In case of Mongo DB also database is like any other database.


Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields.


A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.


In MongoDB, Primary Key is a Default key _id provided by mongodb itself.

For example:

   _id: ObjectId(7df78ad8902c)
   title: 'MongoDB Basic', 
   description: 'MongoDB is no sql database',
   tags: ['mongodb', 'database', 'NoSQL'],
where _id is 12 bytes key which help to maintain the uniqueness.

Advantages of MongoDB over RDBMS

  • Schema less
  • Structure of a single object is clear.
  • No complex joins.
  • Deep query-ability.
  • Tuning.
  • MongoDB is easy to scale.
  • Uses internal memory for storing the working set, enabling faster access of data.
Why to use MongoDB?
Here are some features which will help to understand when to use it and why to use
  • Document Oriented Storage − Data is stored in the form of JSON style documents.
  • Index on any attribute
  • Replication and high availability
  • Auto-sharding
  • Rich queries
  • Fast in-place updates
  • Professional support by MongoDB

Posted March 10, 2018 by Izharuddin Shaikh in MongoDB

Tagged with

%d bloggers like this: