[Memo★Database: database-related memos

Source: Internet
Author: User
Truncate database logs
Alter database edmdb
Set recovery simple; -- set the simple recovery mode
Go
DBCC shrinkfile (edmdb_log, 1); -- use this statement to obtain names marked in red: Select * From SYS. database_files
Go
Alter database database_name
Set recovery full; -- restore to original mode
Go
Use strings as in statement parameters during stored procedures

Problem description: In the stored procedure, use a string as the in statement parameter and directly pass the parameter either with a syntax error or with incorrect results.

Solution: it can be implemented in disguise using the charindex function.

Where charindex (ID, @ id_array)> 0 is equivalent to where ID in (@ id_array)

 

Unexpected database termination, displaying "suspicious" Solutions
ALTER DATABASE DBName  SET EMERGENCY ALTER DATABASE DBName  SET SINGLE_USERDBCC CheckDB (DBName  , REPAIR_ALLOW_DATA_LOSS) ALTER DATABASE DBName  SET MULTI_USER 

 

Database restoration error: "unable to obtain exclusive access to the database because the database is in use" SOLUTION
Declare @ dbname varchar (20) set @ dbname = 'cshow '-- change the name of the database that occupies the connection to declare @ SQL nvarchar (500) declare @ spid int -- The spid value is a unique Integer Set @ SQL = 'descare getspid cursor forselect spid from sysprocesses where dbid = db_id (' ''' + @ dbname + ''') 'exec (@ SQL) Open getspidfetch next from getspid into @ spidwhile @ fetch_status <>-1 -- if the fetch statement does not fail to be executed or this row is not in the result set. Beginexec ('Kill '+ @ spid) -- terminate the normal connection fetch next from getspid into @ spidendclose getspiddeallocate getspid

 

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.