From fuller.artful at gmail.com Fri May 14 08:35:02 2010 From: fuller.artful at gmail.com (Arthur Fuller) Date: Fri, 14 May 2010 09:35:02 -0400 Subject: [dba-SQLServer] SAP Acquires Sybase Message-ID: Not strictly speaking an MS-SQL issue, but in case you missed this news... http://www.zdnet.com/blog/howlett/sap-acquires-sybase-for-58-billion-but-why/2093?tag=nl.e539 Arthur From accessd at shaw.ca Fri May 14 11:17:48 2010 From: accessd at shaw.ca (Jim Lawrence) Date: Fri, 14 May 2010 09:17:48 -0700 Subject: [dba-SQLServer] SAP Acquires Sybase In-Reply-To: References: Message-ID: <24B1C28D55B54204875F9CF758C6DD95@creativesystemdesigns.com> That is big news in the computer world as I know a couple of companies and one very large University project that use SyBase exclusively... It is related to MS SQL as the 6.0 and 6.5 was built on the Sybase engine and a lot of the way subsequent versions of MS SQL are laid out is thanks to its predecessor. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Friday, May 14, 2010 6:35 AM To: Discussion concerning MS SQL Server Subject: [dba-SQLServer] SAP Acquires Sybase Not strictly speaking an MS-SQL issue, but in case you missed this news... http://www.zdnet.com/blog/howlett/sap-acquires-sybase-for-58-billion-but-why /2093?tag=nl.e539 Arthur _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From marklbreen at gmail.com Wed May 19 04:02:30 2010 From: marklbreen at gmail.com (Mark Breen) Date: Wed, 19 May 2010 10:02:30 +0100 Subject: [dba-SQLServer] Microsoft Bizspark - Was MAPS: Microsoft Action Pack.... Message-ID: Hello All, Sorry for changing the subject line, but it is a slightly different subject. Have you all heard of Microsoft Bizspark ? When I heard of it I thought that it was too good to be true. My Brother - in - Law signed up to it. I eventually submitted a request myself and voila, I was accepted and I now have three years of full MSDN access and have to pay $100 when I leave in three years time. Read the requirements carefully, and talk to a local partner for advice so as to optimize your application. As I type I have office 2010 installed on my machine and VS2010 waiting to be installed! AFAICS, this program trumps everything that MS has to offer - its virtually free and once you are accepted it lasts three years. Good Luck, Mark On 18 May 2010 16:25, Rocky Smolin wrote: > I see it now. Too early I guess. Missed it. Thanks. > > Rocky > > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gary Kjos > Sent: Tuesday, May 18, 2010 7:56 AM > To: Access Developers discussion and problem solving > Subject: Re: [AccessD] MAPS: Microsoft Action Pack > SubscriptionDevelopmentand Design Benefits > > You don't have access to google? ;-) > > A search on "microsoft action pack subscription cost" > > and the first link listed..... > https://partner.microsoft.com/40016455 > > > ---------------------------------------------------------------------------- > ---------------------------------------------------------- > > The Microsoft Action Pack Subscription download-only version today costs > $299 plus tax, per year. If you would also like to receive physical media, > the price is $498 plus tax, per year. If you opt in for physical media in > the middle of your annual subscription period, the additional cost will be > assessed on a prorated basis. > Starting May 24, 2010, we will provide enhanced benefits to Action Pack > Solution Provider. The download-only version will cost $329 plus tax, per > year. If you would also like to receive physical media, the new price will > be $429 plus tax, per year. > > > ---------------------------------------------------------------------------- > ------------------------------------------------------------ > > GK > > On Tue, May 18, 2010 at 9:17 AM, Rocky Smolin > wrote: > > Gustav: > > > > I looked at the site but couldn't find a price. Do you know how much > > the Action Pack is now? I took a test a while back to re-enroll but > > never got the Pack. > > > > TIA > > > > Rocky > > > > > > -----Original Message----- > > From: accessd-bounces at databaseadvisors.com > > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav > > Brock > > Sent: Tuesday, May 18, 2010 6:36 AM > > To: accessd at databaseadvisors.com; dba-vb at databaseadvisors.com > > Subject: [AccessD] MAPS: Microsoft Action Pack Subscription > > Developmentand Design Benefits > > > > Hi all > > > > As of May 24. the development tools - most importantly Visual Studio > > 2010 Professional - is now part of a separate package dedicated > developers: > > > > Microsoft Action Pack Development and Design Benefits > > https://partner.microsoft.com/global/program/managemembership/40133000 > > > > Three MSDN for Microsoft Action Pack Development and Design > > subscriptions (licensed per user): > > Microsoft Visual Studio 2010 Professional > > Microsoft Expression Web > > The latest version of the Windows and Windows Server operating > > systems, and Microsoft SQL Server for development and testing > > > > You still have to pass some "test" every second year: > > https://partner.microsoft.com/global/40132997 > > > > /gustav > > > > > >>>> Gustav at cactus.dk 18-01-2008 09:10 >>> > > Hi all > > > > Well, this is on schedule. Today an envelope arrived including these > > cd-roms: > > > > Microsoft Visual Studio 2008 Standard Edition > > Microsoft Expression Studio > > > > and a DVD: > > > > Custom Web Development Jumpstart > > and Windows Live Partner Resources Kit > > > > Also, I received 2 GB of ram for my laptop. Do we have a match? > > > > /gustav > > > >>>> Gustav at cactus.dk 04-12-2007 18:06:22 >>> > > Hi all > > > > Received this today: > > > > Our records indicate .. that you are eligible to order the Microsoft > > Web Solutions Toolkit. > > You will automatically be shipped the Web Solutions Toolkit in January > 2008. > > > > > > /gustav > > > > > >>>> Gustav at cactus.dk 10-10-2007 10:09:07 >>> > > Hi all > > > > We (my employer and I) don't want to spend money on the "MS exam > > circus" as the ROI is zero. Thus, our official Small Business > > Specialist status will be lost (and our clients don't care as they > > hardly knew that anyway). No big deal. > > > > However, that status have the additional benefit that combined with > > the Action Pack Subscription (where the ROI is huge) you are offered > > Visual Studio Standard 2005 for free. So no SB partner => no free VS > > which is bad now that VS2008 is close. > > > > But a new free add-on to the Action Pack is now announced which could > > be of interest for those of you not having Visual Studio yet or have > > felt the limitations of the free Express editions, a "special edition > > toolkit" for Web Solution Providers: > > > > https://partner.microsoft.com/webresourcekit > > > > It includes Microsoft Visual Studio Standard 2008 and Expression Studio. > > The estimated ship date for the kit is January 2008. > > > > One of the steps to obtain the kit is to: > > > > Successfully complete one of three free online courses and the > > associated assessment with a score of 70 percent or higher .. > > > > These seems to have a duration from 0,5 to 1,5 hours, so you have to > > pay by spending some of your valuable time! > > > > /gustav > > > > > > -- > > AccessD mailing list > > AccessD at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/accessd > > Website: http://www.databaseadvisors.com > > > > -- > > AccessD mailing list > > AccessD at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/accessd > > Website: http://www.databaseadvisors.com > > > > > > -- > Gary Kjos > garykjos at gmail.com > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > From accessd at shaw.ca Wed May 19 08:26:07 2010 From: accessd at shaw.ca (Jim Lawrence) Date: Wed, 19 May 2010 06:26:07 -0700 Subject: [dba-SQLServer] Microsoft Bizspark - Was MAPS: Microsoft ActionPack.... In-Reply-To: References: Message-ID: <65B6F8E29749492A850CBAC76F41827E@creativesystemdesigns.com> Hi Mark: This does sound very interesting... I have been approached lately on becoming part of a start up company and this proposal by MS could go a long way in this venture... Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark Breen Sent: Wednesday, May 19, 2010 2:03 AM To: Access Developers discussion and problem solving; Discussion concerning Visual Basic and related programming issues.; Discussion concerning MS SQL Server Subject: [dba-SQLServer] Microsoft Bizspark - Was MAPS: Microsoft ActionPack.... Hello All, Sorry for changing the subject line, but it is a slightly different subject. Have you all heard of Microsoft Bizspark ? When I heard of it I thought that it was too good to be true. My Brother - in - Law signed up to it. I eventually submitted a request myself and voila, I was accepted and I now have three years of full MSDN access and have to pay $100 when I leave in three years time. Read the requirements carefully, and talk to a local partner for advice so as to optimize your application. As I type I have office 2010 installed on my machine and VS2010 waiting to be installed! AFAICS, this program trumps everything that MS has to offer - its virtually free and once you are accepted it lasts three years. Good Luck, Mark On 18 May 2010 16:25, Rocky Smolin wrote: > I see it now. Too early I guess. Missed it. Thanks. > > Rocky > > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gary Kjos > Sent: Tuesday, May 18, 2010 7:56 AM > To: Access Developers discussion and problem solving > Subject: Re: [AccessD] MAPS: Microsoft Action Pack > SubscriptionDevelopmentand Design Benefits > > You don't have access to google? ;-) > > A search on "microsoft action pack subscription cost" > > and the first link listed..... > https://partner.microsoft.com/40016455 > > > ---------------------------------------------------------------------------- > ---------------------------------------------------------- > > The Microsoft Action Pack Subscription download-only version today costs > $299 plus tax, per year. If you would also like to receive physical media, > the price is $498 plus tax, per year. If you opt in for physical media in > the middle of your annual subscription period, the additional cost will be > assessed on a prorated basis. > Starting May 24, 2010, we will provide enhanced benefits to Action Pack > Solution Provider. The download-only version will cost $329 plus tax, per > year. If you would also like to receive physical media, the new price will > be $429 plus tax, per year. > > > ---------------------------------------------------------------------------- > ------------------------------------------------------------ > > GK > > On Tue, May 18, 2010 at 9:17 AM, Rocky Smolin > wrote: > > Gustav: > > > > I looked at the site but couldn't find a price. Do you know how much > > the Action Pack is now? I took a test a while back to re-enroll but > > never got the Pack. > > > > TIA > > > > Rocky > > > > > > -----Original Message----- > > From: accessd-bounces at databaseadvisors.com > > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav > > Brock > > Sent: Tuesday, May 18, 2010 6:36 AM > > To: accessd at databaseadvisors.com; dba-vb at databaseadvisors.com > > Subject: [AccessD] MAPS: Microsoft Action Pack Subscription > > Developmentand Design Benefits > > > > Hi all > > > > As of May 24. the development tools - most importantly Visual Studio > > 2010 Professional - is now part of a separate package dedicated > developers: > > > > Microsoft Action Pack Development and Design Benefits > > https://partner.microsoft.com/global/program/managemembership/40133000 > > > > Three MSDN for Microsoft Action Pack Development and Design > > subscriptions (licensed per user): > > Microsoft Visual Studio 2010 Professional > > Microsoft Expression Web > > The latest version of the Windows and Windows Server operating > > systems, and Microsoft SQL Server for development and testing > > > > You still have to pass some "test" every second year: > > https://partner.microsoft.com/global/40132997 > > > > /gustav > > > > > >>>> Gustav at cactus.dk 18-01-2008 09:10 >>> > > Hi all > > > > Well, this is on schedule. Today an envelope arrived including these > > cd-roms: > > > > Microsoft Visual Studio 2008 Standard Edition > > Microsoft Expression Studio > > > > and a DVD: > > > > Custom Web Development Jumpstart > > and Windows Live Partner Resources Kit > > > > Also, I received 2 GB of ram for my laptop. Do we have a match? > > > > /gustav > > > >>>> Gustav at cactus.dk 04-12-2007 18:06:22 >>> > > Hi all > > > > Received this today: > > > > Our records indicate .. that you are eligible to order the Microsoft > > Web Solutions Toolkit. > > You will automatically be shipped the Web Solutions Toolkit in January > 2008. > > > > > > /gustav > > > > > >>>> Gustav at cactus.dk 10-10-2007 10:09:07 >>> > > Hi all > > > > We (my employer and I) don't want to spend money on the "MS exam > > circus" as the ROI is zero. Thus, our official Small Business > > Specialist status will be lost (and our clients don't care as they > > hardly knew that anyway). No big deal. > > > > However, that status have the additional benefit that combined with > > the Action Pack Subscription (where the ROI is huge) you are offered > > Visual Studio Standard 2005 for free. So no SB partner => no free VS > > which is bad now that VS2008 is close. > > > > But a new free add-on to the Action Pack is now announced which could > > be of interest for those of you not having Visual Studio yet or have > > felt the limitations of the free Express editions, a "special edition > > toolkit" for Web Solution Providers: > > > > https://partner.microsoft.com/webresourcekit > > > > It includes Microsoft Visual Studio Standard 2008 and Expression Studio. > > The estimated ship date for the kit is January 2008. > > > > One of the steps to obtain the kit is to: > > > > Successfully complete one of three free online courses and the > > associated assessment with a score of 70 percent or higher .. > > > > These seems to have a duration from 0,5 to 1,5 hours, so you have to > > pay by spending some of your valuable time! > > > > /gustav > > > > > > -- > > AccessD mailing list > > AccessD at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/accessd > > Website: http://www.databaseadvisors.com > > > > -- > > AccessD mailing list > > AccessD at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/accessd > > Website: http://www.databaseadvisors.com > > > > > > -- > Gary Kjos > garykjos at gmail.com > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From accessd at shaw.ca Wed May 19 09:54:47 2010 From: accessd at shaw.ca (Jim Lawrence) Date: Wed, 19 May 2010 07:54:47 -0700 Subject: [dba-SQLServer] Parallelism In-Reply-To: References: <34FFB67A32A64A85A1D61422E34D40CE@creativesystemdesigns.com> <73FC6395D2CA47639932C5A5B5204FEE@creativesystemdesigns.com> <3E23E4865861413788D4FD433E981005@creativesystemdesigns.com> Message-ID: <4A52241149474D76AA93A21F31C31BDA@creativesystemdesigns.com> Hi All: A couple of nights ago, I went to a series of lectures given by a fellow named Tiberiu Covaci, Swedish owner of a company called Multi-Core and he is now doing a tour as a trainer for Microsoft. (His next lecture stop will be in New Orleans.) His training lecture was on Parallelism. The first lecture covered the basic concepts of computers and their new multi-core design, a design made necessary as single core computers ran into the physical wall as of 2005. He then went on to describe the attempts by developers to utilize these new multi-core systems. It has been a slow process as you can imagine. The rudimentary attempts of threading and hyper-threading were far from successful. First a single thread will consume up to 200 cycles just to get substantiated and its deployment still requires the central CPU and to spawn hundreds of threads, in a pool and then there was the issues of synchronizing the process results. Even the best developed multi-threaded applications, like MS SQL 2005 could over-load a computer when challenged by a heavy duty task. MS even went so far as to apply a system lock when performing resource heavy jobs... that means all other functionality on the server would cease... no multi-tasking, until the job was completed... even then sometimes a process would freeze up a server. (We have all heard of that exact situation from a number of our DBA members.) Our lecturer had designed a couple of short programs to showed how multi-threading was implemented and then demonstrated how these apps when over-loaded would crash or lock out the system. He used a Quick-sort, demo while splitting it into multiple pieces, multi-threading it and slowly increasing the sort data showed a 30 percent gain per thread and a 70 percent gain per core (maximum gain) but it also showed virtually not performance loss as the data increased (10 to 100 million records) until the process locked up the CPU. We watched the system progress via the Task Manger's CPU display. Lecture two; enter Parallelism. This process has being developed on the latest versions of Java and .Net frame work (4 or greater). He demonstrated two new core features/objects Parallel and Task. Using Parallelism requires a bit to decompose a problem into its components. He used an example of a recipe where a number of steps was required from initial preparation, to the cooking and to the table. The program which ended calculating the time was initially designed in a standard C# routine. The app was then recoded using Parallel running tasks. Each task can run independently, but wait for a process to be completed if required by scheduling, monitoring a semaphore, event, state and/or wait loops. We also covered how to handle synchronization, data sharing and how to avoid deadlocks. By using pararllelism the meal was completed in half the time... It showed how 6 people could do a job faster than one... now that's obvious but maybe not so obvious with a computer application. The most telling observation was when viewing the Task Manger's CPU display. No matter how heavy the requirements that were imposed on the system, the CPU demand remained very low and flat and each core showed an even distribution of utilization. I was totally impressed. Now I know how such super databases as Cassandra, using Java Parallelism works. My suggestion to all those of you using MS SQL 2005 or less; "Bail out quick and get you hands on the latest MS SQL... there will be no comparison in performance." A couple of recommended books on the subject are: "Patterns of Parallel Processing" and "Concurrent Programming on Windows" The latest .Net has all these features built in...just ready to use. Jim From jwcolby at colbyconsulting.com Wed May 19 15:03:28 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 May 2010 16:03:28 -0400 Subject: [dba-SQLServer] Parallelism In-Reply-To: <4A52241149474D76AA93A21F31C31BDA@creativesystemdesigns.com> References: <34FFB67A32A64A85A1D61422E34D40CE@creativesystemdesigns.com> <73FC6395D2CA47639932C5A5B5204FEE@creativesystemdesigns.com> <3E23E4865861413788D4FD433E981005@creativesystemdesigns.com> <4A52241149474D76AA93A21F31C31BDA@creativesystemdesigns.com> Message-ID: <4BF44410.30401@colbyconsulting.com> Jim, I am using SQL Server 2008 and I do some pretty hefty table processing. I can tell you that I often get 100% utilization of all the cores I give SQL Server, though I only have a single socket quad core machine with 16 gigs RAM, and I only give SQL Server 3 of the 4 cores and 12 gigs - precisely in an attempt to prevent the "system lockup" that you mention. To be honest this the first time I have seen a "system lock" mentioned, though I absolutely positively believe that is what is happening. I would be interested to know if there is a way to prevent that from ever being implemented. I had a lockup the other day. I learned a couple of things (like assigning a specific number of cores and specific amount of memory) which pretty much made the problem go away but very very sporadically I get one. I waited for a couple of hours for something that didn't seem like it should take that long, then ended up having to reboot my machine. Rebooting a SQL Server while it is "doing something" is pretty scary and usually damages the database that it is working on. John W. Colby www.ColbyConsulting.com Jim Lawrence wrote: > Hi All: > > A couple of nights ago, I went to a series of lectures given by a fellow > named Tiberiu Covaci, Swedish owner of a company called Multi-Core and he is > now doing a tour as a trainer for Microsoft. (His next lecture stop will be > in New Orleans.) > > His training lecture was on Parallelism. The first lecture covered the basic > concepts of computers and their new multi-core design, a design made > necessary as single core computers ran into the physical wall as of 2005. He > then went on to describe the attempts by developers to utilize these new > multi-core systems. It has been a slow process as you can imagine. > > The rudimentary attempts of threading and hyper-threading were far from > successful. First a single thread will consume up to 200 cycles just to get > substantiated and its deployment still requires the central CPU and to spawn > hundreds of threads, in a pool and then there was the issues of > synchronizing the process results. Even the best developed multi-threaded > applications, like MS SQL 2005 could over-load a computer when challenged by > a heavy duty task. MS even went so far as to apply a system lock when > performing resource heavy jobs... that means all other functionality on the > server would cease... no multi-tasking, until the job was completed... even > then sometimes a process would freeze up a server. (We have all heard of > that exact situation from a number of our DBA members.) > > Our lecturer had designed a couple of short programs to showed how > multi-threading was implemented and then demonstrated how these apps when > over-loaded would crash or lock out the system. He used a Quick-sort, demo > while splitting it into multiple pieces, multi-threading it and slowly > increasing the sort data showed a 30 percent gain per thread and a 70 > percent gain per core (maximum gain) but it also showed virtually not > performance loss as the data increased (10 to 100 million records) until the > process locked up the CPU. We watched the system progress via the Task > Manger's CPU display. > > Lecture two; enter Parallelism. This process has being developed on the > latest versions of Java and .Net frame work (4 or greater). He demonstrated > two new core features/objects Parallel and Task. Using Parallelism requires > a bit to decompose a problem into its components. He used an example of a > recipe where a number of steps was required from initial preparation, to the > cooking and to the table. The program which ended calculating the time was > initially designed in a standard C# routine. > > The app was then recoded using Parallel running tasks. Each task can run > independently, but wait for a process to be completed if required by > scheduling, monitoring a semaphore, event, state and/or wait loops. We also > covered how to handle synchronization, data sharing and how to avoid > deadlocks. By using pararllelism the meal was completed in half the time... > It showed how 6 people could do a job faster than one... now that's obvious > but maybe not so obvious with a computer application. > > The most telling observation was when viewing the Task Manger's CPU display. > No matter how heavy the requirements that were imposed on the system, the > CPU demand remained very low and flat and each core showed an even > distribution of utilization. > > I was totally impressed. Now I know how such super databases as Cassandra, > using Java Parallelism works. My suggestion to all those of you using MS SQL > 2005 or less; "Bail out quick and get you hands on the latest MS SQL... > there will be no comparison in performance." > > A couple of recommended books on the subject are: > "Patterns of Parallel Processing" and > "Concurrent Programming on Windows" > > The latest .Net has all these features built in...just ready to use. > > Jim > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jwcolby at colbyconsulting.com Wed May 19 15:18:48 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 May 2010 16:18:48 -0400 Subject: [dba-SQLServer] dynamic sql Message-ID: <4BF447A8.2050004@colbyconsulting.com> Guys, I use dynamic SQL a lot. I have received feedback from others on these groups that "there is never a valid reason for dynamic SQL", there is always a safer "better" way to do this. I would like to lay out what I do and get some feedback on exactly how I would do what I am doing without using dynamic SQL. A couple of examples. I build an entire database for an order for my client. Each database has some fairly specific stuff, as well as data for that order, which I may need to use again for another order. IOW, I select X records, send a small subset of those records off to a client, then months down the road may need to send another subset of those records. Each order is based on selection criteria, and that criteria is different for each order. So I build a table on-the-fly. I have a common set of fields, then I have the selection fields. I then pull all of the data from a view into that custom table. So I have a view. I use code to get the names of the fields in that view and I build a table which has exactly the same fields as the view contains, using dynamic SQL. I use the view to then append the data into the table. Since the table has the same fields as the view, it basically just appends right in. Using dynamic SQL I am able to build any select query I need and build a table which exactly matches that view. Another example. I have many different databases which contain millions of name / address / demographic fields. For example I have a table of 20 million people who have children, with fields for whether they children in specific age brackets. I have another database with 12 million records of people who have cats and / or dogs. Another where... Each of these databases has a name / address component (fields) which are standardized (by me) so that the name / address field names are identical. I then have stored procedures which build name / address tables, append the name / address components out of the central table into a temp table in sorted order, grab just 2 million record chunks, and BCP the records out to files on disk for address validation. There is a similar set of stored procedures where I pull the resulting validated address fields back in to SQL Server into the same database and perform other processing inside of the database. Because I have standardized the field names, I can use dynamic SQL in stored procedures to pass in the name of the database and a table or view name for the export piece and the import piece as well. There are probably 5-10 stored procedures which perform the export process as well as a like number which performs the import. In fact I used to have "hard coded" stored procedures in each database which did this stuff, but maintenance was a nightmare. If I needed to change anything I had to go into each database and modify the stored procedures on a case by case basis. I now have a "master" database where I store my stored procedures and I can simply pass in the parameters to the stored procedure to tell it what database / view to use. One place to edit, one place to go to make modifications. So that gives an overview of some of the ways that I use dynamic SQL. I am looking for the "Why I shouldn't" and what my alternatives are, or comments on when and why dynamic SQL is useful (as I find it useful) and how to go about making the resulting dynamic SQL safe(r) to use. Thanks, -- John W. Colby www.ColbyConsulting.com From accessd at shaw.ca Wed May 19 16:04:52 2010 From: accessd at shaw.ca (Jim Lawrence) Date: Wed, 19 May 2010 14:04:52 -0700 Subject: [dba-SQLServer] dynamic sql In-Reply-To: <4BF447A8.2050004@colbyconsulting.com> References: <4BF447A8.2050004@colbyconsulting.com> Message-ID: <8410EAC79F8C49F7A6B85593736753B6@creativesystemdesigns.com> Using dynamic SQL and sending SQL strings from your app when your application is in your home environment is no problem. ...But if you expose your SQL server to others then a Insertion sort, for the people who know is less than a 10 minute job. I watched a security trainer go through every piece of security (the machine was setup by MS senior IT fellow) on a machine using dynamic sequel in about 10 minutes. Mind you this guy knew every system hack but considering the fellow that otherwise secured the beast used every security method... so I doubt whether anyone but a professional could hack your machines if they were ever exposed to the web. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, May 19, 2010 1:19 PM To: Access Developers discussion and problem solving; Sqlserver-Dba Subject: [dba-SQLServer] dynamic sql Guys, I use dynamic SQL a lot. I have received feedback from others on these groups that "there is never a valid reason for dynamic SQL", there is always a safer "better" way to do this. I would like to lay out what I do and get some feedback on exactly how I would do what I am doing without using dynamic SQL. A couple of examples. I build an entire database for an order for my client. Each database has some fairly specific stuff, as well as data for that order, which I may need to use again for another order. IOW, I select X records, send a small subset of those records off to a client, then months down the road may need to send another subset of those records. Each order is based on selection criteria, and that criteria is different for each order. So I build a table on-the-fly. I have a common set of fields, then I have the selection fields. I then pull all of the data from a view into that custom table. So I have a view. I use code to get the names of the fields in that view and I build a table which has exactly the same fields as the view contains, using dynamic SQL. I use the view to then append the data into the table. Since the table has the same fields as the view, it basically just appends right in. Using dynamic SQL I am able to build any select query I need and build a table which exactly matches that view. Another example. I have many different databases which contain millions of name / address / demographic fields. For example I have a table of 20 million people who have children, with fields for whether they children in specific age brackets. I have another database with 12 million records of people who have cats and / or dogs. Another where... Each of these databases has a name / address component (fields) which are standardized (by me) so that the name / address field names are identical. I then have stored procedures which build name / address tables, append the name / address components out of the central table into a temp table in sorted order, grab just 2 million record chunks, and BCP the records out to files on disk for address validation. There is a similar set of stored procedures where I pull the resulting validated address fields back in to SQL Server into the same database and perform other processing inside of the database. Because I have standardized the field names, I can use dynamic SQL in stored procedures to pass in the name of the database and a table or view name for the export piece and the import piece as well. There are probably 5-10 stored procedures which perform the export process as well as a like number which performs the import. In fact I used to have "hard coded" stored procedures in each database which did this stuff, but maintenance was a nightmare. If I needed to change anything I had to go into each database and modify the stored procedures on a case by case basis. I now have a "master" database where I store my stored procedures and I can simply pass in the parameters to the stored procedure to tell it what database / view to use. One place to edit, one place to go to make modifications. So that gives an overview of some of the ways that I use dynamic SQL. I am looking for the "Why I shouldn't" and what my alternatives are, or comments on when and why dynamic SQL is useful (as I find it useful) and how to go about making the resulting dynamic SQL safe(r) to use. Thanks, -- John W. Colby www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ha at phulse.com Wed May 19 16:31:35 2010 From: ha at phulse.com (Hans-Christian Andersen) Date: Wed, 19 May 2010 22:31:35 +0100 Subject: [dba-SQLServer] dynamic sql In-Reply-To: <4BF447A8.2050004@colbyconsulting.com> References: <4BF447A8.2050004@colbyconsulting.com> Message-ID: Hi John, I'm speaking from beyond the world of Microsoft - the world of PostgreSQL, MySQL and so forth. Two main reasons that spring to mind why dynamic SQL can be a bad idea is: 1. Query caching - This may or may not be the case in your instance. Like I said, I can't really speak for MSSQL, but dynamic sql could very well cause performance problems, if the query cache is unable to cache things properly. 2. Security - Allowing your application to inject SQL into your queries can leave your application dangerously exposed. If this isn't interfacing with a public application, then you don't really have much to worry about. But if it is, little Bobby Tables might very well destroy your database. I prefer to go with properly prepared statements, validation and parameterization, over re-usuable hacks/functions/procedures... Finally, and this is more of an aesthetic point of view, when your code gets to a point where there is too much dynamic generation of "stuff", it can get quite complex to maintain... especially for anyone else who has to look at your code/stored procedures and figure out how it all hangs together. It's just like recursion... it's quite cool when it works, but it's a nightmare to debug when it breaks! [image: exploits_of_a_mom.png] Hans-Christian Software Developer, UK ----------------------------------------------------------------- tel: +44 (0)782 894 5456 e-mail: hans.andersen at phulse.com www: nokenode.com ----------------------------------------------------------------- Unique Gifts, Collectables, Artwork ----------------------------------------------------------------- Come one Come all to www.corinnajasmine.com ----------------------------------------------------------------- On 19 May 2010 21:18, jwcolby wrote: > Guys, > > I use dynamic SQL a lot. I have received feedback from others on these > groups that "there is never > a valid reason for dynamic SQL", there is always a safer "better" way to do > this. > > I would like to lay out what I do and get some feedback on exactly how I > would do what I am doing > without using dynamic SQL. > > A couple of examples. > > I build an entire database for an order for my client. Each database has > some fairly specific > stuff, as well as data for that order, which I may need to use again for > another order. IOW, I > select X records, send a small subset of those records off to a client, > then months down the road > may need to send another subset of those records. > > Each order is based on selection criteria, and that criteria is different > for each order. So I > build a table on-the-fly. I have a common set of fields, then I have the > selection fields. I then > pull all of the data from a view into that custom table. > > So I have a view. I use code to get the names of the fields in that view > and I build a table which > has exactly the same fields as the view contains, using dynamic SQL. I use > the view to then append > the data into the table. Since the table has the same fields as the view, > it basically just appends > right in. Using dynamic SQL I am able to build any select query I need and > build a table which > exactly matches that view. > > Another example. I have many different databases which contain millions of > name / address / > demographic fields. For example I have a table of 20 million people who > have children, with fields > for whether they children in specific age brackets. I have another > database with 12 million records > of people who have cats and / or dogs. Another where... > > Each of these databases has a name / address component (fields) which are > standardized (by me) so > that the name / address field names are identical. I then have stored > procedures which build name / > address tables, append the name / address components out of the central > table into a temp table in > sorted order, grab just 2 million record chunks, and BCP the records out to > files on disk for > address validation. There is a similar set of stored procedures where I > pull the resulting > validated address fields back in to SQL Server into the same database and > perform other processing > inside of the database. > > Because I have standardized the field names, I can use dynamic SQL in > stored procedures to pass in > the name of the database and a table or view name for the export piece and > the import piece as well. > There are probably 5-10 stored procedures which perform the export process > as well as a like > number which performs the import. > > In fact I used to have "hard coded" stored procedures in each database > which did this stuff, but > maintenance was a nightmare. If I needed to change anything I had to go > into each database and > modify the stored procedures on a case by case basis. I now have a > "master" database where I store > my stored procedures and I can simply pass in the parameters to the stored > procedure to tell it what > database / view to use. One place to edit, one place to go to make > modifications. > > So that gives an overview of some of the ways that I use dynamic SQL. I am > looking for the "Why I > shouldn't" and what my alternatives are, or comments on when and why > dynamic SQL is useful (as I > find it useful) and how to go about making the resulting dynamic SQL > safe(r) to use. > > Thanks, > -- > John W. Colby > www.ColbyConsulting.com > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fhtapia at gmail.com Wed May 19 21:00:55 2010 From: fhtapia at gmail.com (Francisco Tapia) Date: Wed, 19 May 2010 19:00:55 -0700 Subject: [dba-SQLServer] dynamic sql In-Reply-To: <4BF447A8.2050004@colbyconsulting.com> References: <4BF447A8.2050004@colbyconsulting.com> Message-ID: Excellent description John, when I get a bit of time I'll write up some sudo code on how to do what you do but a bit more standardized. As it is having all your sprocs (stored procedured) in a central master database certainly helps with maintenance. I saw Shamil's reply and think that partitioned views could be a useful tool but really you are already segragating each dataset in each database. In your situation as I mentioned in the past might be a good passable reason why dynamic sql works. Its not always the case as most systems have user interfaces and any one of those guys could wreck your data. Some user defined functions to ensure parameters are scrubbed might prove useful to you to help strip harmful dynamic syntax. You mentioned that you have standardized fields and tables and you quite possibly have all of this worked out already. As I said I'll comment with more details when I get more time. On 5/19/10, jwcolby wrote: > Guys, > > I use dynamic SQL a lot. I have received feedback from others on these > groups that "there is never > a valid reason for dynamic SQL", there is always a safer "better" way to do > this. > > I would like to lay out what I do and get some feedback on exactly how I > would do what I am doing > without using dynamic SQL. > > A couple of examples. > > I build an entire database for an order for my client. Each database has > some fairly specific > stuff, as well as data for that order, which I may need to use again for > another order. IOW, I > select X records, send a small subset of those records off to a client, then > months down the road > may need to send another subset of those records. > > Each order is based on selection criteria, and that criteria is different > for each order. So I > build a table on-the-fly. I have a common set of fields, then I have the > selection fields. I then > pull all of the data from a view into that custom table. > > So I have a view. I use code to get the names of the fields in that view > and I build a table which > has exactly the same fields as the view contains, using dynamic SQL. I use > the view to then append > the data into the table. Since the table has the same fields as the view, > it basically just appends > right in. Using dynamic SQL I am able to build any select query I need and > build a table which > exactly matches that view. > > Another example. I have many different databases which contain millions of > name / address / > demographic fields. For example I have a table of 20 million people who > have children, with fields > for whether they children in specific age brackets. I have another database > with 12 million records > of people who have cats and / or dogs. Another where... > > Each of these databases has a name / address component (fields) which are > standardized (by me) so > that the name / address field names are identical. I then have stored > procedures which build name / > address tables, append the name / address components out of the central > table into a temp table in > sorted order, grab just 2 million record chunks, and BCP the records out to > files on disk for > address validation. There is a similar set of stored procedures where I > pull the resulting > validated address fields back in to SQL Server into the same database and > perform other processing > inside of the database. > > Because I have standardized the field names, I can use dynamic SQL in stored > procedures to pass in > the name of the database and a table or view name for the export piece and > the import piece as well. > There are probably 5-10 stored procedures which perform the export process > as well as a like > number which performs the import. > > In fact I used to have "hard coded" stored procedures in each database which > did this stuff, but > maintenance was a nightmare. If I needed to change anything I had to go > into each database and > modify the stored procedures on a case by case basis. I now have a "master" > database where I store > my stored procedures and I can simply pass in the parameters to the stored > procedure to tell it what > database / view to use. One place to edit, one place to go to make > modifications. > > So that gives an overview of some of the ways that I use dynamic SQL. I am > looking for the "Why I > shouldn't" and what my alternatives are, or comments on when and why dynamic > SQL is useful (as I > find it useful) and how to go about making the resulting dynamic SQL safe(r) > to use. > > Thanks, > -- > John W. Colby > www.ColbyConsulting.com > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- Sent from my mobile device -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Wed May 19 22:25:26 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 May 2010 23:25:26 -0400 Subject: [dba-SQLServer] dynamic sql In-Reply-To: References: <4BF447A8.2050004@colbyconsulting.com> Message-ID: <4BF4ABA6.1000604@colbyconsulting.com> Francisco, Thanks for the response. I keep my large "source data" databases segregated for a couple of reasons. 1) The tables are largish - tens of millions of records. I have tables with as few as 11 million records clear up to 70 million records. The database files themselves run from 5 GIGS up to hundreds of gigabytes. 2) The hardware I can afford makes dealing with the separated data doable, whereas a merged database scenario would quickly get out of hand. 3)My client (the owner of the data) tends to use just one or two of the databases for any given order. However it is often the case that I will select data where I join the tables in two or occasionally more databases (source tables) together. IOW Women with children ages 0-3 years or 4-7 years AND has a dog. The Children database (20 million records) comes from one source, the cat_dog table (11 million records) from another source. So I have about a dozen of these "source tables" and the client can ask me to "join" any given set of them. I actually do the join on a hash value in each table, where I have hashed the name and address fields and store the hashes. Thus the hash values are identical between the two tables where the name / address info are identical. The hash values are just a shortcut, I could accomplish the same thing using multi-field joins but that is a PITA. Anyway... I drive all of this from C#. I am developing a largish application in C# which executes the stored procedures for any given process. I have an Address validation export process, address validation input process, order fixed width file export process and some others. Because the address validation export / import process is rigorously standardized (by me), I can validate ALL of my "source data" tables using the exact same code. Additionally I can address validate the order data tables with that same process. Basically I just use the same set of out / in stored procedures for each and every database I touch. All driven by my custom C# program. The stored procedures allow me to define the database / table (or view) name to export / import and each SP then has an error code / error message / result code / number of records effected (where applicable). Thus my C# app can monitor for errors on the SQL Server side, watch for number of records effected and so forth and perform error handling / logging up at the application level. Likewise I can log results, dates / times to perform the stored procedure, and so forth. It is slooooowwwly becoming "point and click". The question about dynamic SQL really comes from the fact that I am about to embark on a rewrite of "my" SQL book: http://www.amazon.com/Beginning-SQL-Programmer-Paul-Wilton/dp/0764577328/ref=sr_1_2?ie=UTF8&s=books&qid=1274325300&sr=1-2 I use dynamic SQL a lot, and want to do a chapter on it, but at the same time I want to capture the reality of best practice which apparently is "use it judiciously and with safeguards". I certainly do NOT use it judiciously, I use it everywhere and I have NO safeguards. My specific case allows me to get away with that but I want to do the right thing in the book. Basically I don't know what the right thing is, how to do the safeguards. So this thread is about collecting opinions and methods for doing stuff that is complex enough that dynamic SQL might make sense, but doing it the right way. John W. Colby www.ColbyConsulting.com Francisco Tapia wrote: > Excellent description John, when I get a bit of time I'll write up > some sudo code on how to do what you do but a bit more standardized. > As it is having all your sprocs (stored procedured) in a central > master database certainly helps with maintenance. > > I saw Shamil's reply and think that partitioned views could be a > useful tool but really you are already segragating each dataset in > each database. > > In your situation as I mentioned in the past might be a good passable > reason why dynamic sql works. Its not always the case as most systems > have user interfaces and any one of those guys could wreck your data. > > Some user defined functions to ensure parameters are scrubbed might > prove useful to you to help strip harmful dynamic syntax. You > mentioned that you have standardized fields and tables and you quite > possibly have all of this worked out already. As I said I'll comment > with more details when I get more time. From jwcolby at colbyconsulting.com Thu May 20 07:22:18 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 May 2010 08:22:18 -0400 Subject: [dba-SQLServer] Dynamic SQL article Message-ID: <4BF5297A.7080507@colbyconsulting.com> http://www.sqlservercentral.com/articles/Dynamic+SQL/70109/ -- John W. Colby www.ColbyConsulting.com From David at sierranevada.com Thu May 20 09:51:18 2010 From: David at sierranevada.com (David Lewis) Date: Thu, 20 May 2010 07:51:18 -0700 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: References: Message-ID: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> Hi John: A few questions about how you do things: If I understand your first example correctly, you have database per client (is this one large table, or is it a full-blown relational db with many tables, etc.?). You extract subsets of records repeatedly from that large table. To do this you build a query (the view), which you use to populate a table (SubTable1). From that table you select a subset (SubTable1_a), and later you may select another subset (SubTable1_b). Each of these subsets you persist as physical tables. In this example, why build the physical table (SubTable1)) when the virtual table (the view) will do the same thing? The subsets of the table (SubTable1_a and _b) that are actually sent on to the client can be thought of as 'WHERE xyz=123' clauses to the view that was originally used to populate SubTable1, no? If you kept a record of the where clauses, with other pertinent information, such as date, client, etc., you could reproduce the recordsets at will, and would not need to physically store the data, neither as SubTable1 or as its children _a or _b. I guess the essence of my question is why is it necessary to build a physical table, when you have a virtual table? d lewis ------------------------------ Message: 2 Date: Wed, 19 May 2010 16:18:48 -0400 From: jwcolby Subject: [dba-SQLServer] dynamic sql To: Access Developers discussion and problem solving , Sqlserver-Dba Message-ID: <4BF447A8.2050004 at colbyconsulting.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Guys, I use dynamic SQL a lot. I have received feedback from others on these groups that "there is never a valid reason for dynamic SQL", there is always a safer "better" way to do this. I would like to lay out what I do and get some feedback on exactly how I would do what I am doing without using dynamic SQL. A couple of examples. I build an entire database for an order for my client. Each database has some fairly specific stuff, as well as data for that order, which I may need to use again for another order. IOW, I select X records, send a small subset of those records off to a client, then months down the road may need to send another subset of those records. Each order is based on selection criteria, and that criteria is different for each order. So I build a table on-the-fly. I have a common set of fields, then I have the selection fields. I then pull all of the data from a view into that custom table. So I have a view. I use code to get the names of the fields in that view and I build a table which has exactly the same fields as the view contains, using dynamic SQL. I use the view to then append the data into the table. Since the table has the same fields as the view, it basically just appends right in. Using dynamic SQL I am able to build any select query I need and build a table which exactly matches that view. Another example. I have many different databases which contain millions of name / address / demographic fields. For example I have a table of 20 million people who have children, with fields for whether they children in specific age brackets. I have another database with 12 million records of people who have cats and / or dogs. Another where... Each of these databases has a name / address component (fields) which are standardized (by me) so that the name / address field names are identical. I then have stored procedures which build name / address tables, append the name / address components out of the central table into a temp table in sorted order, grab just 2 million record chunks, and BCP the records out to files on disk for address validation. There is a similar set of stored procedures where I pull the resulting validated address fields back in to SQL Server into the same database and perform other processing inside of the database. Because I have standardized the field names, I can use dynamic SQL in stored procedures to pass in the name of the database and a table or view name for the export piece and the import piece as well. There are probably 5-10 stored procedures which perform the export process as well as a like number which performs the import. In fact I used to have "hard coded" stored procedures in each database which did this stuff, but maintenance was a nightmare. If I needed to change anything I had to go into each database and modify the stored procedures on a case by case basis. I now have a "master" database where I store my stored procedures and I can simply pass in the parameters to the stored procedure to tell it what database / view to use. One place to edit, one place to go to make modifications. So that gives an overview of some of the ways that I use dynamic SQL. I am looking for the "Why I shouldn't" and what my alternatives are, or comments on when and why dynamic SQL is useful (as I find it useful) and how to go about making the resulting dynamic SQL safe(r) to use. Thanks, -- John W. Colby www.ColbyConsulting.com ------------------------------ The contents of this e-mail message and its attachments are covered by the Electronic Communications Privacy Act (18 U.S.C. 2510-2521) and are intended solely for the addressee(s) hereof. If you are not the named recipient, or the employee or agent responsible for delivering the message to the intended recipient, or if this message has been addressed to you in error, you are directed not to read, disclose, reproduce, distribute, disseminate or otherwise use this transmission. If you have received this communication in error, please notify us immediately by return e-mail or by telephone, 530-893-3520, and delete and/or destroy all copies of the message immediately. From fhtapia at gmail.com Thu May 20 10:17:06 2010 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 20 May 2010 08:17:06 -0700 Subject: [dba-SQLServer] dynamic sql In-Reply-To: <4BF4ABA6.1000604@colbyconsulting.com> References: <4BF447A8.2050004@colbyconsulting.com> <4BF4ABA6.1000604@colbyconsulting.com> Message-ID: I can see where your getting at and I'll tell you, there are various sources on the 'net that will all state that dynamic sql is close to being evil... not quite.. but close enough ;). I think in general the problem is sanitizing your database inputs ( http://imgs.xkcd.com/comics/exploits_of_a_mom.png ) I'll explain a bit further... in many situations because we are programmers we like to break things down to re-usable code... and there is nothing re-usable when you have a new view for each table hardcoded. BUT... there are other things to consider when you are programming in SQL Server that lend themselves more towards performance than re-usable code. Obviously i'm not stating that you shouldn't aim for re-usable code... but simply that there are situations when you need to consider the cached performance by creating separate views and stored procedures that provide faster returns of data to give your users the illusion of uber faster system performance. It certainly possible to re-use a dynamic sql query plan instead of having to generate a new one from scratch everytime... to do this you'd change your EXEC (@sql) statment to something more like that of the syntax for sp_executesql which actually allows you to re-use your dynamic sql with parameters, using EXEC will force the engine to generate a new query plan every time, causing a performance hit. a major caveat that you need to inform your users of, because "GENERALLY" you'd program access to your database via Views, Stored Procedures and Functions, limiting any access to tables. This maybe something that depends on the project itself as this is in no way a hard set rule, but one that I like to follow as close as I can. In many instances it's not necessary for your users to have direct access to a table... that is not to say that giving SELECT access to a table because of a dynamic sql is not ok, it most certainly is, but depending on the interface you could be exposing more than you bargain for in these situations... FOR instance you've generated select rights to a table but did not limit the exclusions on your security rights... then your users could accidentally look at data that is not privy to them... I had to do something similar not too long ago when we generated an encrypted storage of Credit Card #'s, because of the sensitivity I designed the security to not allow display access of the credit card field to any of the users who were pursuing the database table. Instead access was limited via stored procedures and views that prevented users from gaining any type of access. I also limited my assistant DBA from gaining access to the database by simply giving him access to backup the databases on that specific server, preventing an accidental leak of data. I did go overboard I guess a bit on the security for that system but it contains a lot of sensitive information, and I would not trust dynamic sql to provide me all the security that I wanted especially if for some reason we were hacked internally. I do have more points and I'll add them on as I get more time to discuss... -Francisco http://sqlthis.blogspot.com | Tsql and More... On Wed, May 19, 2010 at 8:25 PM, jwcolby wrote: > Francisco, > > Thanks for the response. > > I keep my large "source data" databases segregated for a couple of reasons. > > 1) The tables are largish - tens of millions of records. I have tables > with as few as 11 million > records clear up to 70 million records. The database files themselves run > from 5 GIGS up to > hundreds of gigabytes. > 2) The hardware I can afford makes dealing with the separated data doable, > whereas a merged database > scenario would quickly get out of hand. > 3)My client (the owner of the data) tends to use just one or two of the > databases for any given > order. However it is often the case that I will select data where I join > the tables in two or > occasionally more databases (source tables) together. > > IOW Women with children ages 0-3 years or 4-7 years AND has a dog. The > Children database (20 > million records) comes from one source, the cat_dog table (11 million > records) from another source. > So I have about a dozen of these "source tables" and the client can ask > me to "join" any given > set of them. > > I actually do the join on a hash value in each table, where I have hashed > the name and address > fields and store the hashes. Thus the hash values are identical between > the two tables where the > name / address info are identical. The hash values are just a shortcut, I > could accomplish the same > thing using multi-field joins but that is a PITA. > > Anyway... > > I drive all of this from C#. I am developing a largish application in C# > which executes the stored > procedures for any given process. I have an Address validation export > process, address validation > input process, order fixed width file export process and some others. > Because the address > validation export / import process is rigorously standardized (by me), I > can validate ALL of my > "source data" tables using the exact same code. Additionally I can address > validate the order data > tables with that same process. Basically I just use the same set of out / > in stored procedures for > each and every database I touch. All driven by my custom C# program. > > The stored procedures allow me to define the database / table (or view) > name to export / import and > each SP then has an error code / error message / result code / number of > records effected (where > applicable). Thus my C# app can monitor for errors on the SQL Server side, > watch for number of > records effected and so forth and perform error handling / logging up at > the application level. > Likewise I can log results, dates / times to perform the stored procedure, > and so forth. > > It is slooooowwwly becoming "point and click". > > The question about dynamic SQL really comes from the fact that I am about > to embark on a rewrite of > "my" SQL book: > > > http://www.amazon.com/Beginning-SQL-Programmer-Paul-Wilton/dp/0764577328/ref=sr_1_2?ie=UTF8&s=books&qid=1274325300&sr=1-2 > > I use dynamic SQL a lot, and want to do a chapter on it, but at the same > time I want to capture the > reality of best practice which apparently is "use it judiciously and with > safeguards". I certainly > do NOT use it judiciously, I use it everywhere and I have NO safeguards. > My specific case allows me > to get away with that but I want to do the right thing in the book. > > Basically I don't know what the right thing is, how to do the safeguards. > So this thread is about > collecting opinions and methods for doing stuff that is complex enough that > dynamic SQL might make > sense, but doing it the right way. > > John W. Colby > www.ColbyConsulting.com > > > Francisco Tapia wrote: > > Excellent description John, when I get a bit of time I'll write up > > some sudo code on how to do what you do but a bit more standardized. > > As it is having all your sprocs (stored procedured) in a central > > master database certainly helps with maintenance. > > > > I saw Shamil's reply and think that partitioned views could be a > > useful tool but really you are already segragating each dataset in > > each database. > > > > In your situation as I mentioned in the past might be a good passable > > reason why dynamic sql works. Its not always the case as most systems > > have user interfaces and any one of those guys could wreck your data. > > > > Some user defined functions to ensure parameters are scrubbed might > > prove useful to you to help strip harmful dynamic syntax. You > > mentioned that you have standardized fields and tables and you quite > > possibly have all of this worked out already. As I said I'll comment > > with more details when I get more time. > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fhtapia at gmail.com Thu May 20 10:22:16 2010 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 20 May 2010 08:22:16 -0700 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> References: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> Message-ID: I think it boils down to speed and accuracy of data. A view will always generate a truthful representation of the available data.. so if you add new records or as John does, processes them through his validator scheme, then the results of the View will be different from his original resultset, and what he needs is an exact copy of the original order, thus the physical tables. secondly i think it also boils down to speed... if his original table is a 70million row table and you've already extracted the results to a 2million row table, it's much faster to quickly re-generate the report for your client from the 2m table than the 70m, saving you time, and producing the exact results... I think he's said in the past that he may be asked to provide resultsA... then maybe asked for that same resultset agian a 2nd time.. or to generate a derivative from resultsA to generate a resultAsubB as an example... in any case it seems like a shame to not be able to provide all available records if new demographic data is suddenly made available... but that's just me. -Francisco http://sqlthis.blogspot.com | Tsql and More... On Thu, May 20, 2010 at 7:51 AM, David Lewis wrote: > Hi John: A few questions about how you do things: > > If I understand your first example correctly, you have database per client > (is this one large table, or is it a full-blown relational db with many > tables, etc.?). You extract subsets of records repeatedly from that large > table. To do this you build a query (the view), which you use to populate a > table (SubTable1). From that table you select a subset (SubTable1_a), and > later you may select another subset (SubTable1_b). Each of these subsets > you persist as physical tables. > In this example, why build the physical table (SubTable1)) when the virtual > table (the view) will do the same thing? The subsets of the table > (SubTable1_a and _b) that are actually sent on to the client can be thought > of as 'WHERE xyz=123' clauses to the view that was originally used to > populate SubTable1, no? If you kept a record of the where clauses, with > other pertinent information, such as date, client, etc., you could reproduce > the recordsets at will, and would not need to physically store the data, > neither as SubTable1 or as its children _a or _b. > > I guess the essence of my question is why is it necessary to build a > physical table, when you have a virtual table? > > d lewis > ------------------------------ > > Message: 2 > Date: Wed, 19 May 2010 16:18:48 -0400 > From: jwcolby > Subject: [dba-SQLServer] dynamic sql > To: Access Developers discussion and problem solving > , Sqlserver-Dba > > Message-ID: <4BF447A8.2050004 at colbyconsulting.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Guys, > > I use dynamic SQL a lot. I have received feedback from others on these > groups that "there is never > a valid reason for dynamic SQL", there is always a safer "better" way to do > this. > > I would like to lay out what I do and get some feedback on exactly how I > would do what I am doing > without using dynamic SQL. > > A couple of examples. > > I build an entire database for an order for my client. Each database has > some fairly specific > stuff, as well as data for that order, which I may need to use again for > another order. IOW, I > select X records, send a small subset of those records off to a client, > then months down the road > may need to send another subset of those records. > > Each order is based on selection criteria, and that criteria is different > for each order. So I > build a table on-the-fly. I have a common set of fields, then I have the > selection fields. I then > pull all of the data from a view into that custom table. > > So I have a view. I use code to get the names of the fields in that view > and I build a table which > has exactly the same fields as the view contains, using dynamic SQL. I use > the view to then append > the data into the table. Since the table has the same fields as the view, > it basically just appends > right in. Using dynamic SQL I am able to build any select query I need and > build a table which > exactly matches that view. > > Another example. I have many different databases which contain millions of > name / address / > demographic fields. For example I have a table of 20 million people who > have children, with fields > for whether they children in specific age brackets. I have another > database with 12 million records > of people who have cats and / or dogs. Another where... > > Each of these databases has a name / address component (fields) which are > standardized (by me) so > that the name / address field names are identical. I then have stored > procedures which build name / > address tables, append the name / address components out of the central > table into a temp table in > sorted order, grab just 2 million record chunks, and BCP the records out to > files on disk for > address validation. There is a similar set of stored procedures where I > pull the resulting > validated address fields back in to SQL Server into the same database and > perform other processing > inside of the database. > > Because I have standardized the field names, I can use dynamic SQL in > stored procedures to pass in > the name of the database and a table or view name for the export piece and > the import piece as well. > There are probably 5-10 stored procedures which perform the export process > as well as a like > number which performs the import. > > In fact I used to have "hard coded" stored procedures in each database > which did this stuff, but > maintenance was a nightmare. If I needed to change anything I had to go > into each database and > modify the stored procedures on a case by case basis. I now have a > "master" database where I store > my stored procedures and I can simply pass in the parameters to the stored > procedure to tell it what > database / view to use. One place to edit, one place to go to make > modifications. > > So that gives an overview of some of the ways that I use dynamic SQL. I am > looking for the "Why I > shouldn't" and what my alternatives are, or comments on when and why > dynamic SQL is useful (as I > find it useful) and how to go about making the resulting dynamic SQL > safe(r) to use. > > Thanks, > -- > John W. Colby > www.ColbyConsulting.com > > > ------------------------------ > > > The contents of this e-mail message and its attachments are covered by the > Electronic Communications Privacy Act (18 U.S.C. 2510-2521) and are intended > solely for the addressee(s) hereof. If you are not the named recipient, or > the employee or agent responsible for delivering the message to the intended > recipient, or if this message has been addressed to you in error, you are > directed not to read, disclose, reproduce, distribute, disseminate or > otherwise use this transmission. If you have received this communication in > error, please notify us immediately by return e-mail or by telephone, > 530-893-3520, and delete and/or destroy all copies of the message > immediately. > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jwcolby at colbyconsulting.com Thu May 20 11:59:08 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 May 2010 12:59:08 -0400 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> References: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> Message-ID: <4BF56A5C.5090008@colbyconsulting.com> David, > If I understand your first example correctly, you have database per client All of this stuff is for MY client (one client). My client gives me huge "lists" (as he calls them) of name / address info, tens of millions of names. I extract each "list" into its own database. So I have a "Children's" database, a "Dog owners" database, a "smokers" database, a ... Each list pretty much comes from a different source, they are purchased from list providers on the open market. I "normalize" them to have the same fields, with the same field names etc, plus a PK autonumber. I then address validate them and start to use them. >You extract subsets of records repeatedly from that large table. To do this you build a query (the view), which you use to populate a table (SubTable1). From that table you select a subset (SubTable1_a), and later you may select another subset (SubTable1_b). Each of these subsets you persist as physical tables. No. I build a view which may be a join of one or many of those "lists" as my client calls them. Once I have selected some records, I persist them, ALONG WITH the fields that are the selection criteria. THOSE SELECTION CRITERIA FIELDS change from order to order. Even the parent "list tables" change from order to order. > In this example, why build the physical table (SubTable1)) when the virtual table (the view) will do the same thing? Several reasons. 1) The real table is a subset of these list tables and is exactly the set of records which match some criteria FOR THAT ORDER. The original view can take minutes or even hours (OK a slight exaggeration but you get the point) to process and get the result set for. 2) The "View" is a join of several different tables, even of several different "lists" (which is why it can take a loooooonnnnng time to select the records that go in the real order table). 3) I have to mark the REAL order table with additional selection criteria. For example the client says "Within the selected records, I want to select X records where XYZ is true, Y records where ABC is true and Z records where JKL is true". In order to do that, I add three fields which I use just for this purpose. Additionally I have a "key" field which I end up putting a text string "key" in that is provided by the client for each of these orders. Obviously if I do not have a "real table" I cannot do that. I need to process subsequent orders against previous orders and not send the same names / addresses out again (sometimes). All of which brings up this point. What I am doing is extremely complex and cannot be adequately described in a single email. I do what I do because I am doing some pretty complicated processing for the client. I am not looking for advice on how to modify that process, if for no other reason than without a multi-day class on the subject, it is not possible for you to understand what these processes are never mind how to make them more efficient. I would LOVE to make them more efficient, but that (as they say) is "beyond the scope of this thread". In the end everyone will use dynamic SQL for their own reasons and their own processes. What is important is not a process redesign, but a "best practices" discussion on HOW to use dynamic SQL when it is required. John W. Colby www.ColbyConsulting.com David Lewis wrote: > Hi John: A few questions about how you do things: > > If I understand your first example correctly, you have database per client (is this one large table, or is it a full-blown relational db with many tables, etc.?). You extract subsets of records repeatedly from that large table. To do this you build a query (the view), which you use to populate a table (SubTable1). From that table you select a subset (SubTable1_a), and later you may select another subset (SubTable1_b). Each of these subsets you persist as physical tables. > In this example, why build the physical table (SubTable1)) when the virtual table (the view) will do the same thing? The subsets of the table (SubTable1_a and _b) that are actually sent on to the client can be thought of as 'WHERE xyz=123' clauses to the view that was originally used to populate SubTable1, no? If you kept a record of the where clauses, with other pertinent information, such as date, client, etc., you could reproduce the recordsets at will, and would not need to physically store the data, neither as SubTable1 or as its children _a or _b. > > I guess the essence of my question is why is it necessary to build a physical table, when you have a virtual table? > > d lewis From davidmcafee at gmail.com Thu May 20 12:48:20 2010 From: davidmcafee at gmail.com (David McAfee) Date: Thu, 20 May 2010 10:48:20 -0700 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: <4BF56A5C.5090008@colbyconsulting.com> References: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> <4BF56A5C.5090008@colbyconsulting.com> Message-ID: John do you work for http://www.spokeo.com ? :) On Thu, May 20, 2010 at 9:59 AM, jwcolby wrote: > David, > > ?> If I understand your first example correctly, you have database per client > > All of this stuff is for MY client (one client). ?My client gives me huge "lists" (as he calls them) > of name / address info, tens of millions of names. ?I extract each "list" into its own database. ?So > I have a "Children's" database, a "Dog owners" database, a "smokers" database, a ... ?Each list > pretty much comes from a different source, they are purchased from list providers on the open > market. ?I "normalize" them to have the same fields, with the same field names etc, plus a PK > autonumber. ?I then address validate them and start to use them. > > ?>You extract subsets of records repeatedly from that large table. ?To do this you build a query > (the view), which you use to populate a table (SubTable1). ?From that table you select a subset > (SubTable1_a), and later you may select another subset (SubTable1_b). ?Each of these subsets you > persist as physical tables. > > No. ?I build a view which may be a join of one or many of those "lists" as my client calls them. > Once I have selected some records, I persist them, ALONG WITH the fields that are the selection > criteria. ?THOSE SELECTION CRITERIA FIELDS change from order to order. ?Even the parent "list > tables" change from order to order. > > ?> In this example, why build the physical table (SubTable1)) when the virtual table (the view) will > do the same thing? > > Several reasons. > > 1) The real table is a subset of these list tables and is exactly the set of records which match > some criteria FOR THAT ORDER. ?The original view can take minutes or even hours (OK a slight > exaggeration but you get the point) to process and get the result set for. > 2) The "View" is a join of several different tables, even of several different "lists" (which is why > it can take a loooooonnnnng time to select the records that go in the real order table). > 3) I have to mark the REAL order table with additional selection criteria. ?For example the client > says "Within the selected records, I want to select X records where XYZ is true, Y records where ABC > is true and Z records where JKL is true". ?In order to do that, I add three fields which I use just > for this purpose. ?Additionally I have a "key" field which I end up putting a text string "key" in > that is provided by the client for each of these orders. ?Obviously if I do not have a "real table" > I cannot do that. > > I need to process subsequent orders against previous orders and not send the same names / addresses > out again (sometimes). > > All of which brings up this point. ?What I am doing is extremely complex and cannot be adequately > described in a single email. ?I do what I do because I am doing some pretty complicated processing > for the client. ?I am not looking for advice on how to modify that process, if for no other reason > than without a multi-day class on the subject, it is not possible for you to understand what these > processes are never mind how to make them more efficient. ?I would LOVE to make them more efficient, > but that (as they say) is "beyond the scope of this thread". > > In the end everyone will use dynamic SQL for their own reasons and their own processes. ?What is > important is not a process redesign, but a "best practices" discussion on HOW to use dynamic SQL > when it is required. > > John W. Colby > www.ColbyConsulting.com > > > David Lewis wrote: >> Hi John: ?A few questions about how you do things: >> >> If I understand your first example correctly, you have database per client (is this one large table, or is it a full-blown relational db with many tables, etc.?). ?You extract subsets of records repeatedly from that large table. ?To do this you build a query (the view), which you use to populate a table (SubTable1). ?From that table you select a subset (SubTable1_a), and later you may select another subset (SubTable1_b). ?Each of these subsets you persist as physical tables. >> In this example, why build the physical table (SubTable1)) when the virtual table (the view) will do the same thing? ?The subsets of the table (SubTable1_a and _b) that are actually sent on to the client can be thought of as 'WHERE xyz=123' clauses to the view that was originally used to populate SubTable1, no? ?If you kept a record of the where clauses, with other pertinent information, such as date, client, etc., you could reproduce the recordsets at will, and would not need to physically store the data, neither as SubTable1 or as its children _a or _b. >> >> I guess the essence of my question is why is it necessary to build a physical table, when you have a virtual table? >> >> d lewis > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jwcolby at colbyconsulting.com Thu May 20 12:54:44 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 May 2010 13:54:44 -0400 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: References: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> Message-ID: <4BF57764.6010803@colbyconsulting.com> Exactly right Francisco. I need to capture a snapshot of exactly what existed for that order and then get back to that exact dataset later quickly and easily. I also need to "mark up" those records as I use them for a specific order. I may use some or all of those records for a different "client" in a different order, but for the original "client" they do not want to see records they have already purchased. Thus as I send them out I mark them as "used", but they are only "used" for that client, and in fact sometimes only for that "order". And while I am always willing to expound on the why, it really isn't possible to suggest a "redesign" of the process without a LOT more information on what I am doing and why. Don't get me wrong, I do in fact modify my processes as I find better ways of doing things, but this is pretty complicated stuff. What I am trying to get is not "how do I make my process better" but rather "how can I use dynamic SQL better". They really are completely independent subjects, and I need info on the dynamic sql side of the house. John W. Colby www.ColbyConsulting.com Francisco Tapia wrote: > I think it boils down to speed and accuracy of data. A view will always > generate a truthful representation of the available data.. so if you add new > records or as John does, processes them through his validator scheme, then > the results of the View will be different from his original resultset, and > what he needs is an exact copy of the original order, thus the physical > tables. secondly i think it also boils down to speed... if his original > table is a 70million row table and you've already extracted the results to a > 2million row table, it's much faster to quickly re-generate the report for > your client from the 2m table than the 70m, saving you time, and producing > the exact results... > > I think he's said in the past that he may be asked to provide resultsA... > then maybe asked for that same resultset agian a 2nd time.. or to generate a > derivative from resultsA to generate a resultAsubB as an example... in any > case it seems like a shame to not be able to provide all available records > if new demographic data is suddenly made available... but that's just me. > -Francisco > http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Thu May 20 12:55:47 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 May 2010 13:55:47 -0400 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: References: <01606FC26AD0E54B8348D886D0C074D33C368A3EFB@schwarz.sierranevada.corp> <4BF56A5C.5090008@colbyconsulting.com> Message-ID: <4BF577A3.6050107@colbyconsulting.com> ROTFL. No, but close. John W. Colby www.ColbyConsulting.com David McAfee wrote: > John do you work for http://www.spokeo.com ? :) From jwcolby at colbyconsulting.com Fri May 21 12:25:34 2010 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 21 May 2010 13:25:34 -0400 Subject: [dba-SQLServer] sql server migration assistant Message-ID: <4BF6C20E.4020300@colbyconsulting.com> Has anyone used the SQL Server Migration Assistant for SQL server 2008? Pros / cons / comparisons to the upsizing wizard? I just looked at it today for the first time and it seems pretty good, but I haven't done an extensive eval. -- John W. Colby www.ColbyConsulting.com From michael at ddisolutions.com.au Mon May 24 02:10:36 2010 From: michael at ddisolutions.com.au (Michael Maddison) Date: Mon, 24 May 2010 17:10:36 +1000 Subject: [dba-SQLServer] sql server migration assistant References: <4BF6C20E.4020300@colbyconsulting.com> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> I've used it once with no problems IIRC. I didn't have much data to deal with though. IIRC it lets you specify datatypes and lengths before you convert, gives a comprehensive report and lets you save the config. Cheers Michael Has anyone used the SQL Server Migration Assistant for SQL server 2008? Pros / cons / comparisons to the upsizing wizard? I just looked at it today for the first time and it seems pretty good, but I haven't done an extensive eval. -- John W. Colby www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.819 / Virus Database: 271.1.1/2884 - Release Date: 05/21/10 04:26:00 From marklbreen at gmail.com Mon May 24 03:32:27 2010 From: marklbreen at gmail.com (Mark Breen) Date: Mon, 24 May 2010 09:32:27 +0100 Subject: [dba-SQLServer] sql server migration assistant In-Reply-To: <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> References: <4BF6C20E.4020300@colbyconsulting.com> <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: hello John, I also have used it to upsize - once from Oracle to SQL and once from Access to SQL. On both occasions it worked very well, be careful to review the reports, sometimes a table is not migrated and you must notice this and fix the issue (nulls in the PK field in Access on one occasion) Thanks Mark On 24 May 2010 08:10, Michael Maddison wrote: > I've used it once with no problems IIRC. > I didn't have much data to deal with though. > IIRC it lets you specify datatypes and lengths before you convert, gives > a comprehensive report and lets you save the config. > > Cheers > > Michael > > Has anyone used the SQL Server Migration Assistant for SQL server 2008? > Pros / cons / comparisons > to the upsizing wizard? > > I just looked at it today for the first time and it seems pretty good, > but I haven't done an > extensive eval. > > -- > John W. Colby > www.ColbyConsulting.com > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.819 / Virus Database: 271.1.1/2884 - Release Date: 05/21/10 > 04:26:00 > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Tue May 25 10:11:30 2010 From: jnatola at hotmail.com (Jean-Paul natola) Date: Tue, 25 May 2010 11:11:30 -0400 Subject: [dba-SQLServer] search entire db In-Reply-To: <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> References: <4BF6C20E.4020300@colbyconsulting.com>, <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: hI all, I'm pretty much suck at sql but I being the ONLY IT person in my organization , i have to deal with it from time to time. I need to find and entry JV0505-10 in the accounting database, but I dont even know what table to look in, can i search the all the tables from a single query? if so what would be the syntax? The alternative woudl be to export all the tables to excel and search them the db is ~300 mb and consists of about 180 tables thx _________________________________________________________________ Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 From fhtapia at gmail.com Tue May 25 10:26:29 2010 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 25 May 2010 08:26:29 -0700 Subject: [dba-SQLServer] search entire db In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com> <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: I wrote about that not too long ago... check it out... http://sqlthis.blogspot.com/2009/07/uto-unidentified-table-object.html -Francisco http://sqlthis.blogspot.com | Tsql and More... On Tue, May 25, 2010 at 8:11 AM, Jean-Paul natola wrote: > > > > hI all, > > I'm pretty much suck at sql but I being the ONLY IT person in my > organization , i have to deal with it from time to time. > > I need to find and entry JV0505-10 in the accounting database, but I dont > even know what table to look in, can i search the all the tables from a > single query? if so what would be the syntax? > > The alternative woudl be to export all the tables to excel and search them > > > > the db is ~300 mb and consists of about 180 tables > > thx > > > _________________________________________________________________ > Hotmail has tools for the New Busy. Search, chat and e-mail from your > inbox. > > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Tue May 25 11:23:53 2010 From: jnatola at hotmail.com (Jean-Paul natola) Date: Tue, 25 May 2010 12:23:53 -0400 Subject: [dba-SQLServer] search entire db In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com>, <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local>, , Message-ID: I know this is trivial to the rest of you, but HOW do i add/register/create it I tried to create new sproc , copied the code into it , saved it and when I try to execut it it returns Msg 2812, Level 16, State 62, Line 1 Could not find stored procedure 'SearcAllTablesAllColumns'. > From: fhtapia at gmail.com > Date: Tue, 25 May 2010 08:26:29 -0700 > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] search entire db > > I wrote about that not too long ago... > > check it out... > > http://sqlthis.blogspot.com/2009/07/uto-unidentified-table-object.html > > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > > > On Tue, May 25, 2010 at 8:11 AM, Jean-Paul natola wrote: > > > > > > > > > hI all, > > > > I'm pretty much suck at sql but I being the ONLY IT person in my > > organization , i have to deal with it from time to time. > > > > I need to find and entry JV0505-10 in the accounting database, but I dont > > even know what table to look in, can i search the all the tables from a > > single query? if so what would be the syntax? > > > > The alternative woudl be to export all the tables to excel and search them > > > > > > > > the db is ~300 mb and consists of about 180 tables > > > > thx > > > > > > _________________________________________________________________ > > Hotmail has tools for the New Busy. Search, chat and e-mail from your > > inbox. > > > > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 > > _______________________________________________ > > dba-SQLServer mailing list > > dba-SQLServer at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 From dbdoug at gmail.com Tue May 25 11:36:14 2010 From: dbdoug at gmail.com (Doug Steele) Date: Tue, 25 May 2010 09:36:14 -0700 Subject: [dba-SQLServer] search entire db In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com> <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: I'm not trying to be rude here, but is the name of the sproc that you saved exactly the same as the name you are trying to execute? Doug Steele On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola wrote: > > I know this is trivial to the rest of you, but HOW do i add/register/create > it > > I tried to create new sproc , copied the code into it , saved it and when I > try to execut it it returns > > > > Msg 2812, Level 16, State 62, Line 1 > > Could not find stored procedure 'SearcAllTablesAllColumns'. > > > From jnatola at hotmail.com Tue May 25 11:43:58 2010 From: jnatola at hotmail.com (Jean-Paul natola) Date: Tue, 25 May 2010 12:43:58 -0400 Subject: [dba-SQLServer] search entire db In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com>, <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local>, , , , Message-ID: yes, and i cought the typo 'SearcAllTablesAllColumns'. I'm not entirely sure how it works in sql but , maybe im saving it incorrectly? or in the wrong location? > Date: Tue, 25 May 2010 09:36:14 -0700 > From: dbdoug at gmail.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] search entire db > > I'm not trying to be rude here, but is the name of the sproc that you saved > exactly the same as the name you are trying to execute? > > Doug Steele > > On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola wrote: > > > > > I know this is trivial to the rest of you, but HOW do i add/register/create > > it > > > > I tried to create new sproc , copied the code into it , saved it and when I > > try to execut it it returns > > > > > > > > Msg 2812, Level 16, State 62, Line 1 > > > > Could not find stored procedure 'SearcAllTablesAllColumns'. > > > > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ The New Busy is not the old busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 From davidmcafee at gmail.com Tue May 25 12:10:27 2010 From: davidmcafee at gmail.com (David McAfee) Date: Tue, 25 May 2010 10:10:27 -0700 Subject: [dba-SQLServer] search entire db In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com> <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: I used the code from the listing and had no typos If you have already created the sproc, change the word CREATE to ALTER --****************************** start of sproc --This stored procedure creates a temporary table for storing search result data and steps through each column found. CREATE PROC [dbo].[SearchAllTablesAllColumns] ( @SearchStr nvarchar(100) ) AS BEGIN -- Purpose: To search all columns in all tables for a given search string -- Written by: Francisco Tapia -- Site: http://sqlthis.blogspot.com -- Inspired by: Narayana Vyas Kondreddi -- http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm -- Tested on: SQL Server 7.0, 2000 and 2005 -- Date modified: June 23, 2009 CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630)) SET NOCOUNT ON DECLARE @TableName nvarchar(256), @ColumnName nvarchar(255), @Parse AS INT SELECT @TableName = '', @ColumnName = '' SET @SearchStr = QUOTENAME('%' + @SearchStr + '%','''') WHILE (@ColumnName IS NOT NULL) BEGIN SET @ColumnName = ( SELECT MIN(QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) + '|' + QUOTENAME(C.Column_name)) FROM INFORMATION_SCHEMA.COLUMNS c INNER JOIN INFORMATION_SCHEMA.TABLES t on c.table_schema = t.table_schema and c.Table_name = t.table_name WHERE T.TABLE_TYPE = 'BASE TABLE' AND C.DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'text', 'ntext') AND QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) + '.' + QUOTENAME(COLUMN_NAME) > @TableName + '.' + @ColumnName ) SET @Parse = PATINDEX ('%|%', @ColumnName) SET @TableName = SUBSTRING(@ColumnName, 1, @Parse - 1) SET @ColumnName = SUBSTRING(@ColumnName, @Parse +1, LEN(@ColumnName)) IF @ColumnName IS NOT NULL BEGIN INSERT INTO #Results EXEC ( 'SELECT ''' + @TableName + '.' + @ColumnName + ''', SUBSTRING(' + @ColumnName + ',1, 3630) FROM ' + @TableName + ' (NOLOCK) ' + ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr ) END END SELECT ColumnName, ColumnValue FROM #Results ORDER BY ColumnName END --******************************** END of Sproc This is how you call the procedure: EXEC SearchAllTablesAllColumns 'YourSearchTextHere' On Tue, May 25, 2010 at 9:43 AM, Jean-Paul natola wrote: > > yes, and i cought the typo > 'SearcAllTablesAllColumns'. > > > > I'm not entirely sure how it works in sql but , maybe im saving it incorrectly? or in the wrong location? > > > > > > > > >> Date: Tue, 25 May 2010 09:36:14 -0700 >> From: dbdoug at gmail.com >> To: dba-sqlserver at databaseadvisors.com >> Subject: Re: [dba-SQLServer] search entire db >> >> I'm not trying to be rude here, but is the name of the sproc that you saved >> exactly the same as the name you are trying to execute? >> >> Doug Steele >> >> On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola wrote: >> >> > >> > I know this is trivial to the rest of you, but HOW do i add/register/create >> > it >> > >> > I tried to create new sproc , copied the code into it , saved it and when I >> > try to execut it it returns >> > >> > >> > >> > Msg 2812, Level 16, State 62, Line 1 >> > >> > Could not find stored procedure 'SearcAllTablesAllColumns'. >> > >> > >> > >> _______________________________________________ >> dba-SQLServer mailing list >> dba-SQLServer at databaseadvisors.com >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >> http://www.databaseadvisors.com >> > > _________________________________________________________________ > The New Busy is not the old busy. Search, chat and e-mail from your inbox. > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Tue May 25 12:15:25 2010 From: jnatola at hotmail.com (Jean-Paul natola) Date: Tue, 25 May 2010 13:15:25 -0400 Subject: [dba-SQLServer] search entire db In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com>, <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local>, , , , , , Message-ID: on eother thing I noticed while looking at the existing sprocs in the account DB is that they start with USE [dbname] is that required as well? > Date: Tue, 25 May 2010 10:10:27 -0700 > From: davidmcafee at gmail.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] search entire db > > I used the code from the listing and had no typos > If you have already created the sproc, change the word CREATE to ALTER > > --****************************** start of sproc > > --This stored procedure creates a temporary table for storing search > result data and steps through each column found. > > CREATE PROC [dbo].[SearchAllTablesAllColumns] > ( > @SearchStr nvarchar(100) > ) > AS > BEGIN > -- Purpose: To search all columns in all tables for a given search string > -- Written by: Francisco Tapia > -- Site: http://sqlthis.blogspot.com > -- Inspired by: Narayana Vyas Kondreddi > -- http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm > -- Tested on: SQL Server 7.0, 2000 and 2005 > -- Date modified: June 23, 2009 > > CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630)) > > SET NOCOUNT ON > > DECLARE @TableName nvarchar(256), @ColumnName nvarchar(255), @Parse AS INT > > SELECT @TableName = '', @ColumnName = '' > SET @SearchStr = QUOTENAME('%' + @SearchStr + '%','''') > > WHILE (@ColumnName IS NOT NULL) > BEGIN > SET @ColumnName = ( > SELECT MIN(QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) > + '|' + QUOTENAME(C.Column_name)) > FROM INFORMATION_SCHEMA.COLUMNS c > INNER JOIN INFORMATION_SCHEMA.TABLES t on > c.table_schema = t.table_schema and c.Table_name = t.table_name > WHERE T.TABLE_TYPE = 'BASE TABLE' > AND C.DATA_TYPE IN ('char', 'varchar', 'nchar', > 'nvarchar', 'text', 'ntext') > AND QUOTENAME(C.Table_Schema) + '.' + > QUOTENAME(C.Table_name) + '.' + QUOTENAME(COLUMN_NAME) > @TableName > > + '.' + @ColumnName > > ) > > SET @Parse = PATINDEX ('%|%', @ColumnName) > > SET @TableName = SUBSTRING(@ColumnName, 1, @Parse - 1) > SET @ColumnName = SUBSTRING(@ColumnName, @Parse +1, > LEN(@ColumnName)) > > IF @ColumnName IS NOT NULL > BEGIN > INSERT INTO #Results > EXEC > ( > 'SELECT ''' + @TableName + '.' + @ColumnName + ''', SUBSTRING(' > + @ColumnName + ',1, 3630) > FROM ' + @TableName + ' (NOLOCK) ' + > ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr > ) > END > END > > SELECT ColumnName, ColumnValue FROM #Results > ORDER BY ColumnName > > END > > --******************************** END of Sproc > > This is how you call the procedure: > > EXEC SearchAllTablesAllColumns 'YourSearchTextHere' > > > > > On Tue, May 25, 2010 at 9:43 AM, Jean-Paul natola wrote: > > > > yes, and i cought the typo > > 'SearcAllTablesAllColumns'. > > > > > > > > I'm not entirely sure how it works in sql but , maybe im saving it incorrectly? or in the wrong location? > > > > > > > > > > > > > > > > > >> Date: Tue, 25 May 2010 09:36:14 -0700 > >> From: dbdoug at gmail.com > >> To: dba-sqlserver at databaseadvisors.com > >> Subject: Re: [dba-SQLServer] search entire db > >> > >> I'm not trying to be rude here, but is the name of the sproc that you saved > >> exactly the same as the name you are trying to execute? > >> > >> Doug Steele > >> > >> On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola wrote: > >> > >> > > >> > I know this is trivial to the rest of you, but HOW do i add/register/create > >> > it > >> > > >> > I tried to create new sproc , copied the code into it , saved it and when I > >> > try to execut it it returns > >> > > >> > > >> > > >> > Msg 2812, Level 16, State 62, Line 1 > >> > > >> > Could not find stored procedure 'SearcAllTablesAllColumns'. > >> > > >> > > >> > > >> _______________________________________________ > >> dba-SQLServer mailing list > >> dba-SQLServer at databaseadvisors.com > >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > >> http://www.databaseadvisors.com > >> > > > > _________________________________________________________________ > > The New Busy is not the old busy. Search, chat and e-mail from your inbox. > > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 > > _______________________________________________ > > dba-SQLServer mailing list > > dba-SQLServer at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2 From fhtapia at gmail.com Tue May 25 12:59:22 2010 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 25 May 2010 10:59:22 -0700 Subject: [dba-SQLServer] search entire db In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com> <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: back... Jean-Paul I noticed you're having some difficulty, yes the top of the script uses this "USE" database name syntax replace the bracket text with the name of your database, this creates the sproc for your use in the said database -Francisco http://sqlthis.blogspot.com | Tsql and More... On Tue, May 25, 2010 at 10:15 AM, Jean-Paul natola wrote: > > on eother thing I noticed while looking at the existing sprocs in the > account DB is that they start with > > > > USE [dbname] > > > > is that required as well? > > > > > > > > Date: Tue, 25 May 2010 10:10:27 -0700 > > From: davidmcafee at gmail.com > > To: dba-sqlserver at databaseadvisors.com > > Subject: Re: [dba-SQLServer] search entire db > > > > I used the code from the listing and had no typos > > If you have already created the sproc, change the word CREATE to ALTER > > > > --****************************** start of sproc > > > > --This stored procedure creates a temporary table for storing search > > result data and steps through each column found. > > > > CREATE PROC [dbo].[SearchAllTablesAllColumns] > > ( > > @SearchStr nvarchar(100) > > ) > > AS > > BEGIN > > -- Purpose: To search all columns in all tables for a given search string > > -- Written by: Francisco Tapia > > -- Site: http://sqlthis.blogspot.com > > -- Inspired by: Narayana Vyas Kondreddi > > -- http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm > > -- Tested on: SQL Server 7.0, 2000 and 2005 > > -- Date modified: June 23, 2009 > > > > CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue > nvarchar(3630)) > > > > SET NOCOUNT ON > > > > DECLARE @TableName nvarchar(256), @ColumnName nvarchar(255), @Parse AS > INT > > > > SELECT @TableName = '', @ColumnName = '' > > SET @SearchStr = QUOTENAME('%' + @SearchStr + '%','''') > > > > WHILE (@ColumnName IS NOT NULL) > > BEGIN > > SET @ColumnName = ( > > SELECT MIN(QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) > > + '|' + QUOTENAME(C.Column_name)) > > FROM INFORMATION_SCHEMA.COLUMNS c > > INNER JOIN INFORMATION_SCHEMA.TABLES t on > > c.table_schema = t.table_schema and c.Table_name = t.table_name > > WHERE T.TABLE_TYPE = 'BASE TABLE' > > AND C.DATA_TYPE IN ('char', 'varchar', 'nchar', > > 'nvarchar', 'text', 'ntext') > > AND QUOTENAME(C.Table_Schema) + '.' + > > QUOTENAME(C.Table_name) + '.' + QUOTENAME(COLUMN_NAME) > @TableName > > > > + '.' + @ColumnName > > > > ) > > > > SET @Parse = PATINDEX ('%|%', @ColumnName) > > > > SET @TableName = SUBSTRING(@ColumnName, 1, @Parse - 1) > > SET @ColumnName = SUBSTRING(@ColumnName, @Parse +1, > > LEN(@ColumnName)) > > > > IF @ColumnName IS NOT NULL > > BEGIN > > INSERT INTO #Results > > EXEC > > ( > > 'SELECT ''' + @TableName + '.' + @ColumnName + ''', SUBSTRING(' > > + @ColumnName + ',1, 3630) > > FROM ' + @TableName + ' (NOLOCK) ' + > > ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr > > ) > > END > > END > > > > SELECT ColumnName, ColumnValue FROM #Results > > ORDER BY ColumnName > > > > END > > > > --******************************** END of Sproc > > > > This is how you call the procedure: > > > > EXEC SearchAllTablesAllColumns 'YourSearchTextHere' > > > > > > > > > > On Tue, May 25, 2010 at 9:43 AM, Jean-Paul natola > wrote: > > > > > > yes, and i cought the typo > > > 'SearcAllTablesAllColumns'. > > > > > > > > > > > > I'm not entirely sure how it works in sql but , maybe im saving it > incorrectly? or in the wrong location? > > > > > > > > > > > > > > > > > > > > > > > > > > >> Date: Tue, 25 May 2010 09:36:14 -0700 > > >> From: dbdoug at gmail.com > > >> To: dba-sqlserver at databaseadvisors.com > > >> Subject: Re: [dba-SQLServer] search entire db > > >> > > >> I'm not trying to be rude here, but is the name of the sproc that you > saved > > >> exactly the same as the name you are trying to execute? > > >> > > >> Doug Steele > > >> > > >> On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola < > jnatola at hotmail.com>wrote: > > >> > > >> > > > >> > I know this is trivial to the rest of you, but HOW do i > add/register/create > > >> > it > > >> > > > >> > I tried to create new sproc , copied the code into it , saved it and > when I > > >> > try to execut it it returns > > >> > > > >> > > > >> > > > >> > Msg 2812, Level 16, State 62, Line 1 > > >> > > > >> > Could not find stored procedure 'SearcAllTablesAllColumns'. > > >> > > > >> > > > >> > > > >> _______________________________________________ > > >> dba-SQLServer mailing list > > >> dba-SQLServer at databaseadvisors.com > > >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > >> http://www.databaseadvisors.com > > >> > > > > > > _________________________________________________________________ > > > The New Busy is not the old busy. Search, chat and e-mail from your > inbox. > > > > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 > > > _______________________________________________ > > > dba-SQLServer mailing list > > > dba-SQLServer at databaseadvisors.com > > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > > http://www.databaseadvisors.com > > > > > > > > _______________________________________________ > > dba-SQLServer mailing list > > dba-SQLServer at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > http://www.databaseadvisors.com > > > > _________________________________________________________________ > Hotmail is redefining busy with tools for the New Busy. Get more from your > inbox. > > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Tue May 25 13:21:44 2010 From: jnatola at hotmail.com (Jean-Paul natola) Date: Tue, 25 May 2010 14:21:44 -0400 Subject: [dba-SQLServer] search entire db-SOLVED In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com>, <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local>, , , , , , Message-ID: Evidently , due to browser/file format or whatever , mine wasnt as clean as your, I had all this on top of the filed {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww19960\viewh12760\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural GO\f0\fs24 \cf0 CREATE PROC [dbo].[SearchAllTablesAllColumns]\ > Date: Tue, 25 May 2010 10:10:27 -0700 > From: davidmcafee at gmail.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] search entire db > > I used the code from the listing and had no typos > If you have already created the sproc, change the word CREATE to ALTER > > --****************************** start of sproc > > --This stored procedure creates a temporary table for storing search > result data and steps through each column found. > > CREATE PROC [dbo].[SearchAllTablesAllColumns] > ( > @SearchStr nvarchar(100) > ) > AS > BEGIN > -- Purpose: To search all columns in all tables for a given search string > -- Written by: Francisco Tapia > -- Site: http://sqlthis.blogspot.com > -- Inspired by: Narayana Vyas Kondreddi > -- http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm > -- Tested on: SQL Server 7.0, 2000 and 2005 > -- Date modified: June 23, 2009 > > CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630)) > > SET NOCOUNT ON > > DECLARE @TableName nvarchar(256), @ColumnName nvarchar(255), @Parse AS INT > > SELECT @TableName = '', @ColumnName = '' > SET @SearchStr = QUOTENAME('%' + @SearchStr + '%','''') > > WHILE (@ColumnName IS NOT NULL) > BEGIN > SET @ColumnName = ( > SELECT MIN(QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) > + '|' + QUOTENAME(C.Column_name)) > FROM INFORMATION_SCHEMA.COLUMNS c > INNER JOIN INFORMATION_SCHEMA.TABLES t on > c.table_schema = t.table_schema and c.Table_name = t.table_name > WHERE T.TABLE_TYPE = 'BASE TABLE' > AND C.DATA_TYPE IN ('char', 'varchar', 'nchar', > 'nvarchar', 'text', 'ntext') > AND QUOTENAME(C.Table_Schema) + '.' + > QUOTENAME(C.Table_name) + '.' + QUOTENAME(COLUMN_NAME) > @TableName > > + '.' + @ColumnName > > ) > > SET @Parse = PATINDEX ('%|%', @ColumnName) > > SET @TableName = SUBSTRING(@ColumnName, 1, @Parse - 1) > SET @ColumnName = SUBSTRING(@ColumnName, @Parse +1, > LEN(@ColumnName)) > > IF @ColumnName IS NOT NULL > BEGIN > INSERT INTO #Results > EXEC > ( > 'SELECT ''' + @TableName + '.' + @ColumnName + ''', SUBSTRING(' > + @ColumnName + ',1, 3630) > FROM ' + @TableName + ' (NOLOCK) ' + > ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr > ) > END > END > > SELECT ColumnName, ColumnValue FROM #Results > ORDER BY ColumnName > > END > > --******************************** END of Sproc > > This is how you call the procedure: > > EXEC SearchAllTablesAllColumns 'YourSearchTextHere' > > > > > On Tue, May 25, 2010 at 9:43 AM, Jean-Paul natola wrote: > > > > yes, and i cought the typo > > 'SearcAllTablesAllColumns'. > > > > > > > > I'm not entirely sure how it works in sql but , maybe im saving it incorrectly? or in the wrong location? > > > > > > > > > > > > > > > > > >> Date: Tue, 25 May 2010 09:36:14 -0700 > >> From: dbdoug at gmail.com > >> To: dba-sqlserver at databaseadvisors.com > >> Subject: Re: [dba-SQLServer] search entire db > >> > >> I'm not trying to be rude here, but is the name of the sproc that you saved > >> exactly the same as the name you are trying to execute? > >> > >> Doug Steele > >> > >> On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola wrote: > >> > >> > > >> > I know this is trivial to the rest of you, but HOW do i add/register/create > >> > it > >> > > >> > I tried to create new sproc , copied the code into it , saved it and when I > >> > try to execut it it returns > >> > > >> > > >> > > >> > Msg 2812, Level 16, State 62, Line 1 > >> > > >> > Could not find stored procedure 'SearcAllTablesAllColumns'. > >> > > >> > > >> > > >> _______________________________________________ > >> dba-SQLServer mailing list > >> dba-SQLServer at databaseadvisors.com > >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > >> http://www.databaseadvisors.com > >> > > > > _________________________________________________________________ > > The New Busy is not the old busy. Search, chat and e-mail from your inbox. > > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 > > _______________________________________________ > > dba-SQLServer mailing list > > dba-SQLServer at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 From davidmcafee at gmail.com Tue May 25 13:58:16 2010 From: davidmcafee at gmail.com (David McAfee) Date: Tue, 25 May 2010 11:58:16 -0700 Subject: [dba-SQLServer] search entire db-SOLVED In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com> <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: Yes, the copy I downloaded was like that too. Francisco or Susan might want to look into that. The other two scripts in the zip file (2000_findColumns.sql & 2005_findColumns) were both OK. David On Tue, May 25, 2010 at 11:21 AM, Jean-Paul natola wrote: > > > Evidently , due to browser/file format or whatever , mine wasnt as clean as your, I had all this on top of the filed > > {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460 > > {\fonttbl\f0\fswiss\fcharset0 Helvetica;} > > {\colortbl;\red255\green255\blue255;} > > \margl1440\margr1440\vieww19960\viewh12760\viewkind0 > > \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural > > > > GO\f0\fs24 \cf0 CREATE PROC [dbo].[SearchAllTablesAllColumns]\ > > > > > > > > > > >> Date: Tue, 25 May 2010 10:10:27 -0700 >> From: davidmcafee at gmail.com >> To: dba-sqlserver at databaseadvisors.com >> Subject: Re: [dba-SQLServer] search entire db >> >> I used the code from the listing and had no typos >> If you have already created the sproc, change the word CREATE to ALTER >> >> --****************************** start of sproc >> >> --This stored procedure creates a temporary table for storing search >> result data and steps through each column found. >> >> CREATE PROC [dbo].[SearchAllTablesAllColumns] >> ( >> @SearchStr nvarchar(100) >> ) >> AS >> BEGIN >> -- Purpose: To search all columns in all tables for a given search string >> -- Written by: Francisco Tapia >> -- Site: http://sqlthis.blogspot.com >> -- Inspired by: Narayana Vyas Kondreddi >> -- http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm >> -- Tested on: SQL Server 7.0, 2000 and 2005 >> -- Date modified: June 23, 2009 >> >> CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630)) >> >> SET NOCOUNT ON >> >> DECLARE @TableName nvarchar(256), @ColumnName nvarchar(255), @Parse AS INT >> >> SELECT @TableName = '', @ColumnName = '' >> SET @SearchStr = QUOTENAME('%' + @SearchStr + '%','''') >> >> WHILE (@ColumnName IS NOT NULL) >> BEGIN >> SET @ColumnName = ( >> SELECT MIN(QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) >> + '|' + QUOTENAME(C.Column_name)) >> FROM INFORMATION_SCHEMA.COLUMNS c >> INNER JOIN INFORMATION_SCHEMA.TABLES t on >> c.table_schema = t.table_schema and c.Table_name = t.table_name >> WHERE T.TABLE_TYPE = 'BASE TABLE' >> AND C.DATA_TYPE IN ('char', 'varchar', 'nchar', >> 'nvarchar', 'text', 'ntext') >> AND QUOTENAME(C.Table_Schema) + '.' + >> QUOTENAME(C.Table_name) + '.' + QUOTENAME(COLUMN_NAME) > @TableName >> >> + '.' + @ColumnName >> >> ) >> >> SET @Parse = PATINDEX ('%|%', @ColumnName) >> >> SET @TableName = SUBSTRING(@ColumnName, 1, @Parse - 1) >> SET @ColumnName = SUBSTRING(@ColumnName, @Parse +1, >> LEN(@ColumnName)) >> >> IF @ColumnName IS NOT NULL >> BEGIN >> INSERT INTO #Results >> EXEC >> ( >> 'SELECT ''' + @TableName + '.' + @ColumnName + ''', SUBSTRING(' >> + @ColumnName + ',1, 3630) >> FROM ' + @TableName + ' (NOLOCK) ' + >> ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr >> ) >> END >> END >> >> SELECT ColumnName, ColumnValue FROM #Results >> ORDER BY ColumnName >> >> END >> >> --******************************** END of Sproc >> >> This is how you call the procedure: >> >> EXEC SearchAllTablesAllColumns 'YourSearchTextHere' >> >> >> >> >> On Tue, May 25, 2010 at 9:43 AM, Jean-Paul natola wrote: >> > >> > yes, and i cought the typo >> > 'SearcAllTablesAllColumns'. >> > >> > >> > >> > I'm not entirely sure how it works in sql but , maybe im saving it incorrectly? or in the wrong location? >> > >> > >> > >> > >> > >> > >> > >> > >> >> Date: Tue, 25 May 2010 09:36:14 -0700 >> >> From: dbdoug at gmail.com >> >> To: dba-sqlserver at databaseadvisors.com >> >> Subject: Re: [dba-SQLServer] search entire db >> >> >> >> I'm not trying to be rude here, but is the name of the sproc that you saved >> >> exactly the same as the name you are trying to execute? >> >> >> >> Doug Steele >> >> >> >> On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola wrote: >> >> >> >> > >> >> > I know this is trivial to the rest of you, but HOW do i add/register/create >> >> > it >> >> > >> >> > I tried to create new sproc , copied the code into it , saved it and when I >> >> > try to execut it it returns >> >> > >> >> > >> >> > >> >> > Msg 2812, Level 16, State 62, Line 1 >> >> > >> >> > Could not find stored procedure 'SearcAllTablesAllColumns'. >> >> > >> >> > >> >> > >> >> _______________________________________________ >> >> dba-SQLServer mailing list >> >> dba-SQLServer at databaseadvisors.com >> >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >> >> http://www.databaseadvisors.com >> >> >> > >> > _________________________________________________________________ >> > The New Busy is not the old busy. Search, chat and e-mail from your inbox. >> > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 >> > _______________________________________________ >> > dba-SQLServer mailing list >> > dba-SQLServer at databaseadvisors.com >> > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >> > http://www.databaseadvisors.com >> > >> > >> _______________________________________________ >> dba-SQLServer mailing list >> dba-SQLServer at databaseadvisors.com >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >> http://www.databaseadvisors.com >> > > _________________________________________________________________ > Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fhtapia at gmail.com Tue May 25 14:09:53 2010 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 25 May 2010 12:09:53 -0700 Subject: [dba-SQLServer] search entire db-SOLVED In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com> <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local> Message-ID: Yeah I'll get a hold of someone to correct it On 5/25/10, David McAfee wrote: > Yes, the copy I downloaded was like that too. > > Francisco or Susan might want to look into that. > > The other two scripts in the zip file (2000_findColumns.sql & > 2005_findColumns) were both OK. > > David > > On Tue, May 25, 2010 at 11:21 AM, Jean-Paul natola > wrote: >> >> >> Evidently , due to browser/file format or whatever , mine wasnt as clean >> as your, I had all this on top of the filed >> >> {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460 >> >> {\fonttbl\f0\fswiss\fcharset0 Helvetica;} >> >> {\colortbl;\red255\green255\blue255;} >> >> \margl1440\margr1440\vieww19960\viewh12760\viewkind0 >> >> \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural >> >> >> >> GO\f0\fs24 \cf0 CREATE PROC [dbo].[SearchAllTablesAllColumns]\ >> >> >> >> >> >> >> >> >> >> >>> Date: Tue, 25 May 2010 10:10:27 -0700 >>> From: davidmcafee at gmail.com >>> To: dba-sqlserver at databaseadvisors.com >>> Subject: Re: [dba-SQLServer] search entire db >>> >>> I used the code from the listing and had no typos >>> If you have already created the sproc, change the word CREATE to ALTER >>> >>> --****************************** start of sproc >>> >>> --This stored procedure creates a temporary table for storing search >>> result data and steps through each column found. >>> >>> CREATE PROC [dbo].[SearchAllTablesAllColumns] >>> ( >>> @SearchStr nvarchar(100) >>> ) >>> AS >>> BEGIN >>> -- Purpose: To search all columns in all tables for a given search string >>> -- Written by: Francisco Tapia >>> -- Site: http://sqlthis.blogspot.com >>> -- Inspired by: Narayana Vyas Kondreddi >>> -- http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm >>> -- Tested on: SQL Server 7.0, 2000 and 2005 >>> -- Date modified: June 23, 2009 >>> >>> CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue >>> nvarchar(3630)) >>> >>> SET NOCOUNT ON >>> >>> DECLARE @TableName nvarchar(256), @ColumnName nvarchar(255), @Parse AS >>> INT >>> >>> SELECT @TableName = '', @ColumnName = '' >>> SET @SearchStr = QUOTENAME('%' + @SearchStr + '%','''') >>> >>> WHILE (@ColumnName IS NOT NULL) >>> BEGIN >>> SET @ColumnName = ( >>> SELECT MIN(QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) >>> + '|' + QUOTENAME(C.Column_name)) >>> FROM INFORMATION_SCHEMA.COLUMNS c >>> INNER JOIN INFORMATION_SCHEMA.TABLES t on >>> c.table_schema = t.table_schema and c.Table_name = t.table_name >>> WHERE T.TABLE_TYPE = 'BASE TABLE' >>> AND C.DATA_TYPE IN ('char', 'varchar', 'nchar', >>> 'nvarchar', 'text', 'ntext') >>> AND QUOTENAME(C.Table_Schema) + '.' + >>> QUOTENAME(C.Table_name) + '.' + QUOTENAME(COLUMN_NAME) > @TableName >>> >>> + '.' + @ColumnName >>> >>> ) >>> >>> SET @Parse = PATINDEX ('%|%', @ColumnName) >>> >>> SET @TableName = SUBSTRING(@ColumnName, 1, @Parse - 1) >>> SET @ColumnName = SUBSTRING(@ColumnName, @Parse +1, >>> LEN(@ColumnName)) >>> >>> IF @ColumnName IS NOT NULL >>> BEGIN >>> INSERT INTO #Results >>> EXEC >>> ( >>> 'SELECT ''' + @TableName + '.' + @ColumnName + ''', SUBSTRING(' >>> + @ColumnName + ',1, 3630) >>> FROM ' + @TableName + ' (NOLOCK) ' + >>> ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr >>> ) >>> END >>> END >>> >>> SELECT ColumnName, ColumnValue FROM #Results >>> ORDER BY ColumnName >>> >>> END >>> >>> --******************************** END of Sproc >>> >>> This is how you call the procedure: >>> >>> EXEC SearchAllTablesAllColumns 'YourSearchTextHere' >>> >>> >>> >>> >>> On Tue, May 25, 2010 at 9:43 AM, Jean-Paul natola >>> wrote: >>> > >>> > yes, and i cought the typo >>> > 'SearcAllTablesAllColumns'. >>> > >>> > >>> > >>> > I'm not entirely sure how it works in sql but , maybe im saving it >>> > incorrectly? or in the wrong location? >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> >> Date: Tue, 25 May 2010 09:36:14 -0700 >>> >> From: dbdoug at gmail.com >>> >> To: dba-sqlserver at databaseadvisors.com >>> >> Subject: Re: [dba-SQLServer] search entire db >>> >> >>> >> I'm not trying to be rude here, but is the name of the sproc that you >>> >> saved >>> >> exactly the same as the name you are trying to execute? >>> >> >>> >> Doug Steele >>> >> >>> >> On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola >>> >> wrote: >>> >> >>> >> > >>> >> > I know this is trivial to the rest of you, but HOW do i >>> >> > add/register/create >>> >> > it >>> >> > >>> >> > I tried to create new sproc , copied the code into it , saved it and >>> >> > when I >>> >> > try to execut it it returns >>> >> > >>> >> > >>> >> > >>> >> > Msg 2812, Level 16, State 62, Line 1 >>> >> > >>> >> > Could not find stored procedure 'SearcAllTablesAllColumns'. >>> >> > >>> >> > >>> >> > >>> >> _______________________________________________ >>> >> dba-SQLServer mailing list >>> >> dba-SQLServer at databaseadvisors.com >>> >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >>> >> http://www.databaseadvisors.com >>> >> >>> > >>> > _________________________________________________________________ >>> > The New Busy is not the old busy. Search, chat and e-mail from your >>> > inbox. >>> > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 >>> > _______________________________________________ >>> > dba-SQLServer mailing list >>> > dba-SQLServer at databaseadvisors.com >>> > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >>> > http://www.databaseadvisors.com >>> > >>> > >>> _______________________________________________ >>> dba-SQLServer mailing list >>> dba-SQLServer at databaseadvisors.com >>> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >>> http://www.databaseadvisors.com >>> >> >> _________________________________________________________________ >> Hotmail has tools for the New Busy. Search, chat and e-mail from your >> inbox. >> http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 >> _______________________________________________ >> dba-SQLServer mailing list >> dba-SQLServer at databaseadvisors.com >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >> http://www.databaseadvisors.com >> >> > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- Sent from my mobile device -Francisco http://sqlthis.blogspot.com | Tsql and More... From jnatola at hotmail.com Tue May 25 14:11:34 2010 From: jnatola at hotmail.com (Jean-Paul natola) Date: Tue, 25 May 2010 15:11:34 -0400 Subject: [dba-SQLServer] search entire db-SOLVED In-Reply-To: References: <4BF6C20E.4020300@colbyconsulting.com>, <59A61174B1F5B54B97FD4ADDE71E7D016B5A3D@ddi-01.DDI.local>, , , , , , , , Message-ID: By the way, thanks for posting a clean version, I would have spent hours (well more hours than i did) trying to figure out what i was doing wrong. and of course thanks to Francisco for actually writing it > Date: Tue, 25 May 2010 11:58:16 -0700 > From: davidmcafee at gmail.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] search entire db-SOLVED > > Yes, the copy I downloaded was like that too. > > Francisco or Susan might want to look into that. > > The other two scripts in the zip file (2000_findColumns.sql & > 2005_findColumns) were both OK. > > David > > On Tue, May 25, 2010 at 11:21 AM, Jean-Paul natola wrote: > > > > > > Evidently , due to browser/file format or whatever , mine wasnt as clean as your, I had all this on top of the filed > > > > {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460 > > > > {\fonttbl\f0\fswiss\fcharset0 Helvetica;} > > > > {\colortbl;\red255\green255\blue255;} > > > > \margl1440\margr1440\vieww19960\viewh12760\viewkind0 > > > > \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural > > > > > > > > GO\f0\fs24 \cf0 CREATE PROC [dbo].[SearchAllTablesAllColumns]\ > > > > > > > > > > > > > > > > > > > > > >> Date: Tue, 25 May 2010 10:10:27 -0700 > >> From: davidmcafee at gmail.com > >> To: dba-sqlserver at databaseadvisors.com > >> Subject: Re: [dba-SQLServer] search entire db > >> > >> I used the code from the listing and had no typos > >> If you have already created the sproc, change the word CREATE to ALTER > >> > >> --****************************** start of sproc > >> > >> --This stored procedure creates a temporary table for storing search > >> result data and steps through each column found. > >> > >> CREATE PROC [dbo].[SearchAllTablesAllColumns] > >> ( > >> @SearchStr nvarchar(100) > >> ) > >> AS > >> BEGIN > >> -- Purpose: To search all columns in all tables for a given search string > >> -- Written by: Francisco Tapia > >> -- Site: http://sqlthis.blogspot.com > >> -- Inspired by: Narayana Vyas Kondreddi > >> -- http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm > >> -- Tested on: SQL Server 7.0, 2000 and 2005 > >> -- Date modified: June 23, 2009 > >> > >> CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630)) > >> > >> SET NOCOUNT ON > >> > >> DECLARE @TableName nvarchar(256), @ColumnName nvarchar(255), @Parse AS INT > >> > >> SELECT @TableName = '', @ColumnName = '' > >> SET @SearchStr = QUOTENAME('%' + @SearchStr + '%','''') > >> > >> WHILE (@ColumnName IS NOT NULL) > >> BEGIN > >> SET @ColumnName = ( > >> SELECT MIN(QUOTENAME(C.Table_Schema) + '.' + QUOTENAME(C.Table_name) > >> + '|' + QUOTENAME(C.Column_name)) > >> FROM INFORMATION_SCHEMA.COLUMNS c > >> INNER JOIN INFORMATION_SCHEMA.TABLES t on > >> c.table_schema = t.table_schema and c.Table_name = t.table_name > >> WHERE T.TABLE_TYPE = 'BASE TABLE' > >> AND C.DATA_TYPE IN ('char', 'varchar', 'nchar', > >> 'nvarchar', 'text', 'ntext') > >> AND QUOTENAME(C.Table_Schema) + '.' + > >> QUOTENAME(C.Table_name) + '.' + QUOTENAME(COLUMN_NAME) > @TableName > >> > >> + '.' + @ColumnName > >> > >> ) > >> > >> SET @Parse = PATINDEX ('%|%', @ColumnName) > >> > >> SET @TableName = SUBSTRING(@ColumnName, 1, @Parse - 1) > >> SET @ColumnName = SUBSTRING(@ColumnName, @Parse +1, > >> LEN(@ColumnName)) > >> > >> IF @ColumnName IS NOT NULL > >> BEGIN > >> INSERT INTO #Results > >> EXEC > >> ( > >> 'SELECT ''' + @TableName + '.' + @ColumnName + ''', SUBSTRING(' > >> + @ColumnName + ',1, 3630) > >> FROM ' + @TableName + ' (NOLOCK) ' + > >> ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr > >> ) > >> END > >> END > >> > >> SELECT ColumnName, ColumnValue FROM #Results > >> ORDER BY ColumnName > >> > >> END > >> > >> --******************************** END of Sproc > >> > >> This is how you call the procedure: > >> > >> EXEC SearchAllTablesAllColumns 'YourSearchTextHere' > >> > >> > >> > >> > >> On Tue, May 25, 2010 at 9:43 AM, Jean-Paul natola wrote: > >> > > >> > yes, and i cought the typo > >> > 'SearcAllTablesAllColumns'. > >> > > >> > > >> > > >> > I'm not entirely sure how it works in sql but , maybe im saving it incorrectly? or in the wrong location? > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> >> Date: Tue, 25 May 2010 09:36:14 -0700 > >> >> From: dbdoug at gmail.com > >> >> To: dba-sqlserver at databaseadvisors.com > >> >> Subject: Re: [dba-SQLServer] search entire db > >> >> > >> >> I'm not trying to be rude here, but is the name of the sproc that you saved > >> >> exactly the same as the name you are trying to execute? > >> >> > >> >> Doug Steele > >> >> > >> >> On Tue, May 25, 2010 at 9:23 AM, Jean-Paul natola wrote: > >> >> > >> >> > > >> >> > I know this is trivial to the rest of you, but HOW do i add/register/create > >> >> > it > >> >> > > >> >> > I tried to create new sproc , copied the code into it , saved it and when I > >> >> > try to execut it it returns > >> >> > > >> >> > > >> >> > > >> >> > Msg 2812, Level 16, State 62, Line 1 > >> >> > > >> >> > Could not find stored procedure 'SearcAllTablesAllColumns'. > >> >> > > >> >> > > >> >> > > >> >> _______________________________________________ > >> >> dba-SQLServer mailing list > >> >> dba-SQLServer at databaseadvisors.com > >> >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > >> >> http://www.databaseadvisors.com > >> >> > >> > > >> > _________________________________________________________________ > >> > The New Busy is not the old busy. Search, chat and e-mail from your inbox. > >> > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 > >> > _______________________________________________ > >> > dba-SQLServer mailing list > >> > dba-SQLServer at databaseadvisors.com > >> > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > >> > http://www.databaseadvisors.com > >> > > >> > > >> _______________________________________________ > >> dba-SQLServer mailing list > >> dba-SQLServer at databaseadvisors.com > >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > >> http://www.databaseadvisors.com > >> > > > > _________________________________________________________________ > > Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. > > http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1 > > _______________________________________________ > > dba-SQLServer mailing list > > dba-SQLServer at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ The New Busy is not the old busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3