Wednesday 29 October 2014

How to Delete all the Tables and Stored Procedures in Sql Server 2008

How to delete or drop all tables from a SQL Server database using just a SQL query.


The following SQL will delete all the tables and their associated information from a database.

USE [database]
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
The only downside to this is that you cannot perform a rollback, so you need to make sure this is what you want to do. Otherwise, that’s all there is to it. Just run this in a New Query Window in SQL Server Management Studio (SSMS) and you’re done.


Sql Scripts - Delete all Tables, Procedures, Views and Functions

Friday, August 20, 2010SQL Server T-SQL
In a shared environment you typically don't have access to delete your database, and recreate it for fresh installs of your product.
I managed to find these scripts which should help you clean out your database.
Use at your own risk.

Delete All Tables

--Delete All Keys

DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
WHILE (@@FETCH_STATUS = 0)
BEGIN
Exec SP_EXECUTESQL @Sql
FETCH NEXT FROM @Cursor INTO @Sql
END
CLOSE @Cursor DEALLOCATE @Cursor
GO
EXEC sp_MSForEachTable 'DROP TABLE ?'
GO

Delete All Stored Procedures

declare @procName varchar(500)
declare cur cursor
  for select [name] from sys.objects where type = 'p'
open cur

fetch next from cur into @procName
    while @@fetch_status = 0
    begin
          if @procName <> 'DeleteAllProcedures'
                exec('drop procedure ' + @procName)
                fetch next from cur into @procName
    end

close cur
deallocate cur

Delete All Views

declare @procName varchar(500)
declare cur cursor
  for select [name] from sys.objects where type = 'v'
open cur

fetch next from cur into @procName
    while @@fetch_status = 0
    begin
                exec('drop view ' + @procName)
                fetch next from cur into @procName
    end
close cur
deallocate cur

Delete All Functions

declare @procName varchar(500)
declare cur cursor
  for select [name] from sys.objects where type = 'fn'
open cur

fetch next from cur into @procName
    while @@fetch_status = 0
    begin
                exec('drop function ' + @procName)
                fetch next from cur into @procName
    end

close cur
deallocate cur


Delete All SP

DECLARE @sql NVARCHAR(MAX) = N''; SELECT @sql += N'DROP PROCEDURE dbo.' + QUOTENAME(name) + '; ' FROM sys.procedures WHERE name LIKE N'sp[_]%' AND SCHEMA_NAME(schema_id) = N'dbo'; EXEC sp_executesql @sql;

Tuesday 28 October 2014

Creating your first Windows Phone Applications

Creating your first Windows Phone app
Introduction
This tutorial will explain how to create your first Windows Phone app using Expression Blend.
How to...
  • Start with the new project
  • Select ‘Windows Phone Application’
  • Assign some suitable name to the application
  • Click Finish
  • You should land up with the same screen like in the previous tutorial.
  • Set the view percentage to suitable value
  • Delete both the TextBlock controls from page
  • Drag a button from ToolBox to the page
  • Click on the button to reposition it at the bottom center, using Selection Tool
  • Click two times inside the button and change its title to “About”
  • Select button with selection tool
  • See all the events offered by button in properties window
  • Double click on empty click event to add event handler
  • Observe the click event handler function in the class called as MainPage
  • MainPage is derived from PhoneApplicationPage
  • Type following line of code in the click event handler function
MessageBox.Show("MyFirst WP application !");
  • Press F5 to run and test the app developer so far. Result will be as shown below
Above image explains how the application will appear in emulator
  • Click on XAML page to go to design of the page
  • Drag a TextBlock and two Buttons on Page and place them on page
  • User Selection too to reposition them on page
  • Select the TextBlock and set its name property as “txtCount” ( this will be used to change the Properties of TextBlock)
  • Change name of first Button to “btnUp” and second to Button to “btnDown” by selecting the Buttons one by one
  • Click two times (not the double click) on the Button to change title of first Button as “up” and then second Button to “down”
  • Click two times on TextBlock and change the title to “0”
  • Now select Button first “btnUp” and goto “click” event in property window
  • Double click on property window to add click event handler
  • Change the code as follows then press F5 and test the app.
  • Now switch to design view select second Button “btnDown” and goto “click” event in property window
  • Double click on property window to add click event handler
  • Change the code as follows then press F5 and test the app.

This finishes the application which counts up the counter and down.