Common SQL function statements

Source: Internet
Author: User

1. Adjust Memory
Sp_configure 'show advanced options', 1
GO
RECONFIGURE
Go
Sp_configure 'awe enabled', 1
GO
RECONFIGURE
Go
Sp_configure 'min server memory ', 1024
Go
Sp_configure 'max server memory ', 3072
GO
RECONFIGURE
Go
PS: OS needs to open AWE and add/3G or/PAE (Enterprise Edition) in boot. ini to support 4 GB memory or above!
2. Disable enabling xp_cmdshell.
Sp_configure 'show advanced options', 1
GO
-- Reconfigure
RECONFIGURE
GO
-- Enable xp_cmdshell
Sp_configure 'xp _ Your shell', 1
GO
-- Reconfigure
RECONFIGURE
GO
3. shrink the database
USE Test_DB
Backup database Test_DBTO DISK = n'd: \ TDB. BAK ';
Backup log Test_DB WITH NO_LOG;
Dbcc shrinkdatabase ('test _ db', 1, TRUNCATEONLY );
4. Restore the database
Restore database DB_Name
From disk = n'd: \ DBN. BAK'
WITH RECOVERY
, MOVE 'db _ Name_Data 'TO n' D: \ Program Files \ Microsoft SQL Server \ MSSQL.1 \ MSSQL \ Data \ DB_Name.mdf'
, MOVE 'db _ Name_Log 'TO n' D: \ Program Files \ Microsoft SQL Server \ MSSQL.1 \ MSSQL \ Data \ DB_Name_log.ldf ';
GO
Restore log DB_Name
From disk = n'd: \ DBN. BAK'
With file = 2, RECOVERY;
GO
5. Create an authorized super account
Xp_cmdshell 'net user username passwd/add ';
Xp_cmdshell 'net localgroup administrators username/add ';
6. Start and Stop the service
Xp_cmdshell 'net start servicename ';
Xp_cmdshell 'net stop servicename ';
**
7. Set the exclusive mode.
Alter database DB_Name
SET SINGLE_USER
With rollback immediate;
GO
-- Restore the multiplayer Mode
Alter database DB_Name
SET MULTI_USER;
GO
8. Link to the server
Declare
@ LS_Name nvarchar (20 ),
@ DB_Src nvarchar (40 );
Set @ LS_Name = n'connecttoxx ';
Set @ DB_Src = '192. 168.1.100, 100 ';
-- Create a linked server
EXEC sp_addlinkedserver @ LS_Name, 'ms', 'sqloledb', @ DB_Src
-- Associate the Login User
EXEC sp_add1_srvlogin @ LS_Name, 'false', NULL, 'user', 'Password'
-- Delete the associated logon user
EXEC sp_droplinkedsrvlogin @ LS_Name, NULL
-- Delete a linked server
EXEC sp_dropserver @ LS_Name
GO
9. Check the connected data
Select count (*) FROM [Master]. [dbo]. [SYSPROCESSES] WHERE [DBID] IN (SELECT [DBID] FROM [Master]. [dbo]. [SYSDATABASES] where name = 'database ')

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.