SQL Server Management Studio支持自定义快捷键:工具->选项->键盘:
其中,Alt+F1、Ctrl+1、Ctrl+2是系统预定义的快捷键。
双击表名(或按Ctrl单击表名),选定一个表名,如tablename,按Alt+F1,相当于执行“sp_help tablename”,可以查看对象的说明信息。
常用自定义快捷键:
--Ctrl+F1:显示视图、存储过程、函数、触发器的定义脚本。
sp_helptext
--Ctrl+3:显示表或视图的前100行,选定“tablename,1000”按Ctrl+3可显示表的前1000行。
sp_executesql N'IF OBJECT_ID(@tablename) IS NOT NULL EXEC(N''SELECT TOP(''+@n+N'') * FROM ''+@tablename)',N'@tablename nvarchar(100),@n int=100',
--Ctrl+4:显示表或视图的字段名,以逗号分隔。
sp_executesql N'SELECT columns = STUFF((SELECT '', ''+name FROM sys.columns WHERE object_id = OBJECT_ID(@tablename) FOR XML PATH('''')),1,2,'''')',N'@tablename nvarchar(100)',
或者:
sp_executesql N'declare @Colstr varchar(max) select @Colstr = isnull(@Colstr+'','','''')+isnull(name,'''') from sys.columns WHERE object_id = OBJECT_ID(@tablename) select @Colstr as Colstr',N'@tablename nvarchar(100)',
--Ctrl+5:显示表的行数和占用空间。
sp_spaceused
--Ctrl+6:显示表中每个索引占用的空间。
sp_executesql N'SELECT index_name = ind.name, ddps.used_page_count, ddps.reserved_page_count, ddps.row_count FROM sys.indexes ind INNER JOIN sys.dm_db_partition_stats ddps ON ind.object_id = ddps.object_id AND ind.index_id = ddps.index_id WHERE ind.object_id = OBJECT_ID(@tablename)',N'@tablename nvarchar(100)',
--Ctrl+0:根据选定关键词在当前数据库中查找表、视图、存储过程、函数
sp_executesql N'SELECT * FROM sys.objects WHERE type IN (''U'',''V'',''P'',''FN'') AND name LIKE ''%''+@keyword+''%'' ORDER BY type,name',N'@keyword nvarchar(50)',
以上设置sqlserver2000多数都不支持,Ctrl+3,Ctrl+4可以用以下存储过程代替:
CREATE PROCEDURE sp_select_table(
@tablename SYSNAME)
AS
/*显示表中的数据*/
EXEC('select * from '+@tablename)
GO
CREATE PROCEDURE sp_select_column(
@tablename SYSNAME)
AS
/*列出表中所有字段*/
declare @Colstr varchar(2000)
select @Colstr = isnull(@Colstr+',','')+isnull(name,'') from syscolumns c
WHERE EXISTS(select 1 from sysobjects o where o.name = @tablename and o.xtype='U' and o.id=c.id)
select @Colstr as Colstr
GO