Most 1s in SQL Server datetime value

Today is one of those rare days where you can see a lots of 1s in the date i.e, 11/11/2011. To add to that, the clock ticks 11:11:11 everyday, so I planned to capture the SQL Server datetime value returned by GETDATE() function. As I have to execute GETDATE() function at that exact moment, which is very unlikely, I used WAITFOR TIME statement as shown below..

Do you like this site? Like our FB page @ Facebook.com\LearnSQLWithBru so that, you know when there is a new blog post.

— Bru Medishetty

List of all Data and Log Files of a SQL Instance

Ever faced a sitaution where you had to find out all the database files (Data and Log) of a SQL Instance?

I came across this situaion many times, especially when I am working with a new SQL Instance which was taken over by my team OR when the previous admin of that box has left the company and its now my turn to maintain / administer that instance.

In order to list the files, we just need to query the system table sysaltfiles.  The picture below is a screen show that I ran earlier today on one of my SQL Instances.

SELECT * FROM SYSALTFILES

This  query can be further tweaked to get only the data files or only the log files by adding where clause and filter by griupid column. Groupid = 1 indicates it is a data file and groupid = 0 indicates it is a log file.

Do you like this site? Like our FB page @ Facebook.com\LearnSQLWithBru so that, you know when there is a new blog post.

– Bru Medishetty

Dropping a Column from a table using T-SQL – SQL Server

This blog explains how to drop a column from a table using T-SQL query. It might be easy to do it from SSMS, on the other side, it is not always convenient to do it from SSMS. When you have to repeat the task of dropping additional columns at a later time, you will have to go back to the object explorer repeatedly and choose those column to be dropped, where as using T-SQL query you just need to change the column name to be dropped. Now let’s look at the script to do it.

ALTER TABLE EmployeeTable DROP COLUMN Gender 
Go

The Syntax to drop a table column is quite simple, it goes this way ALTER TABLE YOURTABLENAME DROP COLUMN YOURCOLUMN“.

To use the code in this example, first you will need to create the table EmployeeTable using the script in another blog Creating Primary Key in a SQL Server table

Do you like this site? Like our FB page @ Facebook.com\LearnSQLWithBru so that, you know when there is a new blog post.

–Bru Medishetty