Transact-SQL or T-SQL programming, Reporting Services, Analysis Services (OLAP), Microsoft SQL Server 2012 (SQL Server Denali), SQL Server 2008 R2, SQL Server 2008(Katmai) and SQL Server 2005 (Yukon) Articles and Tutorials
| SQL Server sp_configure Stored Procedure |
Enable Ole Automation Procedures in SQL Server 2012
SQL Server database administrator must enable Ole Automation Procedures using sp_configure for SQL developers to use sp_OACreate or sp_OAMethod like Ole Automation Procedures in their SQL scripts
|
| Restore Database from Backup File |
How to Restore Database from Backup File in SQL Server 2012
To restore database in SQL Server 2012 from database backup file is a method to move a database from a SQL Server instance to another SQL Server 2012 instance.
|
| SQL Server Tutorial |
sys.dm_db_index_physical_stats to Rebuild Index or Reorganize Index on SQL Server Database
Using sys.dm_db_index_physical_stats dynamic management function to rebuild index or reorganize index on a SQL Server database can easily be managed with a scheduled task by database administrators.
A SQL Server database administrator should periodically take action on index maintenance by using reorganize index or rebuild index commands
|
| SQL Server Tutorial |
Drop SQL Server Check Constraint without Constraint Name
To drop SQL Check Constraint where constraint's name is unknown, sys.check_constraints system view can be used. This SQL Server tutorial show how developers can create sql procedure that drop check constraint with only table name and column name parameters.
|
| SQL Server 2012 Contained Databases |
sp_configure Contained Database Authentication to Create Contained Database in SQL Server 2012
The sp_configure value 'contained database authentication' must be set to 1 in order to create a contained database. You may need to use RECONFIGURE to set the value_in_use. (Microsoft SQL Server, Error: 12824)
|
| XML in SQL Server |
Query XML in SQL Server for Different Hierarchy Levels using Cross Apply
SQL Server XML tutorial shows to query XML data using Cross Apply SQL join for XML nodes, attributes with different hierarchy levels. SQL XML query for complex XML in SQL Server 2012 frequently use Cross Apply to get desired output result from XML data.
|
| SQL Server XML Tutorial |
Query SQL Server Database Table XML data using Cross Apply Join
SQL programmers can SELECT from XML data nodes stored in SQL Server table column with XML data type. Although it is very similar to query XML variable, querying XML data column requires the use of SQL CROSS APPLY join. Cross Apply enables to execute SQL XML query on all rows of the database table instead of running SQL Select query on single XML data.
|
| SQL XML Tutorial |
Query XML data using SQL XML in SQL Server
This SQL XML tutorial shows to query XML data in SQL Server for SQL programmers to import XML to SQL Server and store XML data in SQL Server database table in table columns with SQL XML data types.
|
| SQL Tutorial - Add SQL Unique Constraint |
Add SQL Server Unique Constraint on Multiple Columns
This SQL tutorial shows how to add SQL Server unique constraint on multiple columns in a database table. SQL unique constraint on multiple columns ensures that in SQL Server table there will not be a second row sharing the same data on defined columns with an other table row.
|
| SQL Tutorial - Select Count Distinct |
SQL Count Distinct Select Query Example
To count distinct values in a database table or sql view, Transact-SQL developers can use SQL Count Distinct Select command as demonstrated in this SQL tutorial
|
| SQL Tutorial - SQL Server Row_Number() Function |
SQL Row_Number() Function Example Queries
Using SQL Row_Number() OVER (Partition By partitioncolumn Order By sortcolumn) SQL developers can create an ordered list of records grouped by a column
|
| SQL Tutorial - SQL Order By Clause |
SQL Order By Query Examples
SQL Order By clause is used to sort data returned by the execution of SQL queries developed by SQL programmers or database administrators.
|
| Insert Image to SQL Server Database |
Save Image to Database Table in SQL Server
To save image in SQL Server database table in binary format, the easiest method is to execute an SQL OPENROWSET command with BULK and SINGLE_BLOB options.
|
| Check SQL Server Version |
Download SQL Server 2012 Service Pack 1 (SQL Server 2012 SP1)
SQL Server 2012 Service Pack 1 download is available at Microsoft Downloads portal as a standalone SQL Server 2012 SP1 download and also as bundled with SQL Server 2012 named as Slipstream download
|
| Check SQL Server Version |
Check SQL Server Version using Registry Editor
To check SQL Server version on a server, there are different methods like using RegEdit Registry Editor tool or executing T-SQL commands like SELECT @@Version. In this SQL Server tutorial, I'll show how to detect SQL Server version using Registry Editor
|
| SQL Server Restore Database Fail |
SQL Server Restore Database fail because of incompatible backup and restore server version
Microsoft SQL Server Management Studio
Restore of database 'SQL Server database name' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)
System.Data.SqlClient.SqlError: The database was backed up on a server running version 8.00.0534. That version is incompatible with this server, which is running version 11.00.2100. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server. (Microsoft.SqlServer.SmoExtended)
|
| SQL Server Integer Data Types |
Max Integer Values for SQL Server Numeric Data Types
SQL Server database design requires good knowledge of data types besides many other details. Max integer values for sql numeric data types is important if you don't want to spare more database space than required for integer or numeric data
|
| SQL Server Table Valued Parameters and Table Type |
Pass Multiple Values using Table Valued Parameters to SQL Stored Procedure
Using table valued parameters in SQL stored procedure, SQL developers can provide a solution to pass a list of parameter values to the SQL stored procedure. Passing multiple values is now possible with table-valued parameters in SQL Server stored procedure programming
|
| SQL Server Attach Database Error |
Attach database failed for Server
An error occurred when attaching the database(s).
Unable to open the physical file. Operating system error 2: "2(The system cannot find the file specified.)". (Microsoft SQL Server, Error: 5120)
|
| SQL Function Example |
Select from Stored Procedure in SQL Function using OpenQuery
T-SQL programmers can select from stored procedure in sql function code using OpenQuery and linked server pointing to itself.
This SQL tutorial shows how to execute SQL stored procedure within SQL function codes and return SELECT data as a table-valued function table.
|
| SQL Server 2012 Linked Server |
How to Add SQL Server Linked Server on SQL Server 2012
This SQL Server 2012 tutorial shows how to add linked server to SQL Server 2012 instance
|
| Create SQL Server Loopback Linked Server |
You cannot create a local SQL Server as a linked server
It is possible to create SQL Server linked server on a SQL Server instance pointing to itself. This is called loopback linked server in SQL Server.
By creating local SQL Server instance as a linked server to itself enables Transact-SQL developers to use SQL Server OpenRowset or OpenQuery commands for special purposes.
|
| Create SQL Server Linked Server Error |
SQL Server Linked Server creation require sysadmin Role
While creating new linked server on SQL Server 2012 using Microsoft SQL Server Management Studio, I got the following error message:
A required operation could not be completed. You must be a member of the sysadmin role to perform this operation. (SqlManagerUI)
|
| SQL Server Troubleshooting |
SQL Server Model Database Error and Download Model Database
SQL Server error while "Starting up database model" requires a fresh model database data and log file replacement.
You can download model database data and log file for various SQL Server versions here.
|
| SQL Tools for SQL Server Administrators and Database Developers |
Execute SQL Scripts against multiple databases using Script Executor
SQL tool Script Executor from xSQL Software helps database administrators and developers to deploy sql scripts to multiple databases esily making this complex administrative task managed in a secure way.
|
| SQL Tutorial - FIFO Example in SQL Server |
FIFO Example Query in SQL Server
This SQL tutorial includes FIFO example query in SQL Server. SQL FIFO method example query is based on two database tables SalesOrder and ProductionOrder sql tables
|
| SQL Server Integration Services Tutorial - SSIS Package |
Export Data to Flat File using SSIS Package
This SQL Server SSIS tutorial shows how to export data stored in database table into a flat file by using SSIS package. Using SQL Server Business Intelligence Development Studio (BIDS), SQL Server BI developers can easily create SSIS package to transfer table data to a text file
|
| Transact-SQL Tutorial |
Compare 3 Numbers using SQL Script
This SQL tutorial shows how to compare 3 numbers using SQL script for Transact-SQL beginners. By changing the below sql codes, developers can easily sort 3 numbers given as variables from biggest to smallest values.
|
| Transact-SQL Tutorial |
SQL Repeat Rows N Times According to Column Value
To repeat table rows in different number of times SQL developers can use given T-SQL codes in this SQL tutorial. Sometimes developers are required to repeat records according to a number column in that table rows.
|
| SQL Server Data Compare Tool |
xSQL Data Compare – data comparison and synchronization tool for SQL Server
In this SQL data compare tool guide, we review xSQL Software's Data Compare tool. SQL Server database administrators and SQL developers can use this SQL Server tool for data comparison and data synchronization.
|
| SQL Server Schema Compare Tool |
xSQL Object – SQL Schema Compare tool for SQL developers and DBA
SQL Server database schema compare tool review includes xSQL Software's SQL schema compare tool and its schema comparison and create synchronization script features.
|
| Transact-SQL Merge Command |
T-SQL Merge in SQL Server Trigger for Summary Table Maintenance
In order to provide a detail and summary table solution in a SQL Server database, SQL Merge command can be used in SQL Server trigger codes as demonstrated in T-SQL tutorial.
|
| SQL Server Auditing Tool |
Failed Login Attempts Auditing using SQL Server Audit Tool
To log failed login attempts to SQL Server database instance is a best practice for database administrators to keep data platform safe and secure from unauthorized users
|
| SQL Server Auditing Tools |
SQL Server Login Auditing using SQL Server Audit Tool
Database administrator can log successful logins to SQL Server using new SQL Server auditing tool SQL Server Audit. In this SQL Server tutorial, administrators can configure an SQL Server login auditing mechanism using SQL Server Audit tool step by step
|
| SQL Server Tools |
SQL Server Activity Monitor Tool for Database Administrators
A new SQL Server tool for database administrators with SQL Server 2008 is SQL Server Activity Monitor for monitoring SQL Server performance and for troubleshoot SQL Server performance problems.
|
| Transact-SQL Tutorial |
List Month Names using SQL Functions
SQL developers may need to list month names using SQL functions during their T-SQL programming tasks. This Transact-SQL tutorial will demonstrate sql codes with DATENAME() function that can be used in order to list names of months in SQL
|
| SQL Mail XPs |
Configure SQL Mail XPs sys.xp_readmail by using sp_configure
SQL Server blocked access to procedure 'sys.xp_readmail' of component 'SQL Mail XPs' because this component is turned off as part of the security configuration for this server
|
| Database Mail |
SQL Server Email using sp_send_dbmail with File Attachment
T-SQL programmers can easily attach files to database mails in SQL Server sent by using sp_send_dbmail by passing file physical paths into @file_attachments parameter
|
| Transact-SQL Tutorial |
SQL paging using ROW_NUMBER() SQL Server Function
SQL paging in web applications like ASP.NET web sites, etc is a common requirement for SQL Server developers. For SQL Server versions before SQL Server 2012, for example paging in SQL Server 2005 can be implemented using ROW_NUMBER() SQL Server function easily
|
| SQL Server FileStream |
FILESTREAM feature is not supported on WoW64
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
FILESTREAM feature is not supported on WoW64. The feature is disabled. (Microsoft SQL Server, Error: 5593)
|
| SQL Server 2012 Installation |
There was a failure to validate setting CTRLUSERS in validation function ValidateUsers
During SQL Server 2012 RC0 evaluation version installation, I got the following setup error : Error code 0x85640004.
There was a failure to validate setting CTRLUSERS in validation function ValidateUsers. Error code 0x85640004.
|
| SQL Server BCP |
SQL Server BCP Utility with sp_HelpText to Generate Script File for Each Stored Procedure in a Database
SQL Server BCP utility is used to write sql query results to text files into a file folder. If T-SQL developers use SQL BCP with sp_HelpText, it is possible to generate script files for SQL Server objects too.
|
| Transact-SQL Development in SQL Server 2012 |
New SQL IIF Boolean Function in SQL Server 2012
New SQL IIF function introduced with SQL Server 2012 evaluates a boolean expression and according to the being True or False of the boolean expression, returns one of the input values
|
| SQL Server Tools |
How to Display SQL Server Job History
SQL Server developers and database administrators can list SQL Server job history by querying MSDB database. SQL Server MSDB database stores data related with SQL Server Agent service processes like database jobs, SQL Server job scheduling, job history, etc.
|
| SQL Server FileStream Configuration |
Default FileStream filegroup is not available in database 'DatabaseName'
Msg 1969, Level 16, State 1, Line 1
Default FILESTREAM filegroup is not available in database 'DatabaseName'
|
| SQL Server Management Studio |
Hide Results Pane Shortcut Ctrl+R in SQL Server Management Studio, Denali CTP3
SQL Server Management Studio (SSMS) Hide Results Pane shortcut Ctlr + R is not defined on my SQL Server 2012, Denali CTP 3 installation at home
|
| SQL Server Recursive Query |
SQL Server Recursive Query with Recursive CTE (Common Table Expession)
SQL Server Recursive Query structure is new with SQL Server 2005 Common Table Expression improvement. What makes CTE indispensable in SQL development is its recursive query creation features.
|
| SQL Server Computed Columns |
Computed Column Sample in SQL Server Database Table
A computed column in SQL Server is an expression field which uses other columns in the table as input in the expression.
|
| SQL Server Backup |
SQL Server Backup using Cmd Windows Command Line Backup with SQLCmd
This SQL Server 2008 tutorial show how to back up SQL database using command line tool SQLCMD
|
| T-SQL Time Data Type Calculations |
How to Calculate Time Operations in SQL Server on Time Data Type
Frequently, t-sql developers sum time fields and then return total time variable as and expression in hour, minute and seconds.
|
| SQL Server 2012 Express LocalDB Management |
SQL Server Express LocalDB Management Utility SqlLocalDB.exe
A SQL Server Express LocalDB database is managed by the SqlLocalDB.exe management utility. In BOL (Books OnLine), you may also read about LocalDBManager.exe management utility, too.
|
| New SQL Server Functions |
SQL Choose() Function in SQL Server 2012, Denali
SQL Choose() function returns an input argument from a list of input values at the desired index which is specified as an input arguement as well
|
| New SQL Server Datetime Functions |
Calculate SQL Last Day of Month using End of Month EOMonth() Function in SQL Server 2012
SQL Server EOMonth() function returns the last day of the month that the input argument start_date is in that month. There is an optional input parameter offset, which helps T-SQL developers to find the end of month that is N months later or before the input start date argument
|
| SQL Server Analytic Functions |
SQL LAG() Function in SQL Server 2012 for Calculating Previous Values
SQL Server LAG() function is a new SQL Analytic Function introduced with SQL Server 2012, Denali, CTP3 for T-SQL developers. SQL Lag() can be used to return previous row value in an ordered list of rows
|
| SQL Server Analytic Functions |
SQL LEAD() Function in SQL Server 2012 for Calculating Next Value
SQL LEAD() function is one of the recent enhancements among SQL Analytic Functions introduced with Denali, CTP3 for SQL Server 2012 developers. What SQL Server Lead() function does is returning simply the next Nth row value in an order
|
| Install SQL Server 2012 Express LocalDB |
SQL Server 2012 Express LocalDB Installation
SQL Server 2012 Express LocalDB is a new edition for SQL Server Express product especially targeting application developers.
This document is showing SQL Server Express LocalDB installation step by step with screenshots
|
| Install SQL Server 2012 |
How to Install SQL Server 2012 Denali CTP3
This tutorial is showing how to insall SQL Server 2012 Denali CTP3 on a database server. The above described setup process may vary according to the SQL Server feature selection you configured for the instance. I hope the setup guide will be helpful for developers and SQL Server database administrators.
|
| SQL Server 2012 Sample Database |
Download Sample Database AdventureWorks for SQL Server 2012
Microsoft SQL Server 2012 database administrators and T-SQL developers can download sample database AdventureWorks for SQL Server 2012, Denali CTP3
|
| SQL Server Analytic Functions |
First_Value SQL Analytic Function in SQL Server 2012 T-SQL
First_Value SQL analytic function returns the first value of an ordered set of values
|
| SQL Server Analytic Functions |
Last_Value SQL Analytic Function in SQL Server 2012 T-SQL
Last_Value() function is one of the newest enhancements in T-SQL just like other new SQL Server analytic functions introduced with SQL Server 2012, Denali CTP3 release
|
| SQL Server Express LocalDB |
What is SQL Server Express LocalDB enhancement with SQL Server 2012
The SQL Server Express 2012 LocalDB enables developers directly connect to a SQL Server database. And programmers can easily write to SQL database files and read from SQL Server database tables without dealing with the management of a SQL Server instance on their local machine.
|
| SQL Server Reporting Services 2012 Enhancements |
What is New in SQL Server Reporting Services 2012 with CTP3
Microsoft has released CTP3 version of next Data Platform tool, SQL Server 2012 aka Denali.
And there are good news for Business Intelligence developers who are using SQL Server Reporting Services for BI development
|
| T-SQL Enhancements in SQL Server 2012 |
SQL Analytic Functions new in SQL Server 2012 for T-SQL Developers
Microsoft SQL Server 2012 introduces a list of SQL Analytic Functions for T-SQL developers.
|
| SQL Programmability Enhancements in SQL Server 2012 |
New T-SQL Functions in SQL Server 2012 for T-SQL Developers
Microsoft SQL Server 2012 introduces new 14 built-in functions as a programmability enhancement for T-SQL developers with the latest release of SQL Server 2012, Denali CTP3 release
|
| SQL Server Reporting Services |
SQL Server Reporting Services: Create Data-Driven Subscription
In this SQL Server Reporting Services tutorial, business intelligence developers will create data-driven subscription in Reporting Services. Data-driven subscriptions enable SQL Server Business Intelligence developers deliver database reports in various formats in mass numbers with single task
|
| SQL Server Tools |
SQL Server Copy Database Wizard
SQL Server Copy Database Wizard provides a handy SQL Server tool for database administrators and developers to copy sql database from one SQL Server instance to another SQL Server
|
| SQL Server Tools |
Define Keyboard Shortcuts in SQL Server Management Studio to Simplfy T-SQL Commands
Why don't you use SQL Server Management Studio Query Window keyboard shortcuts? Just highlight the SQL Server object name on Query Editor window and press shortcut keys
|
| SQL Server Reporting Services |
Subscriptions cannot be created because the credentials used to run the report are not stored
Reporting Services subscription error : Subscriptions cannot be created because the credentials used to run the report are not stored, or if a linked report, the link is no longer valid.
|
| T-SQL |
Last Update Date using SQL Trigger in SQL Server Database Table
It is important to keep last update date on a database table row to see the last time when the current record is updated. Database administrators and SQL developers generally put InsertDate and UpdateDate columns in table definitions during their CREATE TABLE scripts. I use SQL Serve Update Trigger or SQL Server Instead Of Update Trigger to keep last update date field up-to date
|
| SQL Server 2012 Denali |
Cannot connect to SQL Server 2012 Denali
I'm running SQL Server 2012, aka Denali CTP 1 on my local computer. Yesterday I got an error message "Cannot connect to SQL Server Denali instance" when I tried to connect to SQL Server 2012 instance using SQL Server Management Studio (SSMS).
|
| SQL Split String Function |
TSQL Character Split Function in SQL Server
SQL Server split function in this t-sql tutorial returns each alpha-numeric character of the input string in different rows in order back to the user as output. One important task for this string function is it adds additional null values between characters, if there is a numeric character in the input string
|
| T-SQL Tutorial |
SQL Count Function with Partition By Clause
SQL Count with Partition By clause is one of the new powerful syntax that t-sql developers can easily use which is introduced with SQL Server 2005
|
| SQL Formatter SQL Server Tools |
SQL Assistant SQL Formatter tool for SQL Server Database Developers
Using SQL formatter tool for formatting sql code is very important to make sql code reading easier. I believe many sql developers searched for a formatting sql code tool. I ended to suffer from unformatted sql codes within hundreds of lines of t-sql code in stored procedures with SQL Assistant SQL Server tool.
|
| SQL Server Performance Optimization |
SQL Query Performance Optimization using SET Statistics in SQL Server
It is a vital task for SQL Server developers and database administrators to optimize SQL query performance especially if the database application is showing poor performance.
|
| SQL Running Totals |
SQL Running Total Sample in SQL Server 2008
Calculating sql running total in SQL Server queries is a common task for most of t-sql developers. In order to display running totals for a quantity or amount column, easiest method in SQL Server is using t-sql CTE (Common Table Expression) structures
|
| T-SQL Date Table |
Create Date and Time Intervals Table in SQL Server 2008
Time schedule table or date table is frequently required by sql developers during t-sql coding. In this t-sql tutorial I want to give some sql hints that SQL programmers can use in their daily works. You will see that the following sql samples use SQL Server numbers table code in order to create a periodic time blocks or time intervals for different purposes
|
| SQL Cursor Tutorial |
T-SQL Nested Cursor in SQL Server 2008
SQL developers can create nested cursor in SQL Server by defining an outer cursor and within the cursor code a new cursor is defined for each row in main cursor select. The inner cursor is created, executed, closed and deallocated each time in the outer cursor for each row
|
| SQL Server Instead Of Trigger |
SQL Server Instead Of Trigger with Sequence Table Sample
Using SQL Server Instead of Trigger defined on a table in combination with a sequence table and T-SQL features like SQL Output clause and T-SQL Row_Number function I will show how to insert the identity column value of a table from the sequence table.
|
| Oracle Linked Server |
Create Oracle Linked Server to Query data from Oracle to SQL Server
This SQL Server tutorial shows how to create SQL Server linked server to Oracle database, for SQL Server administrators and t-sql developers to execute sql statements over the target Oracle database tables.
|
| SQL Server BCP Command |
SQL Server BCP Command Example for SQL Output to File
In this sql tutorial, t-sql developers will find MS SQL BCP example to write SQL output to file.
Using SQL BCP command, developers can write output to text file.
Here t-sql developers can find the basic sql BCP command syntax.
|
| SQL Server Import Data using SSIS Package |
SQL Server Import Data using SQL Server Import Export Data Wizard SSIS Package
SQL Server Import and Export Wizard, one of powerful SQL Server tools enables SQL Server import data easily for ETL developers and database administrators.
It also enables step by step sql data import task, save sql import task as an SQL Server Integration Services SSIS package and run ssis package to complete data import into SQL Server database.
|
| SQL Server Logon Trigger |
Logon Triggers - Logon failed for login due to trigger execution
While trying to connect SQL Server using SQL Server Management Studio Object Explorer, I got the following error message "Logon failed for login 'sqluser' due to trigger execution.".
When I see the error message occured during connect to SQL Server 2008 R2 database, I realized that the cause of the sql exception is the SQL Server logon trigger which I created recently for SQL Server login audit purposes
|
| T-SQL Programming |
SQL Waitfor Delay and SQL Waitfor Time in SQL Server
T-SQL developers use SQL Waitfor statement to postpone or delay the execution of a t-sql script block or to set the execution time of the sql code block.
|
| T-SQL Programming |
How to Calculate SQL Last Day of Month in SQL Server
In order to return the last day of the month of a specific date the sql last day of month code scripts that are given in this T-SQL tutorial can be used.
|
| T-SQL Programming |
Use xp_dirtree SQL Server Stored Procedure and Recursive CTE Query to List Hierarchical Structure of File Folders
T-SQL programming enables developers to use xp_dirtree SQL Server stored procedure with SQL recursive CTE query to display subdirectory list as a hierarchical structure of file folders.
|
| SQL Server Export to Excel |
Export Data to Excel using SQL Server Integration Services SSIS Package
In this SQL Server tutorial, I want to show how SQL developers can create SQL Server SSIS package for sql data export to Excel file and deploy SSIS package to SQL Server Integration Services.
|
| T-SQL Tutorial |
How to Prevent DROP Table using SQL Server View With SchemaBinding
SQL programmers can create SQL Server database VIEW objects using With SchemaBinding option.
To create view with SchemaBinding enables sql developers create database view objects that will prevent changes in the dependent database objects.
This will result in more stable sql View objects
|
| T-SQL Trigger |
How to Prevent DROP Table using SQL Server DDL Trigger
T-SQL developers and SQL Server administrators can prevent unauthorized users to drop sql tables using sql DROP TABLE command on their databases with the use of SQL Server DDL trigger
|
| T-SQL Functions |
Case Sensitive SQL Split Function
In this T-SQL tutorial, SQL developers can find a sample sql case sensitive split string function.
This sample SQL split string function identifies upper case letters and behaves as the start of a new word.
|
| Transact-SQL DateAdd |
SQL Server DateAdd Function T-SQL Example
SQL Server DateAdd function returns date which is added a time inverval identified by "basic datetime interval units times a given number of times" to a specific input date or datetime parameter.
|
| Transact-SQL Programming |
Fuzzy String Matching using Levenshtein Distance Algorithm in SQL Server
The Levenshtein distance algoritm is a popular method of fuzzy string matching.
Levenshtein distance algorithm has implemantations in SQL Server also.
Levenshtein distance sql functions can be used to compare strings in SQL Server by t-sql developers.
The term Levenshtein distance between two strings means the number of character replacements or chararacter insert or character deletion required to transform one string to other.
|
| SQL Server Dynamic SQL Query |
How to Build SQL Server Dynamic SQL Query Example
In this SQL tutorial, sql developers will find an sql dynamic query example.
I will try to build a dynamic sql query in SQL Server which can be altered and placed in a SQL Server stored procedure
|
| SQL Server Tools |
LiteSpeed Backup SQL Server Backup Compression Tool
In many companies SQL Server database administrators in IT departments prefer to use third-party SQL Server backup compression software and sql backup compression tools for SQL Server.
LiteSpeed Backup SQL Server Backup Compression tool is one of the mature tools in the market that makes the sql backup and restore database tasks easier for database administrators.
|
| SQL Server 2012 |
How to Install SQL Server 2012 - Microsoft SQL Server 2012 Installation Guide
Microsoft has released the next version of SQL Server, code-name SQL Server Denali, Microsoft SQL Server 2012 CTP 1 recently.
I also download SQL Server 2012 CTP1 from Microsoft downloads and while installing SQL Server 2012 I tried to take some notes.
I hope SQL Server database professionals like administrators and t-sql developers find my SQL2012 setup notes useful.
|
| SQL Server 2012 |
Microsoft SQL Server 2012 Requirements
During Microsoft SQL Server 2012 installation, in order to install SQL Server 2012 without a problem and an interreption please take care to the Microsoft SQL Server 2012 Requirements list.
It is better to install the Microsoft SQL Server 2012 requirements before starting MS SQL2012 installation or before you download SQL Server 2012 Denali Setup files.
|
| SQL Server 2012 |
Download SQL Server 2012 Sample Databases including AdventureWorks Database
Microsoft has released the Microsoft SQL Server 2012 CTP1, the first Community Technology Preview (CTP) of next version of MS SQL Server.
The release of Microsoft SQL Server 2012 CTP1, and the the coming closer of the RTM release date SQL Server 2012 sample databases are being more required for SQL Server administrators and T-SQL programmers.
|
| T-SQL sp_MSForEachDB Stored Procedure |
List Database Size using SQL Server sp_MSForEachDB Stored Procedure
SQL Server sp_MSForEachDB stored procedure can be used by SQL Server database administrators and SQL developers to get a list of SQL Server databases and the database sizes.
|
| SQL Server sp_rename Stored Procedure |
How to Rename Dabase Name using T-SQL sp_rename in SQL Server 2008
In order to rename database name in SQL Server, sp_renamedb stored procedure can be used.
|
| SQL Count Over Partition By |
SQL Select Count of ResultSet Rows using COUNT(*) OVER PARTITION BY
T-SQL developers frequently require the sql select count of the resultset beside the rows data itself.
Here is a small SELECT statement trick to return the total rows count within the returned result set
|
| SQL Tutorial - COALESCE |
SQL COALESCE Function Example
T-SQL developers sometimes require to test if a group of sql parameter values are NULL or not.
SQL developers can use the SQL COALESCE function which returns the first NOT NULL value of the function arguments.
|
| SQL Pad Leading Zeros |
SQL Tutorial - SQL Pad Leading Zeros
In order to sql pad leading zeros, sql developers use sql string concatenation and sql string functions LEFT and RIGHT.
LEFT and RIGHT sql string functions enable sql developers to take left part of a string variable or column, or extract right part of a string
|
|
SQL Server 2005 Service Pack 2 is now available
Microsoft has announced SQL Server 2005 Service Pack 2 (SP2) on 16th of February 2007 For more information on SP2 read article at SQL Server 2005 SP2 titled article.
|
SQL Server 2005 Service Pack 1 is now available
Microsoft has announced SQL Server 2005 Service Pack 1 (SP1) on 18th of April
For more information on SP1 read article at SQL Server 2005 SP1 titled article.
|
| SQL Trigger Tutorial |
SQL Tutorial : Log Price Changes using SQL Server Trigger in SQL Server 2008
In this sql tutorial, I want to give SQL Server trigger example in SQL Server 2008 R2.
SQL developers can also use this SQL trigger example code with a minor change in MS SQL Server 2008 and in MS SQL Server 2005.
In this SQL Server trigger example, the aim of the sql trigger is to keep history of changes on price column in a table.
When a new record is inserted the SQL Server trigger will also create a new row in sql log table.
When the data row is updated in the sql table, sql trigger will check if certain column is also updated.
Here in this example, sql trigger will check if price column is updated.
If certain column is updated or changed, sql trigger will also update the log table.
If data row in main sql database table is deleted, then log table will also be updated to reflect this sql delete operation in log table.
|
| T-SQL Tutorial - Table-Valued Function |
SQL Server Table-Valued Function Example
A SQL Server table-valued function is a user-defined function which returns a table data type as output.
What makes SQL Server table-valued functions more useful in some situations than sql views or sql stored procedures is like every sql function, a t-sql table-valued function also accepts parameters.
|
| SQL Server Trigger |
SQL Trigger Example in SQL Server 2008
An SQL trigger can contain sql codes that are executed automatically by SQL Server engine when a certain event occurs.
Since this sql tutorial is concentrated on DML (Data Manipulation Language) concepts right now, our sql code examples will be a DML sql trigger.
The events that trigger SQL Server triggers which are actually stored t-sql codes are sql INSERT, UPDATE and DELETE statements executed on a sql database table.
|
| SQL Server Analysis Services |
Service 'MSSQLServerOLAPService' start request failed
After I had install Microsoft SQL Server 2008 R2, while trying to start MS SQL Server Analysis Service I got the following error message : The service could not be started. Reason: Service 'MSSQLServerOLAPService' start request failed.
|
| Change Data Capture |
SQL Server Log Tool for Capturing Data Changes by building Change Data Capture Structure for MS SQL Server 2005
If you are using Microsoft SQL Server 2005 as your relational database and you neeed to log data changes in sql server databases in order to log changes or for recovery data, you can use the logging changes solution described here in this article built like Change Data Capture structures for MS SQL Server 2005 databases.
|
| SQL Server Export to Excel |
SQL Server Export to Excel using SQL Server Import and Export Wizard
Data export to Excel from SQL Server has always been a problem for T-SQL developers and SQL Server administrators.
Microsoft SQL Server professionals have now advanced sql tools for solution to SQL Server export to Excel within SQL Server Management Studio.
The latest SQL tool to export data to Excel from SQL Server is SQL Server Import and Export Wizard
|
| SQL Tutorial |
How to drop Default Constraint on a Table Column without knowing the Constraint Name for MS SQL Server 2005
How to drop Default Constraint on a Table Column without knowing the Constraint Name for MS SQL Server 2005
|
| SQL Tutorial |
How to Search SQL Text Anywhere in SQL Server Database
Many developers face the problem to search SQL text anywhere in the sql database objects definition.
If sql developers have an sql search tool which can be used to find specific keywords in SQL Server object definitions, then the solution to search string in sql is easy.
|
| SQL Tutorial |
How to Debug Stored Procedure in SQL Server 2008
Just to make a short introduction for how to debug stored procedure in SQL Server 2008, I code the below t-sql code and execute it to create stored procedure in sample SQL Server database
|
| SQL Tutorial |
SQL Tutorial - How to Map Payments to Expenses using T-SQL Query
n your SQL Server database you have two database tables to store expenses and payments for closing expense amount.
You want to list the expenses of a customer using t-sql by querying your sql tables.
This list will also add the payments done by the same customer to close these expenses.
Each payment will be listed as new columns beside the expenses records.
|
| SQL CLR String Split Function |
SQL Server String Split T-SQL CLR Function Sample
SQL Server CLR It is one of the best enhancements of Microsoft SQL Server 2005 on t-sql development.
SQL CLR enables developers to create sql clr stored procedure and sql server clr function to build complex processes easier and perform better using VB.NET or C#.
String split is one of the sample applications where SQL Server CLR functions will perform better in SQL Server 2005 and SQL Server 2008.
In this sql clr tutorial, we will see VB.NET codes of a SQL Server CLR function.
And later we will create sql split function referring that sql CLR string split function.
|
| T-SQL xp_cmdshell |
List Directory Files using T-SQL xp_cmdShell Stored Procedure
In this sql tutorial, developers can find a short t-sql script which can be used to list directory files and display contents as a file list using the t-sql xp_cmdShell stored procedure
|
| SQL Server Partition Table |
How to Partition Table (a Non-Partitioned Table) using T-SQL in SQL Server 2008
"Can we partition existing table in SQL Server ?", or "How can we add partitioning to a non partitioned table ?" are frequently asked questions about sql partitioning and partitioned tables in MS SQL Server among t-sql developers and SQL Server professionals. Especially partitioning non-partitioned tables may become a difficult task to partition an already existing table if it contains a lot of data and has many constraints and relations with other sql tables in the database.
|
| SQL Server Backup |
How to Create SQL Server Backup Job
All SQL Server database administrators create SQL Server backup job to take database backup of their SQL Servers.
It is of course possible to execute SQL Server backup scripts periodically, or to execute t-sql backup commands from a scheduled SQL Server job, but Microsoft SQL Server 2008 R2 has advanced Maintenance Plan options to manage sql backup tasks for you.
|
| SQL XML Query Example |
Microsoft SQL Server XML Query Example
In this SQL XML Query example, t-sql developers will see enhancements introduced first with Microsoft SQL Server 2005 related with SQL XML features.
Let's start first by defining a sample sql xml structure which contains a list of SQL programming and administration books.
|
| SQL Server Backup Script |
SQL Server Backup Script for All Databases in SQL Server Instance
Undocumented stored procedure sp_Msforeachdb can help SQL administrators and t-sql developers to repeat tasks on each of sql databases running on the SQL Server instance.
Taking sql backup of all sql databases on a SQL Server can be considered as a repeatitive task for many administrators.
So it is certain that an SQL Server backup script using sp_Msforeachdb undocumented stored procedure will make it sql backups easier for many sql professionals.
|
| SQL Backup Script |
MS SQL Server Backup Script
Microsoft SQL Server database administrators and T-SQL programmers can use SQL Server backup script to take sql backup of their sql databases.
|
| SQL Backup |
SQL Backup - SQL Server Backup Database Tool in SQL Server Management Studio
SQL Server backup is copy of your data in your database which can be used to restore your data in case of a failure in your production environment or in your data platform.
SQL Server Backup Administrators are responsible from regularly taking sql backups of databases in SQL Server instances.
Database backups can be stored on disks or on backup tapes according to the medium that is accepted in backup and recovery scenarios.
|
| SQL VBScript |
How to Run VBScript from SQL Server 2008
SQL developers can run vb script files from SQL Server t-sql codes by using xp_cmdshell procedure.
It is sometimes a requirement especially for web developers to call vb script from SQL Server engine and execute vbscript from sql code.
Of course calling vbscript from sql can be solved by using CLR in SQL Server after the release of SQL Server 2005.
|
| SQL Server E-Mail |
Send SQL Mail using CDONTS.NewMail in SQL Server 2008
SQL developers can send e-mail from SQL Server using CDONTS or CDOSYS.
Although SQL Server 2005 introduced Database Mail for sending emails from SQL Server, the old school is still common among SQL Server administrators and t-sql developers.
Let's make an example and remember how CDONTS can be used along with SQL Server OLE Automation stored procedures.
|
| SQL Server 2008 Database Mail Setup |
How to configure Database Mail in SQL Server 2008 R2 and Use sp_send_dbmail
What is SQL Database Mail ?
Database Mail Configuration in SQL Server 2008 R2
How to Send eMail using Database Mail sp_send_dbmail T-SQL Command
|
| SQL XML Query in SQL Server |
SQL XML Query in SQL Server 2008
With t-sql enhancements introduced with Microsoft SQL Server 2005, developers are now enable to use more powerful T-SQL XML commands during their developments.
Let's define a sample sql xml variable @xml using type definition XML.
Our sample SQL XML data contains a list of SQL Server 2008 books published by various publishing companies.
|
| Import XML into SQL Server |
How to Import XML into SQL Server 2005 or SQL Server 2008
In SQL XML data can be queried with new t-sql xml query improvements easier than ever.
In this MSSQL XML tutorial, I will try to give t-sql xml query samples that can be used with dealing sql xml data and import XML to SQL Server.
|
| T-SQL |
A correlation name must be specified for the bulk rowset in the from clause.
While inserting image files into a SQL Server database table using the OPENROWSET function, I got the following error message from the SQL engine.
"A correlation name must be specified for the bulk rowset in the from clause."
|
| SQL Server Database Mail |
SQL Server Database Mail sp_send_dbmail Example
Here is a sample t-sql code using sp_send_dbmail system stored procedure to send email from SQL Server.
Since Database Mail feature is first introduced to administartors and developers with MS SQL Server 2005, SQL Server administrators and t-sql developers can use the below sp_send_dbmail example sql code on a Microsoft SQL Server 2005, MS SQL Server 2008 or SQL Server 2008 R2 instance.
|
| SQL Server 2008 Certification |
Microsoft SQL Server 2008 Certification Exams
In this certification guide, candidates will find the list of Microsoft SQL Server 2008 Certification Exams giving credits for MS SQL Server 2008 Certifications.
|
| T-SQL |
sysindexes System View - List of Indexes Defined on a SQL Database Table
SQL developers and SQL Server database administrators frequently require to list of indexes defined on a sql database table.
In MS SQL Server 2005 and later versions (SQL Server 2008, SQL Server 2008 R2), t-sql developers and sql administrators can use below t-sql select script in order to list SQL Server indexes defined for a sql table.
|
| SQL Server 2008 R2 |
AdventureWorks Database - Download Microsoft SQL Server 2008 R2 Sample Databases
After the RTM release of Microsoft SQL Server 2008 R2, the new data platform of Microsoft, related product releases are following each other.
Microsoft has released sample databases for Microsoft SQL Server 2008 R2 on for SQL Server administrators, t-sql developers, BI developers and IT professionals.
You can free download SQL Server 2008 R2 sample databases including AdventureWorks database download from CodePlex.
|
| T-SQL TRY CATCH |
SQL Try Catch in SQL Server 2005
One of the tsql enhancements in Microsoft SQL Server 2005 is SQL Try Catch improvement.
TSQL Try Catch in SQL Server 2005 enables SQL developers to have more control on error and exception handling in Microsoft SQL Server 2005 and MS SQL Server 2008 databases
|
| SQL Server 2008 R2 |
Microsoft SQL Server 2008 R2 Upgrade Advisor Download
If you plan to upgrade to MS SQL Server 2008 R2, you should better choose Install Upgrade Advisor first. After downloading and installing Upgrade Advisor, you can run SQL Server Upgrade Advisor. Running SQL2008 R2 Upgrade Advisor will enable administrators to see if the current SQL Server instances will experience problems related with SQL Server 2008 R2 upgrade.
|
| SQL Server 2008 R2 |
What is new in Microsoft SQL Server 2008 R2 Reporting Services
Microsoft has released MS SQL Server 2008 R2 recently.
Now Business Intelligence (BI) developers want to learn what is new in Microsoft SQL Server 2008 R2 Reporting Services features.
Here is a short list of new features in Reporting Services 2008 R2.
Shared Data Sets
Report Part Gallery
Sparklines, Data Bars and Indicators
Aggregation on Aggregates
Rendering Features
Browser Support
|
| SQL Server 2012 |
MS SQL Server 2012 aka Denali, Next Version of SQL Server
Microsoft has long ago started on project named Denali, codename of MS SQL Server 2012.
If project goes as planned the successor the new SQL Server 2012 version will be available for use in the early months of year 2012. So speculations about the name as Microsoft SQL Server 2010 or SQL Server 2011 will be meaningless.
|
| T-SQL NEWID() |
Use SQL NEWID in SQL Functions as SQL Random Generator
SQL NewID function is used for selecting random row from a resultset in SQL Server databases. Using with TOP N keyword in SELECT statements where SQL NEWID is in the ORDER BY statement, random records are selected from a table or from a set of rows. "SELECT TOP 1 FullName FROM Customers ORDER BY NEWID ()" is a sample sql NEWID usage.
|
| SQL Extended Stored Procedure |
How to Create Folder from SQL Server sys.xp_create_subdir Extended Stored Procedure
In this SQL Server tutorial for sql developers, I'll show t-sql codes that can be used to create folder using SQL Server sys.xp_create_subdir extended stored procedure
|
| SQL Multiple CTE Example |
SQL Multiple CTE Syntax and T-SQL CTE Example in SQL Server 2008
This t-sql tutorial will give t-sql examples to show hot to use sql multiple CTE queries in one SQL Select statement.
|
| SQL Select from Stored Procedure |
How to SQL Select from Stored Procedure using SQL Server OPENQUERY or OPENROWSET
SQL developers frequently require to select from sql stored procedure execute results.
This t-sql tutorial will display a sample t-sql script using SQL Server OPENQUERY which show how to sql select from SQL Server stored procedure.
The second example will be similar to SQL OpenQuery but this time in sql codes we will use SQL OPENROWSET in order to select from stored procedure.
|
| SQL Server Trigger |
SQL Trigger : SQL Server Trigger Example to Log Changes History of a SQL Table
In this t-sql tutorial sql administrators and tsql developers will find SQL Trigger example code created for logging of updated or deleted records into history tables.
The SQL Server trigger will be created as sql update / delete trigger on the target database table.
For example when the web application or users create/insert record into sql table or delete record from sql database table, the sample sql trigger will execute.
The sql trigger will insert the deleted or updated version of the table row into history table
|
| sp_Msforeachdb SQL Procedure |
How to Find a SQL Table in All Different Databases on a SQL Server Instance using sp_Msforeachdb
SQL Server database administrators sometimes need to search for a sql table in all sql databases on a SQL Server instance.
Using sql sp_Msforeachdb undocumented stored procedure, the SELECT statement or any t-sql statement passed as an argument will be executed on every SQL database existing on the SQL Server instance
|
| xp_regread SQL Procedure |
Read Registry using SQL Server xp_regread SQL Stored Procedure
xp_regread sql stored procedure can be used to read registry key values in t-sql codes on a MS SQL Server database server.
xp_regread sql extended stored procedure is one of the undocumented stored procedures.
|
| T-SQL Utilities |
How to use SQL DROP Table If Table Exists in SQL Database
If you want to drop a table which might have already created in the SQL database, you can use sql DROP TABLE command.
The sql drop table command will run successfully if sql table table exists.
Contrarily if the sql table does not exist in SQL Server database, then sql DROP TABLE command will cause sql engine to throw an error.
|
| T-SQL Utilities |
SQL Object Where Used List by a Search SQL Database Objects Text
It is a very common requirement for SQL Server database administrators and sql developers to search in which sql objects a stored procedure or a view or a table is used.
One way of finding sql objects like sql procedures, views and sql functions which uses a specific object is to run a t-sql SELECT statement on the text definitions of all database objects like SPs, views and tsql functions.
The text definitions of all objects are stored in text column of syscomments system table.
|
| SQL Server 2008 |
SQL Server Management Studio 2008 SSMS : "Saving changes is not permitted" error
Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.
|
| SQL Functions |
How to Extract Filename from Path using SQL Functions
In this sql tutorial, t-sql developers can find sql codes for extracting file name from fullpath of a file.
|