Archive for the ‘SQL’ Category

09/25/13
Fahad Zia
tags:  

Create nullable columns using SELECT INTO


SELECT
CAST('' AS nvarchar(10)) AS Col1
,CAST('' AS nvarchar(100)) AS Col2
,CAST('' AS int) AS Col3
,CAST('' AS bit) AS Col4
INTO Test
WHERE 1=2

nullable_columns_table

11/03/11
Fahad Zia
tags:  

List Stored Procedures by Modified Date


SQL Server 2005:

SELECT * FROM sys.objects WHERE type = 'P' ORDER BY modify_date  DESC

SQL Server 2000:

SELECT * FROM sysobjects WHERE type='P' ORDER BY crdate DESC; -- refdate supposedly should be the date modified column but both return the same date

If you notice in SQL 2000, crdate and refdate show the same date so there is no way to sort by date modified with the above query

11/13/10
Fahad Zia

Running large T-SQL files using SQLCMD


Recently I had to export data and schema of one of the databases ,which I did not have direct access to, using sql publishing wizard. The exported file was 400 MB and using SQL Server 2005 I was not able to import all data as it would complain about memory issues opening this file. I had to use SQLCMD -i command to import this file.
More info on how to run sql queries using SQLCMD can be viewed here: http://msdn.microsoft.com/en-us/library/ms170207.aspx