简体   繁体   English

如何通过SQL Server Management Studio Studio对您的数据库运行SQL语句?

[英]How to run SQL statements via SQL Server Management Studio studio against your database?

We have a SQL Server instance hosted offsite and we do not have access to the actual server environment. 我们有一个SQL Server实例在异地托管,我们无权访问实际的服务器环境。 We needed to try and speed up the server's responsiveness and their helpdesk sent us this: 我们需要尝试加快服务器的响应速度,他们的服务台向我们发送了以下信息:

Run the following via SQL via SQL Server Management Studio against your iMIS database: 通过SQL Server Management Studio通过SQL对您的iMIS数据库运行以下命令:

SELECT 
    OBJECT_NAME(parent_id) AS TableName,
    name AS TriggerName,
    create_date AS CreationDate,
    modify_date AS ModifyDate
FROM 
    sys.triggers

Questions: Wouldn't we have to have access to the SQL Server in order to run that code? 问题:我们是否不必访问SQL Server即可运行该代码? Does that code make sense? 该代码有意义吗? Would it speed up our database? 会加快我们的数据库速度吗?

You just need to be able to connect to the database server from your local instance of SSMS. 您只需要能够从本地SSMS实例连接到数据库服务器。 You just need to put in the "Server Name" and Authenticate yourself to the server before you can run this query. 您只需要输入“服务器名称”并向服务器身份验证即可运行此查询。

You might need proper permissions to be able to run these statements. 您可能需要适当的权限才能运行这些语句。 But you can give it a try. 但是您可以尝试一下。

The query above gets the Triggers information ( TableName: The table name on which the trigger is created. TriggerName: The name of the trigger created on the above table. CreationDate: The datetime this trigger was created ModifyDate: The datetime this trigger was last modified. ) Triggers might slow down performance and response times if the Audit table to which the trigger writes data is very huge. 上面的查询获取触发器信息(TableName:在其上创建触发器的表名。TriggerName:在上表中创建的触发器的名称。CreationDate:创建此触发器的日期时间ModifyDate:上一次修改该触发器的日期时间。)如果触发器写入数据的审核表非常大,则触发器可能会降低性能和响应时间。

You could use Powershell to perform this query, and thereby avoid having to use or install SQL Server Management Studio altogether: 您可以使用Powershell来执行此查询,从而避免完全使用或安装SQL Server Management Studio:

$connection = New-Object System.Data.SqlClient.SQLConnection("Data Source=<DB Hostname>;User ID=<DB Username>; Password=<DB Password>")
$connection.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand("SELECT OBJECT_NAME(parent_id) AS TableName, name AS TriggerName, create_date AS CreationDate, modify_date AS ModifyDate FROM sys.triggers",$connection)
$sqlReader = $cmd.ExecuteReader()
while ($sqlReader.Read()) { $sqlReader["TableName"] + ", " + $sqlReader["TriggerName"] + ", " + $sqlReader["CreationDate"] + ", " + $sqlReader["ModifyDate"]}
$connection.Close()

This code won't speed up your database, but will give helpdesk some information about the triggers set on your database. 这段代码不会加快数据库的速度,但是会为服务台提供一些有关在数据库上设置的触发器的信息。 They'll probably use that information for further troubleshooting. 他们可能会将这些信息用于进一步的故障排除。

See this page for more information . 请参阅此页面以获取更多信息

That's a simple SQL statement. 那是一个简单的SQL语句。 No need to access the box itself at the OS level. 无需在操作系统级别访问设备本身。 Just connect like you do from your application (or using your favorite tool "sql mgmt studio?") and run that SQL. 只需像在应用程序中一样进行连接即可(或使用您喜欢的工具“ sql mgmt studio?”)并运行该SQL。

The only caveat I see, is that you need permissions to those object. 我看到的唯一警告是,您需要这些对象的权限。 Do you have them? 你有吗? If not sure, well... run it and see if it allows you to do it. 如果不确定,那么...运行它,看看它是否允许您执行此操作。

And, no. 和不。 That query per se will not speed up anything. 该查询本身不会加快任何速度。 Maybe those guys need to see the result from the query to do something else. 也许这些家伙需要查看查询结果才能执行其他操作。 This looks like an initial step for a solution. 这看起来像是解决方案的第一步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM