Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Controversial: SQL

Controversial: SQL

Scheduled Pinned Locked Moved The Lounge
database
76 Posts 34 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R raddevus

    "This is the way." ~Mandalorian probably best way for me too

    M Offline
    M Offline
    Mycroft Holmes
    wrote on last edited by
    #19

    MSSQL snippets works perfectly for me except you need to rabbit through the category folders to find the exact one you need :-O. Tis a bitch when you can't remember the category/folder it lives in.

    Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

    1 Reply Last reply
    0
    • J Jorgen Andersson
      1. I simply use the file system. Every file gets a [declarative name].sql, so you can doubleclick and it will start SSMS or whatever program is associated. The master folder is also added to TortoiseHg for versioning 2) Then you need to use dynamic SQL, which is a whole can of worms by itself, and also a possible source of so called SQL-injection 3) I use a fancy invention called Comments for that. Just add them to forementioned Files In Oracle you can also add comments directly to the tables and columns themselves, but in SQL Server you only have Extended Properties, which aren't nearly the same thing

      Wrong is evil and must be defeated. - Jeff Ello Never stop dreaming - Freddie Kruger

      R Offline
      R Offline
      raddevus
      wrote on last edited by
      #20

      Jörgen Andersson wrote:

      1. Then you need to use dynamic SQL, which is a whole can of worms by itself, and also a possible source of so called SQL-injection

      I'm just talking about a local resource that I would use to call up previous queries that I've had to do to examine or update data manually. All of our work is done view SPs -- there are no ad-hoc SQL that are allowed to run against our DBs.

      1 Reply Last reply
      0
      • R raddevus

        There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

        U Offline
        U Offline
        User 13269747
        wrote on last edited by
        #21

        Quote:

        There is no good way to store good SQL queries for future use.

        What's wrong with stored procedures?

        R 1 Reply Last reply
        0
        • R raddevus

          There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

          G Offline
          G Offline
          Gaston Verelst
          wrote on last edited by
          #22

          How about [Solution Explorer - SQL Server Management Studio (SSMS) | Microsoft Docs](https://docs.microsoft.com/en-us/sql/ssms/solution/solution-explorer?view=sql-server-ver15) ?

          Check out my blog at http://msdev.pro/

          R 1 Reply Last reply
          0
          • R raddevus

            There's no great way to : 1) store and categorize good sql 2) also would like a way to insert table names and field names so you could select some things and then just fire off the SQL. 3) need a place for notes about what the sql actually does. I tend to forget sql very fast -- sql is boring and declarative and I always have to look at it too much to remember what it does. Sometimes I just want to find an old query that does that thing you know? :)

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #23

            Sounds like templates: Template Explorer - SQL Server Management Studio (SSMS) | Microsoft Docs[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            R 1 Reply Last reply
            0
            • R raddevus

              Well, I have something like that too, but it's difficult to find the right one amidst all of the other chaff. I wish there was a way to categorize them or something like that. And don't offer me the idea of making sections in my text file, cuz i'm lazy (of course -- I'm a dev). :-D

              O Offline
              O Offline
              obeobe
              wrote on last edited by
              #24

              Then amend your post and write: "there is no good way for a lazy dev to keep track of good SQL queries"....

              1 Reply Last reply
              0
              • R raddevus

                There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

                P Offline
                P Offline
                Peter Adam
                wrote on last edited by
                #25

                SQL is too broad term. IBExpert[^] for Firebird has it and much more[^] .

                1 Reply Last reply
                0
                • R raddevus

                  There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

                  D Offline
                  D Offline
                  DumpsterJuice
                  wrote on last edited by
                  #26

                  A lot of tools come to mind on this topic. Notepad, or Notepad++: I recommend using "AGENT RANSACK" a very fast multi-threaded Search engine. (You can start the search in your ROOT file for the SQL files) (Side note: This is my number one favorite tool) Organize the SQL files, by INDEXING Them (aka: "Tags") INDEX: (Example) #DATE Ex: 01/01/2021 #PROJECT Ex: (NAME) #TYPE Ex: (SELECT INSERT UPDATE DELETE) #NOTATION Ex: That query for the thing I had to do at 1AM ...more as needed ---------------------------------------------------------------- Open "Agent ransack" and search on terms in the sql. This could be all put in a database, but I think that may be a bit too much. You want something simple, and you want to find it fast. You already have a body of SQL that is not indexed. Start indexing all NEW SQL FILES, and as you revisit the old ones, (that are not indexed), Index them as you go along. Keep it all in one file, or multiple files, doesnt matter much with Agent Ransack. So what you wind up with is your very own Google Search for your sql. Keep It Simple, keep it moving.

                  R 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    I keep a text file of 'em: "GoodSQLQueries.txt" it's called. It's easy to copy'n'paste 'em when I need 'em. Or just use an SP. What's the problem?

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                    B Offline
                    B Offline
                    BryanFazekas
                    wrote on last edited by
                    #27

                    I use OneNote -- I have a notebook for each database, with sections labeled by tables and/or area. Each query or code segment has a comment briefing describing what it does. This makes hunting for things much easier.

                    1 Reply Last reply
                    0
                    • R raddevus

                      There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

                      M Offline
                      M Offline
                      Member 14541648
                      wrote on last edited by
                      #28

                      I would suggest a couple of things: - a stored procedure that is just a collection of these wonderful SQL statements that is commented well and set up to NOT be runnable (comment out the whole thing between /* and */, probably) - set up a comment area above each piece of code with keywords or details about what the code does and what it would be useful for - using a search (CTRL-F) on the stored procedure you called GreatCodeToMaybeReuseSomeday (or whatever) to find the SQL of interest. - Copy and paste the code you found. Probably the closest to "think it and it will appear"

                      1 Reply Last reply
                      0
                      • R raddevus

                        There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

                        U Offline
                        U Offline
                        User 10331519
                        wrote on last edited by
                        #29

                        Just a thought: Use a library like JsonQL to convert SQL to a JSON representation and store them in MongoDB with descriptive metadata. Search on the content and/or metadata.

                        R 1 Reply Last reply
                        0
                        • U User 13269747

                          Quote:

                          There is no good way to store good SQL queries for future use.

                          What's wrong with stored procedures?

                          R Offline
                          R Offline
                          raddevus
                          wrote on last edited by
                          #30

                          Member 13301679 wrote:

                          What's wrong with stored procedures?

                          I mean like a development studio type of thing where you can select a particular SQL statement that you want to run manually when you're examining data and designing queries. We use SPs for all interactions with DB but I'm talking more about a code reuse type of thing. I guess I could create a library of SPs and then run those when I need to, but I'd still need a way to manage them with names and stuff so I could remember what they do. I guess it is really because I'm in the midst of designing queries for a large system and I only have to do this every 2 or 3 years so I have a long time away from it.

                          U 1 Reply Last reply
                          0
                          • G Gaston Verelst

                            How about [Solution Explorer - SQL Server Management Studio (SSMS) | Microsoft Docs](https://docs.microsoft.com/en-us/sql/ssms/solution/solution-explorer?view=sql-server-ver15) ?

                            Check out my blog at http://msdev.pro/

                            R Offline
                            R Offline
                            raddevus
                            wrote on last edited by
                            #31

                            That does look good but...

                            Link provided said

                            Important This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

                            G 1 Reply Last reply
                            0
                            • R raddevus

                              Member 13301679 wrote:

                              What's wrong with stored procedures?

                              I mean like a development studio type of thing where you can select a particular SQL statement that you want to run manually when you're examining data and designing queries. We use SPs for all interactions with DB but I'm talking more about a code reuse type of thing. I guess I could create a library of SPs and then run those when I need to, but I'd still need a way to manage them with names and stuff so I could remember what they do. I guess it is really because I'm in the midst of designing queries for a large system and I only have to do this every 2 or 3 years so I have a long time away from it.

                              U Offline
                              U Offline
                              User 13269747
                              wrote on last edited by
                              #32

                              Quote:

                              I mean like a development studio type of thing where you can select a particular SQL statement that you want to run manually when you're examining data and designing queries.

                              MySQL Workbench allows that, including loading and saving the files just like an IDE, keeping files in different tabs, etc.

                              R 1 Reply Last reply
                              0
                              • Richard DeemingR Richard Deeming

                                Sounds like templates: Template Explorer - SQL Server Management Studio (SSMS) | Microsoft Docs[^]


                                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                R Offline
                                R Offline
                                raddevus
                                wrote on last edited by
                                #33

                                That's a good one. I'm checking it out. After looking at a couple of those templates I see where they got some of the boilerplate that they use in our RoundhousE[^] scripts. Thanks, I will look more closely at this one.

                                1 Reply Last reply
                                0
                                • R raddevus

                                  That does look good but...

                                  Link provided said

                                  Important This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

                                  G Offline
                                  G Offline
                                  Gaston Verelst
                                  wrote on last edited by
                                  #34

                                  I didn't know that, thanks for the info. I have another one: [Download and install Azure Data Studio - Azure Data Studio | Microsoft Docs](https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15) Maybe this does what you want? I think it also works with SQL Servers that are not in Azure but I didn't test that.

                                  Check out my blog at http://msdev.pro/

                                  1 Reply Last reply
                                  0
                                  • D DumpsterJuice

                                    A lot of tools come to mind on this topic. Notepad, or Notepad++: I recommend using "AGENT RANSACK" a very fast multi-threaded Search engine. (You can start the search in your ROOT file for the SQL files) (Side note: This is my number one favorite tool) Organize the SQL files, by INDEXING Them (aka: "Tags") INDEX: (Example) #DATE Ex: 01/01/2021 #PROJECT Ex: (NAME) #TYPE Ex: (SELECT INSERT UPDATE DELETE) #NOTATION Ex: That query for the thing I had to do at 1AM ...more as needed ---------------------------------------------------------------- Open "Agent ransack" and search on terms in the sql. This could be all put in a database, but I think that may be a bit too much. You want something simple, and you want to find it fast. You already have a body of SQL that is not indexed. Start indexing all NEW SQL FILES, and as you revisit the old ones, (that are not indexed), Index them as you go along. Keep it all in one file, or multiple files, doesnt matter much with Agent Ransack. So what you wind up with is your very own Google Search for your sql. Keep It Simple, keep it moving.

                                    R Offline
                                    R Offline
                                    raddevus
                                    wrote on last edited by
                                    #35

                                    Interesting. I shall consider it.

                                    D 1 Reply Last reply
                                    0
                                    • U User 10331519

                                      Just a thought: Use a library like JsonQL to convert SQL to a JSON representation and store them in MongoDB with descriptive metadata. Search on the content and/or metadata.

                                      R Offline
                                      R Offline
                                      raddevus
                                      wrote on last edited by
                                      #36

                                      This one gets my "programmer's mind" thinking about a lot of possibilities.

                                      1 Reply Last reply
                                      0
                                      • R raddevus

                                        There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

                                        B Offline
                                        B Offline
                                        Brian Battles
                                        wrote on last edited by
                                        #37

                                        I find it handy to store them as pass-through queries in an MS Access database. You can give them names that work for you, and then sort them, filter them, search for them, etc. I also wrote a VBA function to let me search for any text string in all my Access queries in case I want to find which ones contain a certain table or field name and so on.

                                        R 1 Reply Last reply
                                        0
                                        • R raddevus

                                          There is no good way to store good SQL queries for future use. Just, no good way. :rolleyes:

                                          E Offline
                                          E Offline
                                          ElectronProgrammer
                                          wrote on last edited by
                                          #38

                                          For very special, or big, or being used a lot, queries (or for clients who can't spell SQL :-D ), I use something that you will probably hate. I use Java :) I make a program in Java (basically a custom SQL generator) where I insert the code inside a method that receives parameters that allow to configure the query in things like database/table/field names, which fields to return, insert sub-queries, etc. Then document with Javadoc as with any other program. All the queries are inside the same Java program, are selectable and configurable via command line or a web page that dynamically requests more configuration based on what you requested and configured so far. Using the generated Javadoc or an IDE on the program source makes it easy to find anything. The program makes easy to get the configured SQL. This has the advantage that you can tweak the Java source to add more functionality to the queries and make that selectable via parameters. You can even pass the program to clients and they will happily build some queries they need by just answering configuration questions and never touching SQL. I have done this for a client in the past in which the program would generate SQL and JavaScript (to interact with the SQL via web page) for their web site recommendation system using Similarity Matrices, Friends-of-Friends and a few other algorithms implemented in SQL. Since their recommendation system used the same algorithms to recommend different things (people, items, lists of people-item pairs, etc), this method was easier for me to maintain and they were very happy to be able to generate the required SQL in less than 5 minutes by answering a few questions instead of manually modifying each time the almost 500 lines of SQL code for the Similarity Matrix alone. They were even able to use the program by themselves, without requesting my help, to generate SQL to recommend things that were never mentioned to me. Unfortunately, I can not show any of those programs as they are protected by IP :( Yes, this is convoluted, but makes things easier on the long run.

                                          R 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups