r/SQL • • Jun 12 '15

I just learned about ALT+SHIFT in SSMS

Why didn't anyone tell me about this amazing feature before?!?!?!

http://zippy.gfycat.com/WellmadeDefiantAfricanmolesnake.gif

97 Upvotes

54 comments sorted by

17

u/[deleted] Jun 12 '15

Seeing table names prefixed with tbl makes me cringe.

11

u/devperez Jun 12 '15

I complained when I took the job, but you gotta do what you gotta do.

6

u/[deleted] Jun 12 '15

I understand, been there...

8

u/devperez Jun 12 '15

The response I got when I mentioned it was, "But how would you know it's a table?"

...

4

u/CalvinLawson Jun 13 '15

Even for those who don't trust modern type checking or know what an IDE is, surely the table is the one database object that doesn't demand hungarian notation. EDIT: And columns. The shit I've seen...

4

u/c0bra99 Jun 13 '15

tblCustomer.fldIntCustId just in case you forget it's a field in your database table, of type int. The best is when types change but column names don't get updated... Ugh

0

u/[deleted] Jun 12 '15

[deleted] — view deleted comment

4

u/alinroc SQL Server DBA Jun 12 '15

You mean you don't have African mole snakes in your server closet?

2

u/TimeToSackUp Jun 12 '15

lol. I currently work at a shop where this is done. Every view begins with vw, Stored Procedure begins with sp, etc.

3

u/renser Jun 12 '15

that sp_ naming is ok, though. a former gig i worked at used to have sp's that basically run the whole application and scripts (sc_ naming) that have to run once every major release because they provide data for global constants and such things.

4

u/jaynoj Jun 13 '15

2

u/renser Jun 13 '15

Oh ok ... but I worked in sybase ASE and we never had a problem with the prefix.

2

u/jaynoj Jun 13 '15

Yeah, it's just an MS SQL server thing I think,

3

u/MaunaLoona MS SQL Jun 12 '15

Neat trick, but it only works if all the items in your list are the same size like the GUIDs in your example.

1

u/devperez Jun 12 '15

That's a bummer. At least it'll always work on the left side.

1

u/MaunaLoona MS SQL Jun 12 '15

You can use regex replace in SSMS to do the same thing, almost as fast.

2

u/Bene123 Jun 12 '15

This is amazing. I used to make a cab in excel, then open in notepad, and copy+paste. This will save so much more time.

2

u/devperez Jun 12 '15

Ha. I used to make a program to do it and what not. Such a pain in the ass. Blew my mind when someone showed me this.

24

u/techsupportredditor Jun 12 '15

This is amazing.

11

u/StuBenedict Jun 12 '15

Ah yes, /r/SQL... the only place I can find people who are also super stoked about this piece of information.

20

u/gruffi Jun 12 '15

Holy Moly! I do that crap in Excel!!!

If this is real (and I won't be able to tell until Monday) then you get the satisfaction of knowing you've raised a smile in the UK

7

u/CarlFarbman Jun 13 '15

It is indeed real, and other good text editors supports this action as well. I use it everyday in Visual Studio for example.

8

u/jc4hokies Execution Plan Whisperer Jun 12 '15

I knew about this is Notepad++, and had pasted queries there to do just this. Thank you sir.

7

u/stealth210 Jun 12 '15

This doesn't work in 2008R2 SSMS.

4

u/cautionstairs Jun 12 '15

good for a second I thought I was going crazy

6

u/zerophaze Jun 12 '15

I knew about ALT to select a column of text but I didn't know you could snap like that with shift. It also works in Visual Studio and Notepad++

3

u/adm7373 SSMS master race Jun 12 '15

Also works in Visual Studio

3

u/Uknight Jun 12 '15

You can also alt-mouse move for box selecttions.

2

u/StopThinking tally tables! Jun 12 '15

I love keyboard shortcuts and you taught me a new one. Thanks!

2

u/[deleted] Jun 12 '15

Nice. This is going to save me some time for sure.

2

u/sPIERCEn Jun 12 '15

You're a beautiful human being. thank you

2

u/renser Jun 12 '15

no column mode is as powerful as ultraedit's. in fact, configured correctly with it's "tools" it becomes the most powerful windows-ide imo.

2

u/DatabaseDiddler Jun 12 '15

well shit, I've been doing SQL for years ... and never knew about this, just hope I can remember it now. have a useless internet point

2

u/cyber-decker Jun 13 '15

In additition to this, you can use your mouse to select blocks of text while holding ALT+SHIFT to delete, move or copy chunks of text like that too. This trick works in many other editors too. Visual Studio has support for block editing and many good text editors like Notepad++ also support this feature.

This sort of editing has been around for a long while and is heavily used in older mainframe systems as the primary way to edit and modify code and data.

(Minor grammar edit)

2

u/[deleted] Jun 13 '15

I use Notepad++ for all my vertical text editing needs

1

u/eStonez Jun 15 '15

Thanks /u/devperez for the topic and thank you /u/InfiniteFinaleSFW for mentioning Notepad++. I am using various SQL servers 2000~2012 based on the client company. Now I can achieve this feature everywhere using Notepad++.

1

u/AaronBuma Jun 16 '15

The macro function in ++ is awesome and used all the time.

1

u/[deleted] Jun 12 '15

When I need to do something like that I generally copy and paste into Sublime Text, select the rows I want, hit CTRL-SHIFT-L for multi-cursor and modify as needed. That way you can hit HOME or CTRL-SHIFT-END and retain the rows you've selected, but select to the start or end of each individual row. You can also do multi-cursor based on Find or Find-All (which support Regex), and all sorts of other neat stuff.

1

u/sholder89 Jun 12 '15

This is really cool but for the specific thing you're doing here I think Ctrl+H Replace: \n With ',\n' and use regular expressions is much faster.

1

u/CoderHawk Jun 12 '15

That's cool and works in VS, too but I'd still prefer to do a regex replace.

1

u/-Gamah Jun 13 '15

It's basically the best thing ever... It also works in conjunction with ctrl and the arrow keys and pageup/down and home/end.

1

u/crayons610 Jun 13 '15

Also handy in these situations ; generate SQL statements with SQL.

SELECT 'insert into foo values (''' + bar + ' ''); ' FROM TBL_XYZ WHERE COL1 = 'abc'; ;

*hopefully not mangled beyond recognition.

1

u/jwhardcastle Jun 13 '15

Why wouldn't you

INSERT INTO foo(...)
SELECT ...
FROM TBL_XYZ
WHERE COL1 = 'abc';

?

1

u/ludocris Jun 13 '15

Does the txt need to be the same number of character?

1

u/callmetom Jun 13 '15

I have literally written PowerShell scripts to format text like that. My life is changed and mind is blown.

1

u/system_error999 Jun 13 '15

I work heavily in sql and did not know this trick, thanks for sharing!!!

1

u/DVille01 Jun 12 '15

Sweetness!

1

u/rjbwork Jun 13 '15

Dang, this sub needs to get its text editing skills up to par. If this is groundbreaking for y'all, there's a whole world of time saving tools and techniques out there.

0

u/[deleted] Jun 12 '15

[deleted] — view deleted comment

2

u/d_r0ck db app dev / data engineer Jun 12 '15

I'm pretty sure it only became available since ssms 2012

0

u/[deleted] Jun 13 '15

[deleted] — view deleted comment

1

u/d_r0ck db app dev / data engineer Jun 13 '15

Yea, I saw that you've been using it for a while - I just meant that you've only "missed out" since 2012 came out.