Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Friday, May 8, 2020

SQl Database Cache Cleanup

Sometimes we have some issues because of SQL server database cache on measuring query performance, when we comparing the execution time of two different queries, it’s important to clear the cache of database to confirm the execution of the first query does not affect the performance of the second query

Here is the query to get the list of database with their cache size

SELECT  COUNT(*) * 8 / 1024 AS 'Cached Size (MB)' ,
        CASE database_id
          WHEN 32767 THEN 'ObjectDb'
          ELSE DB_NAME(database_id)
        END AS 'Database'
FROM    sys.dm_os_buffer_descriptors
GROUP BY DB_NAME(database_id) ,
        database_id
ORDER BY 'Cached Size (MB)' DESC;

Result will be like below



We can use below commands to check Resource pool and cached memory size

SELECT name AS 'Pool Name',
       cache_memory_kb / 1024.0 AS [cache_memory_MB],
       used_memory_kb / 1024.0 AS [used_memory_MB]
FROM sys.dm_resource_governor_resource_pools;


We can use below query to clear cache of all databases or any specific one

GO
DBCC FREEPROCCACHE /* Clear the entire plan cache for a SQL Server instance. */
GO
DBCC DROPCLEANBUFFERS  /* Removes all clean buffers from the buffer pool */
GO
DBCC FREESYSTEMCACHE ('All') /* Clear all unused cache entries from all caches, we can use specifc Resource Pool Name instead of 'All' */
GO
DBCC FREESESSIONCACHE /*Clear the distributed query connection cache */


If we wish to clear plan cache for any specific database, then we can use 

/* Clear the plan cache for a specific Database. */
DBCC FLUSHPROCINDB (DatabaseID) GO

We can get databse Id using 

SELECT db_ID()

For specific objects like stored procedure, trigger, table, view, function in the current database, we can use

EXEC sp_recompile N'[ procedure name, trigger, table, view]';

Below are some more use of FREESYSTEMCACHE

/* Clear the ad hoc and prepared plan cache for the entire instance. */
DBCC FREESYSTEMCACHE ('SQL Plans')

/* Clear all cached table variables and temp tables. */
DBCC FREESYSTEMCACHE ('Temporary Tables & Table Variables')

/* Clear for a specific user database. */
DBCC FREESYSTEMCACHE ('userdatabase')

Monday, July 29, 2019

Interview Questions 4+

4 + Years
---------

1. What is CDN
2. What is diamonds issue in asp. Net
3. What data contract in WCF
4. What is important components in WCF
5. Can we call WCF from angular
6. What rest call
7. How to extend the view
8. ACID Property in SQL

C#

1. Why we can't implement multiple inheritance using a class?
2. What is generic and what benefits?
3. What is delegate and its types?
4. What are SOLID principles?
5. Know any Design Patterns?
6. What is extension Methods? Have you created any?
7. What is Dependency Injection? How many ways to implement it?
8. Difference between encapsulation and Abstraction
9. Difference between var and dynamic
10. Difference between read-only and const
11. Difference between ref and out parameter?
12. What are collections?
12. What is constructor chaining?
13. What is default constructor? Can I make database call from constructor?
14. What is private constructor?
15. How to call base class constructor from drived class?
16. How can we update private variable outside a class?
17. Difference between IEnumerable and List? 
Ans. IEnumerable is readonly
18. What is difference between IEnumerable and IQueryable? 
Ans. IEnumerable executes in memory i.e. load all records and then apply filter. IQueryable will execute in database directly.

Web Forms

1. In which event of page cycle is the ViewState available?
2. Difference between Server.Transfer and Response.Redirect
3. What is ViewState? How long the items in ViewState exists?
4. Different Session state management options available in ASP.NET
5. Web application running without web.Config file?
6. Boxing and Unboxing?
7. File extension of web service? Ans. .asmx
8. Components of ADO.NET? Ans. Dataset, Data Reader, Data Adaptor, Command, connection
9. Difference between ExecuteScalar and ExecuteNonQuery? Ans. ExecuteScalar returns output and ExecuteNonQuery returns number of rows affected by the query.
10. 

