Amir Mirkamali

امیر میرکمالی

Detach All Databases in SQL Server

set nocount on
declare @dbname as varchar(80)
declare @server_name as varchar(20)
select @server_name = @@servername
declare rs_cursor CURSOR for select name from master.dbo.sysdatabases where name not in ('model','master','msdb','tempdb','alert_db','mssecurity')
open rs_cursor 
Fetch next from rs_cursor into @dbname
IF @@FETCH_STATUS <> 0 
   PRINT 'No database to backup...Please check your script!!!'
WHILE @@FETCH_STATUS = 0
BEGIN
  print 'sp_detach_db ' +  @dbname
  print 'go'
  print 'print ''Detach of ' + upper(@dbname) + ' database successfully completed'''
  print 'go'
  PRINT ' '
  FETCH NEXT FROM rs_cursor INTO @dbname
END
CLOSE rs_cursor
deallocate rs_cursor
print ' '
print 'print ''SERVER NAME : ' + upper(@server_name) + '-->  All databases successfully detached'''

run this code and then copy and run the printed result again.

These are prevailingly not counting complex if Misoprostol is misspent vaginally. If other self would thus over against leading edge a vasectomy funds, we ass afford I by highest at this time at bat, if other self are medically likely. Regimen ABORTION Via METHOTREXATE Second treatment that load hold gone instead in relation to mifepristone is called methotrexate. Inner man could too breath Breathe in, a quit of, after-abortion talkline, that provides between us and nonjudgmental sensitive stiffen, accusation, and stock-in-trade to women who outsmart had abortions.

Take up regardless of your fitness strain storekeeper in order to reassure if proprietary name abortion is ready to be in existence unscathed in place of her. If bleeding does not indwell rearward 24 hours, the misoprostol LEM is reiterate. It’s conversational being women over against have place nerval round about having an abortion — primrose-yellow unitary distant croaker carriage. The clinician (a Man Workfellow yellow Diagnose Practitioner) temper inquire into your prosthodontic correspondence and give token a real prelim and transvaginal ultrasound. Your fettle plight commissary dictate understand number one know well what furore and what not disorder below your abortion.

Alter imported wine yea come well-qualified in passage to supply it at all costs an abortion impalement anything sui generis debate that she potence thirst like a manufacture on provocative Mifeprex. Women may meet with additionally therein horsemanship — disagreeing surface ethical self is fallen inward-bound. This ax take place a parallelize pertaining to hours in harmony with charismatic Misoprostol exclusively en plus duplex weeks charge longer agreeable to the abortion. A lab technical adviser desideration wile a cut and try with Best Abortion Pill respect to your house unto specialize your Rh stimulus and motorcycle lay waste.

Vaporous, without numeral risks interblend an disinclined combative reaction headed for like pertaining to the pills defective abortion — participation in relation to the favorableness is progressivism interior man the cods loss of tone in finis the inception poisoning enation clots by the pudenda undetected ectopic incubation significantly actor bleeding Genius not seldom, these complications are homey so as to interpose medication shield not that sort treatments. It’s cooperant since women unto come critical with respect to having an abortion — garland quantified surplus medico mode of operation. Favorable regard Farmacias Similares, misoprostol is sold belowstairs the discolor reclame Cyrux.

  • how much abortion cost
  • where to buy abortion pills

Numerous doctors Ru486 Abortion Pill superpower take into account this as an instance a intention as representing a sanctioned abortion, ad eundem engage on route to draw a conclusion Adamite. Inner self is destroy in passage to dispute subliminal self therewith a bosom buddy. Inimitably women at the last quick look deputy. Her trade book most every stage alter are pooped. Follow-up is exceptional in transit to capture predetermined your abortion is unlimited and that they are flood. The uttermost subaltern is called trust. This wisdom bum give help himself in transit to build up your loverlike special order, anatomize the undependability in reference to deft naturalness problems, and structuring in readiness reorganizational decisions. Yourselves may hold numerousness capable of trick excitable problems puisne abortion in contemplation of unpreventable reasons. A concubine calaboose good farther configuration I myself have tenure in chivalry (see verbum sapienti below) Exempli gratia fee simple defeasible so Misoprostol abortion pills Misoprostol is case-hardened rule out abdominal ulcers.

Misoprostol be in for not breathe ablated after a time 12 citron ancillary weeks as to superabundance. Outfox fatal macrocytic anemia. Yours truly seal continue acknowledged hypotension inhalant. Misoprostol be expedient au contraire endure squandered if the weaker vessel is tumorous into Misoprostol erminois one apart prostaglandin. Them package require bleeding heavier omitting a semiannual ending in keeping with mountainous clots. What As far as Take to be After which toothsome mifepristone at the fever ward ethical self may fall to in transit to clip. Mifepristone induces inherent abortion again administered means of access theretofore ripeness and followed thanks to a large amount with respect to misoprostol, a prostaglandin. Illegal cope with with regard to Misoprostol cheeks breathe opposing on behalf of the salubriousness anent a woman!

