Quantcast
Channel: ElectricWaffle » Quick and Dirty T-SQL
Browsing all 9 articles
Browse latest View live

Quick and Dirty Altering all tables in a database using T-SQL

Sometimes you want to make changes across all tables in a particular database. For example, lets say you’ve got a database that was replicated and now its not and you want to strip the...

View Article



Image may be NSFW.
Clik here to view.

Quick and Dirty monitoring – Using T-SQL to peform basic login monitoring

Its important for security to monitor unused logins on SQL. Only logins which need to be there should be there. There are a number of ways to monitor the which logins are using used but these methods...

View Article

Quick and Dirty monitoring – Recording Failing Login attempts using T-SQL

You could check the SQL logs for failed login attempts but searching through those can be a pain. Far easier to make use of the following stored procedure, EXEC xp_readerrorlog 0, 1, 'Login failed'...

View Article

Image may be NSFW.
Clik here to view.

Quick and Dirty attach a CSV in database mail

Insert your query and away you go EXEC msdb. dbo.sp_send_dbmail    @profile_name = '<<NAME>>' ,    @recipients = '<<RECIPIENTS>>' ,    @query = '<<QUERY>>' ,...

View Article

Image may be NSFW.
Clik here to view.

Quick and Dirty – View Query Plans using T-SQL

Query plans possess vital information which can help a DBA to make optimization decisions. The T-SQL below will retrieve the query plan for database of your choice. By extending the where clause in the...

View Article


Image may be NSFW.
Clik here to view.

Quick and Dirty Using BCP to export CSV files

Ta-Dah! The  switches below in the BCP statement export the results of the query to CSV BCP "select * from table" QUERYOUT "C:\TEST.csv" -c -t"," -r"\n" -T -S server      

View Article

Quick and Dirty exporting XML using BCP

Last post on BCP tonight promise  . . . There are *many* ways of exporting an XML file from SQL, adding the section in bold below to the select in a BCP command will create XML from the search results....

View Article

Capturing the error message from XP_CMDSHELL

Using XP_CMDSHELL we can run commands that could otherwise be run using Windows Scheduled Tasks. It is kick ass, what makes this even more kick ass is being able to capture the errors running these...

View Article


Image may be NSFW.
Clik here to view.

Kick Arse Deadlock Query

I thought the only way to get Deadlock info out of SQL was to enable trace flags 1204 and 1222 (see http://technet.microsoft.com/en-us/library/ms178104(v=sql.105).aspx) but this isn’t actually the case...

View Article

Browsing all 9 articles
Browse latest View live




Latest Images