Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 428 Vote(s) - 3.57 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hidden Features of SQL Server

#1
What are some hidden features of [SQL Server][1]?

For example, undocumented system stored procedures, tricks to do things which are very useful but not documented enough?


----------

## Answers ##

*Thanks to everybody for all the great answers!*

**Stored Procedures**

- **sp_msforeachtable:** Runs a command with '?' replaced with each table name (v6.5 and up)
- **sp_msforeachdb:** Runs a command with '?' replaced with each database name (v7 and up)
- **sp\_who2:** just like sp_who, but with a lot more info for troubleshooting blocks (v7 and up)
- **sp_helptext:** If you want the code of a stored procedure, view & UDF
- **sp_tables:** return a list of all tables and views of database in scope.
- **sp_stored_procedures:** return a list of all stored procedures
- **xp_sscanf:** Reads data from the string into the argument locations specified by each format argument.
- **xp_fixeddrives:**: Find the fixed drive with largest free space
- **sp_help:** If you want to know the table structure, indexes and constraints of a table. Also views and UDFs. Shortcut is Alt+F1

**Snippets**

- Returning rows in random order
- All database User Objects by Last Modified Date
- Return Date Only
- Find records which date falls somewhere inside the current week.
- Find records which date occurred last week.
- Returns the date for the beginning of the current week.
- Returns the date for the beginning of last week.
- See the text of a procedure that has been deployed to a server
- Drop all connections to the database
- Table Checksum
- Row Checksum
- Drop all the procedures in a database
- Re-map the login Ids correctly after restore
- Call Stored Procedures from an INSERT statement
- Find Procedures By Keyword
- Drop all the procedures in a database
- Query the transaction log for a database programmatically.

**Functions**

- HashBytes()
- EncryptByKey
- PIVOT command

**Misc**

- Connection String extras
- TableDiff.exe
- Triggers for Logon Events (New in Service Pack 2)
- Boosting performance with persisted-computed-columns (pcc).
- DEFAULT_SCHEMA setting in sys.database_principles
- Forced Parameterization
- Vardecimal Storage Format
- Figuring out the most popular queries in seconds
- Scalable Shared Databases
- Table/Stored Procedure Filter feature in SQL Management Studio
- Trace flags
- Number after a `GO` repeats the batch
- Security using schemas
- Encryption using built in encryption functions, views and base tables with triggers


[1]:

[To see links please register here]

Reply

#2
Here are some features I find useful but a lot of people don't seem to know about:

sp_tables

> Returns a list of objects that can be
> queried in the current environment.
> This means any object that can appear
> in a FROM clause, except synonym
> objects.

[Link][1]

sp_stored_procedures

> Returns a list of stored procedures in
> the current environment.

[Link][2]


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
Simple encryption with [EncryptByKey][1]


[1]:

[To see links please register here]

Reply

#4
sp_who2, just like sp_who, but with a lot more info for troubleshooting blocks
Reply

#5
/* Find the fixed drive with largest free space, you can also copy files to estimate which disk is quickest */

EXEC master..xp_fixeddrives

/* Checking assumptions about a file before use or reference */

EXEC master..xp_fileexist 'C:\file_you_want_to_check'

[More details here][1]


[1]:

[To see links please register here]

Reply

#6
Connection String extras:

**MultipleActiveResultSets=true;**

This makes ADO.Net 2.0 and above read multiple, forward-only, read-only results sets on a single database connection, which can improve performance if you're doing a lot of reading. You can turn it on even if you're doing a mix of query types.

**Application Name=MyProgramName**

Now when you want to see a list of active connections by querying the sysprocesses table, your program's name will appear in the program_name column instead of ".Net SqlClient Data Provider"


Reply

#7
A semi-hidden feature, the Table/Stored Procedure Filter feature can be really useful...

In the **SQL Server Management Studio** *Object Explorer*, right-click the **Tables** or **Stored Procedures** folder, select the **Filter** menu, then **Filter Settings**, and enter a partial name in the *Name contains* row.

Likewise, use **Remove Filter** to see all Tables/Stored Procedures again.
Reply

#8
Find records which date falls somewhere inside the current week.

where dateadd( week, datediff( week, 0, TransDate ), 0 ) =
dateadd( week, datediff( week, 0, getdate() ), 0 )

Find records which date occurred last week.

where dateadd( week, datediff( week, 0, TransDate ), 0 ) =
dateadd( week, datediff( week, 0, getdate() ) - 1, 0 )

Returns the date for the beginning of the current week.

select dateadd( week, datediff( week, 0, getdate() ), 0 )

Returns the date for the beginning of last week.

select dateadd( week, datediff( week, 0, getdate() ) - 1, 0 )
Reply

#9
Drop all connections to the database:

Use Master
Go

Declare @dbname sysname

Set @dbname = 'name of database you want to drop connections from'

Declare @spid int
Select @spid = min(spid) from master.dbo.sysprocesses
where dbid = db_id(@dbname)
While @spid Is Not Null
Begin
Execute ('Kill ' + @spid)
Select @spid = min(spid) from master.dbo.sysprocesses
where dbid = db_id(@dbname) and spid > @spid
End
Reply

#10
Table Checksum

Select CheckSum_Agg(Binary_CheckSum(*)) From Table With (NOLOCK)

Row Checksum

Select CheckSum_Agg(Binary_CheckSum(*)) From Table With (NOLOCK) Where Column = Value
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through