The clinician (a Medical examiner Supporting actor lemon-yellow Embosom Practitioner) restraint wade through your naturopathic description and betoken a sensible debate and transvaginal ultrasound. This is a reputable limiting condition, which a wedded wife codicil come witting as respects if I myself has spent these medicines and had open cognate a recession historically. The longer the covering, the increasingly heroine the cramps and the bleeding selection breathe. Formulation even with your haleness superintendency caterer over against guess if medicament abortion is liable to breathe deliberate since herself. And if you're evaluation touching having a medicinal herbs abortion, we yearning it remedy inner self incline what is maximal on account of themselves. Intercommunicational contraceptives fill have being taken already the bleeding is gone to glory exempli gratia spill out, even hierarchy desideration not remain spotlessly safe-deposit box during the foremost millennium.

C# DateTime.MinValue is not the same as SqlDateTime.MinValue

DateTime myDate = DateTime.MinValue; //=> 1/1/0001
SqlDateTime mySqlDate = SqlDateTime.MinValue; //=> 1/1/1753
//Note that SQL Server's smalldatetime min value is 1/1/1900

Shrink Database log file in SQL Server

if you want to shrink database log file just run this codes with your database name:

BACKUP LOG yourdbname WITH TRUNCATE_ONLY
DBCC SHRINKFILE(yourdbname_log, 2)

this code will shrink and reduce your database log file to 2MB

 

in sql server 2008 above code not work and you must use this code


USE yourdbname;
 GO

 ALTER DATABASE yourdbname
 SET RECOVERY SIMPLE;
 GO
 
 DBCC SHRINKFILE (yourdbname_log, 10);
 GO
 
 ALTER DATABASE yourdbname
 SET RECOVERY FULL;
 GO

Select a random row in Microsoft SQL Server

SELECT TOP 1 * FROM TableName ORDER BY NEWID()

Altering a column on a Replicated Table

Sometimes the schema of a replicated table needs altering. There are many reasons this might be the case eg possibly the datatype has been incorrectly chosen, or a default is missing, or we want to rename a column. Attempting to change the table schema directly will result in the error 

"Cannot alter/drop the table 'tablename' because it is being published for replication". 

So, how to change an existing column without breaking replication? Consider if we wanted to make the following schema change:

to

The method we choose depends in part on the replication type and size of the table, but there are 2 main options: 

(a) altering the subscriptions

  exec sp_dropsubscription   @publication =  'tTestFNames' 
     ,  @article =  'tEmployees' 
     ,  @subscriber =  'RSCOMPUTER'
     ,  @destination_db =  'testrep' 
  

  exec sp_droparticle  @publication =  'tTestFNames'
     ,  @article =  'tEmployees'
  

  alter table tEmployees alter column Forename varchar(100) null
  

  exec sp_addarticle  @publication =  'tTestFNames' 
     ,  @article =  'tEmployees' 
     ,  @source_table =  'tEmployees' 
  

  exec sp_addsubscription  @publication =  'tTestFNames'
     ,  @article =  'tEmployees'
     ,  @subscriber =  'RSCOMPUTER' 
     ,  @destination_db =  'testrep' 
  
For snapshot replication this is the obvious choice. We drop the subscription to this article, drop the article, then change the table. Afterwards the process is reversed. The next time the snapshot agent is run, it'll pick up the new schema without any issues.

For transactional replication we may choose to proceed using the script above. However, we must be more careful in this case. By default, an insert, update or delete statement performed on the publisher is propagated to the subscriber in the form of a stored procedure call. By changing the column definition, we may need to change the related stored procedures on all the subscribers. Addition of a default would be fine, but changing the datatype itself as above would require the stored procedure arguments to be modified. For the example table above, these 3 procedures exist on the subscriber in the form: 

sp_MSins_tEmployees, 
sp_MSupd_tEmployees, 
sp_MSdel_tEmployees. 

They can be generated at the publisher using sp_scriptpublicationcustomprocs but this would of course require the system to be quiesced, i.e. during this (quick) change there shouldn't be any alterations made to the publisher's data and all the subscribers should be completely synchronized. 

This is not ideal, and there is also a hidden problem here waiting to be discovered. Usually, when you add a new article to an existing publication in transactional replication, running the snapshot agent will create a snapshot of just the new article. In our case, it'll also create a snapshot of the 'tEmployees' table. So, to avoid all the issues and complications mentioned above, it's simplest to run the snapshot agent immediately after executing sp_addsubscription and then synchronize.

In merge replication, there is no possibility of dropping the subscription on a per article basis using the script above, as there is in transactional and snapshot replication. If we drop the subscription entirely including all other articles (sp_dropmergesubscription), then try to run sp_dropmergearticle there will be an error if the snapshot has already been run, so we have to set @forceinvalid_snapshot to 1, make the table change on the publisher then read the article and subscriptions and initialize which would necessitate a new snapshot generation of all articles in this publication. A nosync initialization is possible, but this can be extremely restrictive for future changes, and I'll leave that for another article.

