Skip to main content


Showing posts with the label MSSQL

Temporal Tables in SQL Server 2016

Temporal, or system-versioned tables which was introduced in SQL Server 2016, allow us to go back in time and see what the data in table looked like at that point in time. We can say a system-versioned temporal table is a type of user table designed to keep a full history of data changes and allow easy point in time analysis. This type of temporal table is referred to as a system-versioned temporal table because the period of validity for each row is managed by the system. What are the usage of Temporal Tables ? The most common business uses for temporal tables are: Slowly changing dimensions. The temporal tables provide a simpler way to querying data that is current for a specified period of time, such as time slicing data, that well-known problem on Data Warehousing databases. Data Auditing. The temporal tables provide an audit trail to determine when data was modified in the “parent” table. Temporal tables allow you to query data as it was at a particular point in time to

DBCC Clone Database in SQL Server 2016

What is DBCC Clone Database in SQL 2016 ? During Database development many times we required to create exact copy of database without data. This command is used to creating a database clone is fast and easy way for such kind of requirements.  The main important feature and benefits of clone database is it copy entire objects, metadata and statistics from the specified source database without any data. Here is the command to create clone. DBCC CLONEDATABASE (YoungDBA2016, YoungDBA2016_Clone) What are the operation being process when we start cloning database ? When we configure dbcc clone database it does following operations: It Creates a new destination database that uses the same file layout as the source. Then an internal snapshot of the source database. After that it copies the system metadata from the source to the destination database. Then it copies all schema for all objects. Then it copies statistics for all indexes. Does it requires any Services packs for

SQL Servers 20 steps after start or re-start

This was always in my mind, what happened when we start or restart sql server services from os service panel. There are long list of activities process out to get connected with database. These are below : 1. Server process ID allocation and with Authentication mode. 2. Logging SQL Server messages in file 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\Log\ERRORLOG'. 3. Registry startup parameters setting for master, error,log -d,-e, -l 4. SQL Server detected cpu and cores and allocating as per licenses and configuration . 5. SQL Server is starting at normal priority base (=7).  6. SQL Server Detecting RAM and allocating to server as per awe and configured.  7. SQL Server Detecting Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0 for NUMA configuration. 8. Starting up database 'master' and do transactions rolled forward in database 'master' (1:0). 9. SQL Server Audit is starting the audits. 

Database Performance Troubleshooting Methodologies and Dimensions

When You have assigned a task to optimize a database or performance tuning of an application. Then there could be various dimensions to perform this task because slow performance of application could be many more which can not describe on single page but it can be summary in a table like below I found this table that shows database performance and slow running application performance dimension and there activity start procedures. Performance Dimensions Percentage Values Process Strength Activity Strength Remarks Application Design and Business process 25.00% Long Process Lower priority Module wise activity. Database Schema Design - Logical 15.00% Medium Follow best practices Required short downtime Module wise activity. Database Maintenance 15.00% Quick process Required on OLTP Short downtime weekly or monthly. Indexing 15.00% Quick process Required on OLTP Short downtime weekly or monthly Module wise activity. Server Hardware (CPU/Memory/other) 12.00% Medium process Follow

Group by list doesn't require as selected list

When we run group by in mysql " group by list doesn't require as selected  list " . This is another myth and confusing for mysql users. There is a table structure and some test data which I ran on mysql and sql server simultaneously. Create table groupby_test ( id int,desg varchar (20), location varchar(20)); insert into groupby_test values (1,'Jr Software','Delhi'); insert into groupby_test values (2,'Jr Software','Noida'); insert into groupby_test values (3,'Software Software','Delhi'); insert into groupby_test values (4,'Sr Software Software','Gurgaon'); insert into groupby_test values (5,'Software Software','Gurgaon'); Then Executed below group by query on mysql and sql server. select desg, location from groupby_test group by desg; Result in MySQL; Result in SQLServer Msg 8120, Level 16, State 1, Line 9 Column 'groupby_test.location' is invalid in the selec