MVC

1. Page life cycle
2. How to authenticate and authorize?
2. How many Filters? How to implement Filters?
5. What is action result and how many types?
5. A form and a submit button. How to prevent form submit?
6. What is difference between authentication and authorization?
7. What is Model binding?
8. How to do model validations?
9. What global.asax file does?
10. Can we have project without web.config?
11. What are Action filters


Web Api

1. Which protocol it works on?
2. What are Http verbs and which verb used for what purpose?
3. How to use multiple Get and multiple Post methods in a controller?
4. How many types of routings? Which you used?
5. How to enable CORS?
6. How to do api versioning?


Javascript

1. It is multi threaded?
2. What are selectors?
3. What is promise?
4. Can we implement async await ?
5. What is fat arrow function?
6. What is spread operator?
7. What is pure function?
7. Ajax?

Sqlserver

1. Why we use view?
2. Difference between View and SP?
3. Difference between varchar and nvarchar?
3. Types of indexing ? Difference between clustered and non-clustered indexing?
4. Order of fields in non-clustered indexing matters?
4. Why SP execute faster? Can a SP have multiple execution plan?
5. Ever done performance optimization?
6. What are triggers and its types
7. When to use CTE?
8. When to use Cursor?
9. Nested transaction rollback tricky questions
10. Different Types of Locks and their use in SQL
11. Recursive Stored Procedures
12. Magic Table in SQL
13. Basic Types of Joins in SQL (HASH, MERGE and LOOP)



AngularJS

1. Can we have multiple ng-app in a application?
2. If controller function gets called multiple times what can  be possible issue?
3. What is the use of 'track by' in ng-repeat?
4. What is isolated scope?
5. How is scope in directive different from scope in controller?
6. What is the difference between compile and link?
7. Can parent controller access the methods of child controller or vice versa?
8. Difference between broadcast and emit?

Angular

1. How do Observables differ from Promises?
2. How typescript converted to javascript?
3. What is compilation in Angular? And what are the types of compilation in Angular?
4. types of Directives? 
    Ans: They are attribute directives, structural directives, and components.
5. What types of form you have used?
6. Have you used angular universal SSR?

NodeJS

1. How to create server?
2. What is middleware?
3. What you use for state management?
4. What you use to work with mongodb?
5. How can we do encrupt/ decrypt?
6. How to enable CORS in node server?
   A:   const app = express()
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Methods", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
  next();
});
7. How to declare environment variables?
8. What you use for file upload?
   A: multer
9. What is an error-first callback?
10. How to avoid callback hells? 
    A: modularization, control flow libraries, generators with promises, async/await

ReactJS

1. WHere does react rendering starts?
2. How we render a DOM?
   A. ReactDOM.render( )
3. How can we call API?
4. What we use for state management?
5. What is action, reducer and store in react-redux?
6. What is difference between 'export' and 'export default'?
7. Do you know react native also?

IONIC

1. What is IONIC?
2. Explain Ionic lifecycle hooks?
3. What is the difference between PhoneGap, Cordova, and Ionic?
4. What is 'collection-repeat' directive in IONIC?
    A. Renders only visible items in the DOM. Only items visible in a viewport are rendered.
5. How to access camera in ionic?
    A. ionic cordova plugin add cordova-plugin-camera
       npm install @ionic-native/camera
6. How to browse file in ionic?
    A. ionic cordova plugin add cordova-plugin-filechooser
       npm install @ionic-native/file-chooser

Typescript

1. How do you compile TypeScript files?
    A. tsc helloworld.ts
2. Does TypeScript support all object oriented principles?
    A. Yes
3. What are modules in TypeScript?
    A. Modules are the way to organize code in TypeScript.
4. Can we create generic class in typescript?
5. Explain Relative vs. Non-relative module imports.

Configure Console Application as Windows Service

  To configure a  console application  as a  Windows Service , you'll need to follow several steps, which typically involve writing a se...