Showing posts with label Data Base. Show all posts
Showing posts with label Data Base. Show all posts
0
Posted on 5:20 AM by prajeesh and filed under ,
Here is the SQL query to create a stored procedure that deletes all stored procedures in a database


create procedure dropallsp as
declare @procName varchar(500)
declare cur cursor
for Select [name] from sys.procedures where [type] = 'P' and is_ms_shipped = 0 and [name] not like 'sp[_]%diagram%'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur
Shout it kick it on DotNetKicks.com
0
Posted on 5:13 AM by prajeesh and filed under ,
Here is an easy way to drop all tables in a database using a single query.

exec sp_msforeachtable 'Drop table ?'

As it is an undocumented stored procedure it may be get removed any time without any notification. Shout it kick it on DotNetKicks.com
0
Posted on 2:23 AM by prajeesh and filed under ,
This is one of the common requirement for DBA's or Programmers,How to import a .csv file into SQL Server data base,we can do this by bulk insert sql command ,let me explain the steps to do this.










suppose this is our .csv file and we want to import address data from this file(note:fields are separated by commas).
Next step is to create a table in your database for importing

CREATE TABLE address(name varchar(50),place varchar(50),zipcode int)

GO
in the next step we will import data from csv file,open your sql server Query Analyzer and give query as shown in the figure below










the query is
BULK INSERT address FROM 'C:\address.csv'
WITH(FIELDTERMINATOR = ',',ROWTERMINATOR = '\n'
)
GO


you can check the data using SELECT command(select * from address)

enjoy




Shout it kick it on DotNetKicks.com