SQL Server Database Audit Queries

When we work with a single table in SQL Server, it is very easy to perform audit queries. But, while dealing with multiple tables of the same database, it becomes a very tedious job for new database developers. We need data from multiple sources(for example : all tables of a single database). As a newcomer to this field, i too got stuck in the same kind of queries, so, I have searched the web and have listed down a few queries that can help in retrieving data through audit queries. 

3 ways to recompile stored procedures

Requirement for Recompilation :  When we create and execute a procedure it will compiled and create execution plan for the present state of the database . If we do changes into database structure, we should recompiling a procedure updates and optimizes the procedure’s query plan for those changes. This can improve the procedure’s processing performance. Another reason to stress a procedure to recompile is to retro-act the "parameter sniffing". When SQL Server executes procedures, any parameter values that are used by the procedure when it compiles are connected as part of generating the query plan. SQL Server also do automatic recompiling of procedure whenever Server is restarted. 3 ways to recompile manually : 1.) Directly writing in procedure. 2.) During execution of procedure. 3.) Ad-hoc manner from query prompt. Directly writing in procedure. Create PROCEDURE [dbo] . [upTitle_Select] @TitleID int = NULL, @Title varchar ( 5 ) = NUL

SQL71562: external references are not supported when creating a package from this platform

Last week I got this error from one of developer who was trying to deploy his project from Testing server to SQL Azure QA server. He was using “Deploy Database to SQL Azure” option from SSMS Tool-Task option. After connecting to SQL Azure portal when operation started to deployment below errors occurs. Validation of the schema model for data package failed. Error SQL71562: Error validating element has an unresolved refrence to object xx.dbo.xxxx external refrences are not supported when creating a package from this platform . Reason: The reason of the this error was; some functions of project was dependent on master database and only single database was being deploy to SQL Azure. DACFx must block Export when object definitions (views, procedures, etc.) contain external references, as Azure SQL Database does not allow cross-database external references So, this error was coming. Solution : I suggested him to create those function to locally

The database could not be exclusively locked to perform the operation

When database goes big it will difficult to do any administrative task and think if you have to change the name of database ; then it will be major task. I got below error while changing database name on my test database , users were loged in and i was trying to change the name , database server quickly pop-up error . I tried 2-3 times error was same like below : I followed below step to resolv e this issue :- ALTER DATABASE school SET SINGLE_USER WITH ROLLBACK IMMEDIATE ; GO EXEC sp_renamedb N'school' , N'SQLSchool' ; message - The database name 'SQLSchool' has been set . ALTER DATABASE SQLSchool SET MULTI_USER WITH ROLLBACK IMMEDIATE ;

sqlserver_start_time in dm_os_sys_info : sql server 2005

I was trying to get last server start time through DMV sys . dm_os_sys_info on all sql servers instance where groups was 2005+2008+2008r2+2012+2014. I got the result quickly excluded from one sql server 2005 instance it populated error.. Msg 207, Level 16, State 1, Line 1 Invalid column name 'sqlserver_start_time' . I think Microsoft was forgot to add this column in 2005. I managed it through. SELECT crdate FROM sysdatabases WHERE [name] = 'tempdb'. and xp_readerrorlog  Apart from this SYSDATETIME () was also not present in 2005 but now this is available …

How to export performance metadata and statistics

Performance of query execution (stored Procedure or Ad-hoc query) is depends on Execution Plan and execution plans depend on Statistics-histogram . We already know Query Statistics is metadata of database engine which depend on data. Every insert-update-delete changes its stats. SQL server allowing us to export and copy to another server. So we can use it to sync the performance of server during quality or testing of procedures and queries. Step Connect to Production Server and right click on database. In the list just choose Generate Script. Now click on next and Choose Advance option button. Then select script statistics and then Next and Finish. This will generate Script just copy these script and run on Quality server/Testing Server Database.   Happy Reading...

Dont worry if SSMS not support attaching FILESTREAM enabled databases

