SQL Server dba Common commands

Source: Internet
Author: User

Sp_lock
sp_who
Sp_who2
Sp_who2 ' active ';
DBCC INPUTBUFFER (64)

-- check for blocked spid

Select Blocking_session_id,wait_duration_ms,session_id,wait_type from
Sys.dm_os_waiting_tasks
Where blocking_session_id is not null

-- search for spid content

sp_who spid

-- unblock spid

KILL spid

-- search for spid content

DBCC InputBuffer (spid)


-- create account in this machine Test

CREATELOGIN[Test] withPASSWORD=N ' a123456 ',Default_database=[Workflow],Check_policy=OFF

GO


-- Create an account in the library if it's a bak file or an additional repository, you don't need this.

Use Workflow

GO

CREATE USER [test] for LOGIN [test]

GO

-- repair Orphaned account

Use Workflow

GO

execute sp_change_users_ Login ' Update_One ' test test

GO


-- empowering dbo rights

Use [Workflow]

GO

EXEC sp_addrolemember N ' db_owner ' , N ' Test '

GO


-- Show information about the archive

sp_helpdb Workflow


/* View Log size */

DBCC SQLPERF (logspace)

GO


-- cut transaction records

BACKUP LOG ' Datadasename ' with no_log

BACKUP LOG ' Datadasename ' with truncate_only

-- The above two phrases will intercept the transaction records, as long as they are executed, the transaction record is not successful until the next complete preparation!

-- subtract log the size of the file (LOG file name reduced by up to

DBCC Shrinkfile (beedb_log,+)


/******** The position of the DB ********/

-- Check the location of DB

Selectname,Physical_name fromSYS.master_fileswheredatabase_id=db_id(' Salepony ')

-- swap out the location of the DB

Alter Database Sale

modify file Span style= "color: #808080;" > ( name = sale filename Span style= "color: #808080;" >= L:\DataBase\dbfile\ Sale.mdf ' )

Go

Alter Database Sale

modify file Span style= "color: #808080;" > ( name = sale_log Span style= "color: #808080;" > filename Span style= "color: #808080;" >= L:\DataBase\translog\ Sale.ldf ' )

Go

/* Modify the Repository password * /

Alterlogin[SA]withpassword=N ' newpassword '

-old password can not be provided





SQL Server dba Common commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.