Option 4 – DROP TABLE IF EXISTS (SQL Server 2016 and up) The previous T-SQL examples will work in all supported versions. However, SQL Server 2016 introduced a simpler way of dropping a table with DROP IF EXISTS. Instead of having to look and see if whether or not the table exists w...
I don't like these, and if you also don't like them, then you might try new DROP IF EXISTS (a.k.a. DIE :) ) statements in SQL Server 2016.From SQL Server 2016 CTP3 you can use new DIE statements instead of big IF wrappers, e.g.:...
This SQL Server stored procedure, xp_fileexist, is used to determine if a file exists on SQL Server's hard drive or on a network share. It is extremely useful in stored procedures that load data from flat files. It allows you to check and see if the file exists before attempting to b...
There are many different aggregation functions in SQL Server, such as SUM, AVG, MIN, MAX and so on. You can find a listhere. If you only use aggregations, you don’t need to use the GROUP BY clause. For example, we can return the number of rows in a table with theCOUNTfunction: ...
Although an Access database can ensure referential integrity when a user attempts to update or delete data, SQL Server has a sophisticated set of triggers. For example, you can program a trigger to delete records in bulk and ensure data integrity. You can even add triggers...
That is exactly how this query is evaluated: SQL Server considers each row of the Employee table for inclusion in the results by substituting the value in each row into the inner query. For example, if SQL Server first examines the row for Syed Abbas, the variable Employee.BusinessEntityID ...
Unless the caller is the database owner or is a member of the sysadmin fixed server role, the principal must exist even when the user is accessing the database or instance of SQL Server through a Windows group membership. For example, assume the following conditions: CompanyDomain\SQLUsers ...
If your edition of SQL Server doesn't support Always On availability groups, use log shipping.DATABASE_MIRRORING267 Index optionssp_indexoptionALTER INDEXsp_indexoption78 Index optionsCREATE TABLE, ALTER TABLE, or CREATE INDEX syntax without parentheses around the options.Rewrite the statement to use...
SQL Server 2008 Books Online includes two examples of using Extended Events: "How to: Determine Which Queries Are Holding Locks" and "How to: Find the Objects That Have the Most Locks Taken on Them." I'd like to walk through an example of setting up an Extended Events session and analyz...
You can define a gateway SID, but using the default of dg4msql is easier because you do not need to change the initialization parameter file name. However, if you want to access two SQL Server databases, you need two gateway SIDs, one for each instance of the gateway. If you have onl...