SQL Server 2005 introduced the unstructured data types VARCHAR (MAX), NVARCHAR (MAX) and VARBINARY (MAX). And later on File stream features came with 2008. We are using SQL Server version 2012 and unfortunately I would like to say to Microsoft doesn’t given option to attach File-stream Enabled Database from SSMS. Mostly this requires when trying to migrate DB or system or doing some DR activity or maintenance activity. If you will try to attach from SSMS then it may give some errors like below … TITLE: Microsoft SQL Server Management Studio ------------------------------ An error occurred when attaching the database(s).  Click the hyperlink in the Message column for details. ------------------------------ BUTTONS: OK ------------------------------   But don’t worry just try below query to re-attach db.. USE [master] GO CREATE DATABASE <DBNAME> ON ( FILENAME = N'LOCATION\name.mdf' ), ( FILENAME = N'Location\name.ldf&#

Storing BLOB Data: Data Base vs NTFS File System

BLOB/Image/Videos are unstructured data. RDBMS like SQL Server is made to store relational data. File stream is new feature of SQL Server since 2008 to store large data. This is not always the best solution to store images on db. Store the pictures on the file system and picture locations in the database. My previous experience is also saying. Why? Because...

How to create MySQL Link Server in SQL Server 2012

Workbench is a free tool for MySQL but it is collection of issues in working environment. So I came back on SQL Server management studio. But think if our requirement is something like what , data will be at same place in MySQL and we have to access from SQL Server. Then we can use SQL Server's  Server object’s Link server .  Today I am going to share 7 steps how I have made linked server from SQL Server to MySQL. 

Configure Impersonation Authentication in IIS8 for MVC Application

Impersonation is when ASP.NET executes code in the context of an authenticated and authorized client. By default, ASP.NET does not use impersonation and instead executes all code using the same user account as the ASP.NET process, which is typically the ASPNET account. There are 5 below steps by which we can establish Impersonation configuration in our secured application environment. 1.)    Creation of Application/Proxy user where Application is hosted. 2.)    Give appropriate access to the user. 3.)    Create Database Login user on database. 4.)    Authenticate User and provide credential on IIS. 5.)    Then Configure web.config on Application.

Bootstrap Study for SQL Installation Error

When we install any SQL Server Instance, all installation log we can study through its Boot Strap folder which we can find from the PATH C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log .  Like Below

File attachment or query results size exceeds allowable value of 1000000 bytes

Msg 22051, Level 16, State 1, Line 0 File attachment or query results size exceeds allowable value of 1000000 bytes. Hi fiernd, after 3 days illness now i am back in work and trying to short out some issues. Recently I got some error on Database mail, the error I face in SQL Server Database mail while sending bigger attachment using below query.

Operating system error 5(Access is denied.)

Actually I should write this post before my last post Network shared Backup , which I shared yesterday. I have decided I will share this week on network database activity. Show this is my 2 nd post on the same. While I was started to backup, restore and creating a database on network shares I faced below errors. And most of the cases issues are related to Start-up services. Generally when we install SQL server the service will be Local or Network in this situation it will not work until we will not change start-up services or we will give full access to the network shared folder.  

Backup-Restore on Network Shared drive

Hi friends, This is my post on Backup-Restore on Network Shared drive. After 2 days holidays coming back on job is difficult task and today I am not well due to cold. I did some wrong with myself eaten sweets more and after that cold water. SO my throat is not working properly. Actually Every Enterprise is facing with Crunch of resources for running application and keeping backups. Sometime we require to restore database and we have no more space on local server drive. We all facing in our life as a SQL-DBA. If you have space on Shared drive then we can use it for our backup-restore task test activity.  I am sharing you how to do on Network shared drive below tasks but be sure SQL have proper access on such drive or shares :-

How to add an article in Transactional Replication

If we have a set-up of Transactional Replication for Data Distribution running and wanting to add new object to replication on other server we can follow below process. To add an article In Transaction replication with PUSH Subscription