
Rebuild All Database Indexes
You can rebuild all indexes present in your database with the following query: EXEC sp_MSforeachtable @command1=”print ‘?’ DBCC DBREINDEX (‘?’, ‘ ‘, 80)” GO EXEC sp_updatestats GO
You can rebuild all indexes present in your database with the following query: EXEC sp_MSforeachtable @command1=”print ‘?’ DBCC DBREINDEX (‘?’, ‘ ‘, 80)” GO EXEC sp_updatestats GO
There are two ways to prevent your SQL code from running on a testing or production server. You can use the @@SERVERNAME Variable or the DB_NAME function, as shown next below: @@SERVERNAMEIF @@SERVERNAME = ‘ProductionServerName’BEGINPRINT ‘Code will NOT execute’RETURNENDELSEBEGINPRINT ‘Code will execute’ENDDB_NAME()IF DB_NAME() = ‘ProductionServerName’BEGINPRINT ‘Code will NOT execute’RETURNENDELSEBEGINPRINT ‘Code
For a given number, it may be necessary to know the sign of the number for computation purposes. If it is positive, zero or negative, you may have respective case to work on. The signs are returned as 1, 0, -1 for positive number, zero and negative number respectively. Case
MySQL is capable of returning the result of a LIKE directly in the result set itself. For example, if you use a wildcard character in a query such as below, you get to know if the result is true or false based on the value of the resulting column. If
You can easily find tables referenced by foreign keys with a script similar to the following: SELECT = s.name + N’.’ + t.name FROM sys.tables AS t INNER JOIN sys.schemas AS s ON t.[schema_id] = s.[schema_id] WHERE EXISTS ( SELECT 1 FROM sys.foreign_keys AS fk WHERE fk.referenced_object_id = t.[object_id] );
Sp_help?provides a lot of information about the structure of the tables inside your database. You can highlight a table name in the SQL Query editor and then press the Alt + F1 key combination or you could type a command such as the following: sp_help ‘TableName’ This will produce a
POSITION is a powerful function that helps you to find the position of a sub string in a string. Typically, the string is a column in a given table and we use the POSITION function to find the sub string. Example: SELECT POSITION(” IN ) FROM ; This returns a
You can replace new lines and spaces inside a field with a statement similar to the following: REPLACE(REPLACE(LTRIM(RTRIM(FIELD_NAME)), CHAR(13), ”), CHAR(10), ”)
You can check which providers are installed on your server with this command: EXEC sp_MSset_oledb_prop