Useful system stored procedures in SQL Server

2020-05-11 11:00发布

I recently discovered that I could use the sp_help to get a table definition and have been hooked onto it since then. Before my discovery, I had to open up the Object explorer in SQL Management studio, manually search for the table name, right click on the table and select Design. That was a lot of effort!

What other system stored procedures do you all use that you can't simply live without?

12条回答
爷的心禁止访问
2楼-- · 2020-05-11 11:18

sp_who/sp_who2 - lets you know who is doing what on the server.

查看更多
smile是对你的礼貌
3楼-- · 2020-05-11 11:18

highlight any proc or other system object name in your query editor and hit shift-f1 to get help for that word.

查看更多
smile是对你的礼貌
4楼-- · 2020-05-11 11:19

sp_rename

for renaming database objects (tables, columns, indexes, etc.)

查看更多
戒情不戒烟
5楼-- · 2020-05-11 11:22

Alt + F1 is a good shortcut key for sp_help.

sp_helptext is another goodie for getting stored procedure text.

查看更多
我欲成王,谁敢阻挡
6楼-- · 2020-05-11 11:24

I know it's a rather old topic, but it still has a high rank in search engines.

These are my favorite stored procedures, I hope you find them useful too. Almost all of them can be achieved with a simple command, but these stored procedures perform some checks and validation that is useful.

[sys].[sp_revokelogin]
[sys].[sp_password]
[sys].[sp_MSchangeobjectowner]
[sys].[sp_addlogin]
[sys].[sp_addrole]
[sys].[sp_adduser]
[sys].[sp_denylogin]
[sys].[sp_droplogin]
[sys].[sp_droprole]
[sys].[sp_droprolemember]
[sys].[sp_dropuser]
查看更多
乱世女痞
7楼-- · 2020-05-11 11:28

sp_ helpindex [table] - shows you index info (same info as sp_help)

sp_helpconstraint [table] - shows you primary/foreign key/defaults and other constraints *

sp_depends [obj] - shows dependencies of an object, for example:

sp_depends [table] - shows you what stored procs, views, triggers, UDF affect this table

sp_depends [sproc] - shows what tables etc are affected/used by this stored proc

查看更多
登录 后发表回答