Thursday, April 18, 2013

Visual Studio 2008 Expand And Collapse All The Sections Of Code ShortCuts


Some Of ShortCuts That Might Be Useful For .net Developers


CTRL + M + O will collapse all.
CTRL + M + L will expand all.
CTRL + M + P will expand all and disable outlining.
CTRL + M + M will collapse/expand the current section.
These options are also in the context menu under Outlining.

Saturday, April 13, 2013

How to Find The Primary Key And Foreign In A Database


Finding The Primary And Foreign Keys Of All Tables In A Database.


SELECT
    K_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 INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK
    ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK
    ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU
    ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (
            SELECT
                i1.TABLE_NAME,
                i2.COLUMN_NAME
            FROM
                INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
            INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2
                ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
            WHERE
                i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
           ) PT
    ON PT.TABLE_NAME = PK.TABLE_NAME

Monday, April 8, 2013

How To View The Definition Of A Stored Procedure In Sql


To View The Definition Of A Stored Procedure In Transact Sql Using Query Editor


USE DatabaseName;
GO
EXEC sp_helptext N'DatabaseName.dbo.ProcedureName';

What Is The Connection String To Connect The Excel File With Extensions .XLS or .XLSX or .CSV in C#, ASP.Net ?


Connection Strings to Read XLS And XLSX And CSV File In C#,ASP.NET



To Upload CSV File:

string CSVconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPathofFileCsv + @";Extended Properties='text;HDR=Yes;FMT=Delimited(,)';";

To Upload XLS File:


string XLSconnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " + strPathofFileXls + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"";

To Upload XLSX File:


string XLSXconnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strPathofFileXlsx + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";


                        



Saturday, April 6, 2013

How to Delete All Stored Procedure From A Database At a Time


declare cur_dropProc cursor
scroll for
select [name] from sysobjects where xtype='p'



open cur_dropProc
go
Declare @procName varchar(500)
fetch first from cur_dropProc into @procName
while @@fetch_status=0
begin
Exec('drop procedure ' + @procName)
fetch next from cur_dropProc into @procName
end
go
close cur_dropProc
go
deallocate  cur_dropProc

How To Delete All Tables In A Database Using sql


To Delete All Tables In A Database At a time Using One Query.

USE [database name]
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"

How To Get All Table Names In A Database Using sql.

Here Is The Best Way To Get All Table Names , Procedure Names , Views etc.., Using Following Query.



SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'

And For Other Object Types


C    : Check constraint
D    : Default constraint
F     : Foreign Key constraint
L     : Log
P     : Stored procedure
PK  : Primary Key constraint
RF  : Replication Filter stored procedure
S     :System table
TR   : Trigger
U     : User table
UQ  : Unique constraint
V     : View
X     : Extended stored procedure