Writing Sql Results to Excel Sheet

Its a one line query which writes the result set to Excel Sheet. OpenRowSet loads the driver, open Excel connection string and writes the data into specified location. INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0’, ‘Excel 8.0;database=C:\test.xls’, ‘SELECT * FROM [Sheet1$B4:D4]’) SELECT ‘aaa’, ‘bbb’, ‘ccc’ –Select statement can be replaced with your own Select Statement from the database… Read More Writing Sql Results to Excel Sheet

Get the Foreign Key constraint name

If Foreign Key constraints doesn’t have any fixed names and you need the names dynamically through the SQL Query, which may be useful for deployment point of view. They can be obtained as follows: SELECT FK_TableĀ  = FK.TABLE_NAME, FK_Column = CU.COLUMN_NAME, PK_TableĀ  = PK.TABLE_NAME, PK_Column = PT.COLUMN_NAME, Constraint_Name = C.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C INNER JOIN… Read More Get the Foreign Key constraint name