SQL Server中快速输入SELECT * FROM的替代方法及Windows自定义快捷键设置
Hey there! I feel your pain—typing SELECT * FROM hundreds of times a day is such a tedious drag. Let’s break down two solid, practical solutions for you: one built right into SQL Server Management Studio (SSMS), and another using Windows tools to create a global shortcut that works anywhere.
SSMS has native tools to cut down on repetitive typing, no extra software needed.
Custom Code Snippet with Quick Trigger
You can create a custom code snippet that expands to SELECT * FROM with a short keyword:
- Open SSMS, press
Ctrl+K, Ctrl+Bto open the Code Snippets Manager. - Navigate to SQL > My Code Snippets (or create a new folder for your custom snippets).
- Click Import, then create a new file named
SelectAllFrom.snippetwith this content:
<?xml version="1.0" encoding="utf-8"?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>Select All From</Title> <Shortcut>saf</Shortcut> <Description>Inserts SELECT * FROM</Description> <Author>Your Name</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Code Language="SQL"> <![CDATA[SELECT * FROM ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
- Import the file into SSMS. Now, in the query editor, type
safand pressTab+Tab—it’ll instantly expand toSELECT * FROM.
Direct Keyboard Shortcut in SSMS
If you prefer a one-press shortcut instead of a keyword:
- Go to Tools > Options > Environment > Keyboard.
- In the Show commands containing box, search for
Edit.InsertText. - Click Press shortcut keys, type a combination you want (e.g.,
Ctrl+Shift+S), then click Assign and OK. - From now on, pressing that shortcut in SSMS will paste
SELECT * FROMdirectly into your query.
If you want this shortcut to work across all apps (not just SSMS), AutoHotkey is a free, lightweight tool that’s perfect for the job.
Step-by-Step Setup:
- Install AutoHotkey (you can find it via a quick search—no external links needed).
- Right-click your desktop, select New > AutoHotkey Script.
- Open the script with Notepad and paste this code:
; Press Ctrl+Alt+S to auto-type SELECT * FROM ^!s:: SendInput, SELECT * FROM return
- Save the script, then double-click it to run it (it’ll sit quietly in your system tray).
- Now, anywhere you need that phrase—SSMS, text editors, even spreadsheets—press
Ctrl+Alt+Sand it’ll type it for you instantly.
Bonus: Windows Native Text Replacement
If you don’t want to install third-party tools, use Windows’ built-in AutoCorrect:
- Go to Settings > Time & Language > Typing > Advanced keyboard settings > Typing insights > AutoCorrect.
- Add a replacement: type
safin the Replace box, andSELECT * FROMin the With box. Now typingsaffollowed by space/enter will auto-replace it with your desired phrase.
内容的提问来源于stack exchange,提问作者vamshi

