我无法打开我的SQL服务器配置管理器收到此错误消息:
Cannot connect to WMI provider. You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager.
Invalid
Run Code Online (Sandbox Code Playgroud)
我搜索了在线资料并按照建议运行了mofcomp命令: mofcomp “C:\Program Files (x86)\Microsoft SQL Server\120\Shared\sqlmgmproviderxpsp2up.mof”
我现在收到此错误消息:
MOF file has been successfully parsed
Storing data in the repository…
An error occurred while processing item 10 defined on lines 73 – 79 in file C:\Program Files (x86)\Microsoft SQL Server\120\Shared\sqlmgmproviderxpsp2up.mof:
Compiler returned error 0x80070005Error Number: 0x80070005, Facility: …
Run Code Online (Sandbox Code Playgroud) 我有一个 sql 代码来删除架构和用户,见下文:
USE [DB1]
GO
--SELECT * FROM sys.schemas s WHERE s.principal_id = USER_ID('ITAdmin')
WHILE EXISTS (SELECT * FROM sys.schemas s WHERE s.principal_id = USER_ID('ITAdmin'))
BEGIN
DECLARE @tmpSchemaHolderToBeDroppedOrChanged NVARCHAR(100), @tmpAlterSchemaAuthorisationStatement NVARCHAR(200)
SET @tmpAlterSchemaAuthorisationStatement = 'DROP SCHEMA '
SET @tmpSchemaHolderToBeDroppedOrChanged = (SELECT TOP 1 s.name FROM sys.schemas s WHERE s.principal_id = USER_ID('ITAdmin'))
IF @tmpSchemaHolderToBeDroppedOrChanged = 'ITAdmin'
BEGIN
PRINT 'Dropping ITAdmin schema.'
IF schema_id('ITAdmin') IS NOT NULL
BEGIN
DROP SCHEMA ITAdmin;
PRINT 'ITAdmin schema has been dropped.'
END
END
ELSE
BEGIN …
Run Code Online (Sandbox Code Playgroud) 如果我的 SQL mdf 数据文件的剩余可用空间小于 2000 MB,我尝试设置警报。见下文:
\n\n$SQLInstances = "A","B","C"\n\n$SQLQuery = " USE DB\n SELECT CONVERT(DECIMAL(10, 2), CAST(CAST(10240 - size/128.0 AS NVARCHAR(50)) + size/128.0 - CAST(FILEPROPERTY(name, \'SpaceUsed\') AS INT)/128.0 AS NVARCHAR(50))) AS ActualSpaceAvailableMB\n FROM sys.database_files\n WHERE name = \'DB\'"\n\n$login = "XYZ"\n$password = "123" | Convertto-SecureString -AsPlainText -Force\n$creds = New-Object System.Management.Automation.Pscredential -Argumentlist $login,$password\n$SMTPServer = "10.0.0.0.0.0" # This is your SMTP Server \n$to = "ME@ME.COM"# This is the recipient smtp address 1\n$from = "NOREPLY@YOU.COM" # This will be the sender\xc3\x82\xc2\xb4s address \n\nforeach …
Run Code Online (Sandbox Code Playgroud) 我有以下powershell查询:
$sql = "select name, lastName, City, Address from Persons"
$TotalPeople = Invoke-Sqlcmd -ServerInstance $ResultsInstance -Database $ResultsDatabase -Query $sql
Write-Output "Total number of people run is $TotalPeople "
Run Code Online (Sandbox Code Playgroud)
我希望能够计算$ TotalPeople变量中的行数.有没有办法在powershell中做到这一点?
我试图将 Option Recompile 放在 WHERE 子句之后,但由于语法错误而一直失败: Incorrect Syntax near recompile. Expecting ( or SELECT
这是我的sql代码:
IF EXISTS (SELECT 1 FROM Table1 WHERE Code = @Code AND Activity = 'T' OPTION (RECOMPILE))
Run Code Online (Sandbox Code Playgroud)
我知道在很多情况下,如果没有 AND 条件它会起作用。我在网上搜索了一个没有任何有用信息的解决方案。有任何想法吗?