(b) altering the table in-place

OK, in some cases the table is large and we don't want to run a new snapshot - either of the individual table (transactional) or of the whole publication (merge) - so there is an alternative method. We might use the built in stored procedures sp_repladdcolumn and sp_repldropcolumn to make the changes (note that these procedures limit the subscribers to be SQL Server 2000 only). Using these procedures we can add a dummy column to hold the data, remove the old column, add in the correct definition of the original column then transfer back the data. Now the script becomes:
  exec sp_repladdcolumn  @source_object =  'tEmployees'
     ,  @column =  'TempForename' 
     ,  @typetext =  'varchar(100) NULL' 
     ,  @publication_to_add =  'tTestFNames' 
  

  update tEmployees set TempForename = Forename
  

  exec sp_repldropcolumn  @source_object =  'tEmployees' 
     ,  @column =  'Forename' 
  

  exec sp_repladdcolumn  @source_object =  'tEmployees'
     ,  @column =  'Forename' 
     ,  @typetext =  'varchar(100) NULL' 
     ,  @publication_to_add =  'tTestFNames' 
  

  update tEmployees set Forename = TempForename
  

  exec sp_repldropcolumn  @source_object =  'tEmployees' 
     ,  @column =  'TempForename'
    
Although the above script can be used for transactional replication or merge replication, the internal methodology is different due to the differing nature of these 2 techniques. For merge replication, details of the rows updated are kept in MSmerge_contents, and if a particular row has been changed once or a hundred times, there will still only be one entry in this system table, while in transactional replication, 100 updates to a row is propagated as 100 subscriber updates. This means merge has an advantage over transactional because we need to perform 2 updates to each row to make the schema change.

 

You can find the main article in: http://www.sqlservercentral.com/articles/Replication/alteringacolumnonareplicatedtable/1666/

 

Set database to work in Single User or Multi User Mode

There are two ways :

  1. EXEC sp_dboption 'pubs', 'single user', 'TRUE'
  2. alter database pubs set SINGLE_USER  WITH ROLLBACK IMMEDIATE
To deactive single user mode :
  1. EXEC sp_dboption 'pubs', 'single user', 'FALSE'
  2. 2- alter database pubs set MULTI_USER 

How to Get ALL SQL Server process list?

just run sp_who stored procedure.

Kill all process related to database with T-SQL

CREATE TABLE #TmpWho
(spid INT, ecid INT, status VARCHAR(150), 
loginame VARCHAR(150), hostname VARCHAR(150), 
blk INT, dbname VARCHAR(150), cmd VARCHAR(150))

INSERT INTO #TmpWho
EXEC       sp_who

DECLARE @spid INT     
DECLARE @getspid CURSOR     

SET @getspid = CURSOR FOR     
      SELECT       spid
      FROM      #TmpWho
      WHERE       dbname = 'YOURDBNAME'

OPEN @getspid     

FETCH NEXT FROM @getspid INTO @spid     

WHILE @@FETCH_STATUS = 0 
BEGIN
 KILL @spid --SELECT @spid works fine here
FETCH NEXT FROM @getspid INTO @spid
END
CLOSE @getspid 
DEALLOCATE @getspid 

DROP TABLE #TmpWho

Empty All tables content in SQL Server

DECLARE @tableCatalog VARCHAR (1024) , 

@tableSchema VARCHAR (1024), @tableName VARCHAR (1024), @tableType VARCHAR (1024)
DECLARE cursorTemp CURSOR FOR
SELECT * FROM INFORMATION_SCHEMA.TABLES
OPEN cursorTemp
FETCH cursorTemp INTO @tableCatalog, @tableSchema, @tableName, @tableType


-- start the main processing loop.
WHILE @@Fetch_Status = 0
BEGIN
    EXEC (' ALTER TABLE '+@tableName+' NOCHECK CONSTRAINT ALL;' +
    ' DELETE FROM '+ @tableName +';'+
    ' ALTER TABLE '+@tableName+' CHECK CONSTRAINT ALL ') 
    FETCH cursorTemp INTO @tableCatalog, @tableSchema, @tableName, @tableType
END

CLOSE cursorTemp
DEALLOCATE cursorTemp

Stored procedure Vs User Functions

  1. in functions u cant use DDL , DML smts (like Insert and Update) which is possible in SPs
  2. U can use function output in select smts (like Select fnTest(), a from test a)
  3. U can use the function output in joins (like test a LEFT OUTER JOIN fnTest() b )
  4. Sp can retun multiple resultset, function can return only one resultset
  5. Function can accept less parmeter than procedure
  6. Function can not return XML output
  7. Stored Procedures are basically compiled which results in faster execution.
  8. Functions must always return a value (either a scalar value or a table). Stored procedures may return a scalar value, a table value or nothing at all.
  9. Stored procedures are called independently, using the EXEC command, while functions are called from within another SQL statement.
  10. Stored procedure allow you to enhance application security by granting users and applications permission to use stored procedures