From scapistrant at symphonyinfo.com Mon Mar 3 09:21:34 2008 From: scapistrant at symphonyinfo.com (steve) Date: Mon, 3 Mar 2008 09:21:34 -0600 Subject: [dba-SQLServer] Newbie resources In-Reply-To: <00e101c835e9$d49ab560$647aa8c0@M90> References: <004701c833d7$99526c00$647aa8c0@M90><010d01c835e5$6424b7d0$800101df@fci.local> <00e101c835e9$d49ab560$647aa8c0@M90> Message-ID: <580B8DAE8E3A4246874F1902228F0CEB@symphony.symphonyinfo.com> Ok, after 12 years of focusing on Access and using SQL Server only occasionally (treating it just as another table via and ODBC connection) I'm ready to plunge in. Can anyone provide advice on the best current resources for getting a good start? I'm sure this question is asked frequently, but by its very nature, the answer probably changes every 6 months. Steve Capistrant Symphony Information Services www.symphonyinfo.com Email: scapistrant at symphonyinfo.com Skype: steve.capistrant From ssharkins at gmail.com Mon Mar 3 09:27:40 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Mon, 3 Mar 2008 10:27:40 -0500 Subject: [dba-SQLServer] Newbie resources References: <004701c833d7$99526c00$647aa8c0@M90><010d01c835e5$6424b7d0$800101df@fci.local><00e101c835e9$d49ab560$647aa8c0@M90> <580B8DAE8E3A4246874F1902228F0CEB@symphony.symphonyinfo.com> Message-ID: <01eb01c87d43$21537ea0$4b3a8343@SusanOne> My favorite: http://www.sqlservercentral.com/ Susan H. > > I'm sure this question is asked frequently, but by its very nature, the > answer probably changes every 6 months. From pauln at sqlserverbible.com Mon Mar 3 10:20:57 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Mon, 3 Mar 2008 09:20:57 -0700 Subject: [dba-SQLServer] Newbie resources In-Reply-To: <580B8DAE8E3A4246874F1902228F0CEB@symphony.symphonyinfo.com> References: <004701c833d7$99526c00$647aa8c0@M90><010d01c835e5$6424b7d0$800101df@fci.local> <00e101c835e9$d49ab560$647aa8c0@M90> <580B8DAE8E3A4246874F1902228F0CEB@symphony.symphonyinfo.com> Message-ID: <003001c87d4a$90ab3390$b2019ab0$@com> I'm admittedly biased, but SQL Server 2005 Bible, and Total training SQL Server Dev would be a good start. I used to be in Access so the differences between Access and SQL Server are all covered. You'll find that the big difference is that SQL server developer don't use the UI, you'll type all your queries and stored procs. www.sqlserverbible.com -Paul ;-) -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of steve Sent: Monday, March 03, 2008 8:22 AM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Newbie resources Ok, after 12 years of focusing on Access and using SQL Server only occasionally (treating it just as another table via and ODBC connection) I'm ready to plunge in. Can anyone provide advice on the best current resources for getting a good start? I'm sure this question is asked frequently, but by its very nature, the answer probably changes every 6 months. Steve Capistrant Symphony Information Services www.symphonyinfo.com Email: scapistrant at symphonyinfo.com Skype: steve.capistrant _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2917 (20080303) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fhtapia at gmail.com Mon Mar 3 12:54:01 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Mon, 3 Mar 2008 10:54:01 -0800 Subject: [dba-SQLServer] Newbie resources In-Reply-To: <01eb01c87d43$21537ea0$4b3a8343@SusanOne> References: <004701c833d7$99526c00$647aa8c0@M90> <010d01c835e5$6424b7d0$800101df@fci.local> <00e101c835e9$d49ab560$647aa8c0@M90> <580B8DAE8E3A4246874F1902228F0CEB@symphony.symphonyinfo.com> <01eb01c87d43$21537ea0$4b3a8343@SusanOne> Message-ID: 2nded, also www.databasejournal.com has some really interesting "best practice" type articles. On Mon, Mar 3, 2008 at 7:27 AM, Susan Harkins wrote: > My favorite: > > http://www.sqlservercentral.com/ > > Susan H. > > > > > I'm sure this question is asked frequently, but by its very nature, the > > answer probably changes every 6 months. > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Mon Mar 3 16:17:29 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 3 Mar 2008 17:17:29 -0500 Subject: [dba-SQLServer] Append only new records Message-ID: <007901c87d7c$5f255d00$0201a8c0@M90> I am building a table of known validated addresses in the US. For my purposes all I have is Address, city, state, zip and HashAddr. HashAddr is a has which is guaranteed to be unique given the input which is the address fields given. In Access you could append records in at random and those records which did not collide with a unique index goes in, and those that do collide do not go in. Obviously an index on the HashAddress will be the unique index. Is it possible to do the same kind of thing in SQL Server? When I have tried this before (in SQL Server), the whole process aborted if a collision occurred, with no records appended if there was any collision. John W. Colby Colby Consulting www.ColbyConsulting.com From ab-mi at post3.tele.dk Mon Mar 3 16:51:14 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Mon, 3 Mar 2008 23:51:14 +0100 Subject: [dba-SQLServer] Append only new records In-Reply-To: <20080303221935.TUOZ22541.fep23.mail.dk@databaseadvisors.com> Message-ID: <000001c87d81$15b66fb0$2101a8c0@AB> I think the option WITH IGNORE_DUP_KEY = ON for the unique index will do what you want. HTH Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 3. marts 2008 23:17 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Append only new records I am building a table of known validated addresses in the US. For my purposes all I have is Address, city, state, zip and HashAddr. HashAddr is a has which is guaranteed to be unique given the input which is the address fields given. In Access you could append records in at random and those records which did not collide with a unique index goes in, and those that do collide do not go in. Obviously an index on the HashAddress will be the unique index. Is it possible to do the same kind of thing in SQL Server? When I have tried this before (in SQL Server), the whole process aborted if a collision occurred, with no records appended if there was any collision. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From robert at webedb.com Tue Mar 4 12:24:27 2008 From: robert at webedb.com (Robert L. Stewart) Date: Tue, 04 Mar 2008 12:24:27 -0600 Subject: [dba-SQLServer] Append only new records In-Reply-To: References: Message-ID: <200803041825.m24IPAUO013827@databaseadvisors.com> John, With the correct logic, read stored procedure, you can do what you want to do. You could also use SSIS to build a project to do it. Do not turn off the IGNORE DUPLICATES. Use a stored procedure or SSIS package to do the work for you. Robert At 12:00 PM 3/4/2008, you wrote: >Date: Mon, 3 Mar 2008 17:17:29 -0500 >From: "jwcolby" >Subject: [dba-SQLServer] Append only new records >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <007901c87d7c$5f255d00$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >I am building a table of known validated addresses in the US. For my >purposes all I have is Address, city, state, zip and HashAddr. HashAddr is >a has which is guaranteed to be unique given the input which is the address >fields given. > >In Access you could append records in at random and those records which did >not collide with a unique index goes in, and those that do collide do not go >in. Obviously an index on the HashAddress will be the unique index. Is it >possible to do the same kind of thing in SQL Server? When I have tried this >before (in SQL Server), the whole process aborted if a collision occurred, >with no records appended if there was any collision. > >John W. Colby >Colby Consulting >www.ColbyConsulting.com From pauln at sqlserverbible.com Tue Mar 4 12:35:55 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 4 Mar 2008 11:35:55 -0700 Subject: [dba-SQLServer] Append only new records In-Reply-To: <007901c87d7c$5f255d00$0201a8c0@M90> References: <007901c87d7c$5f255d00$0201a8c0@M90> Message-ID: <00b901c87e26$95c48340$c14d89c0$@com> You could always pump them all into a temp table, delete dups, and then move them into the real table. It'd be dirt simple and repeatable. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 03, 2008 3:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Append only new records I am building a table of known validated addresses in the US. For my purposes all I have is Address, city, state, zip and HashAddr. HashAddr is a has which is guaranteed to be unique given the input which is the address fields given. In Access you could append records in at random and those records which did not collide with a unique index goes in, and those that do collide do not go in. Obviously an index on the HashAddress will be the unique index. Is it possible to do the same kind of thing in SQL Server? When I have tried this before (in SQL Server), the whole process aborted if a collision occurred, with no records appended if there was any collision. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2918 (20080303) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Tue Mar 4 14:12:09 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 4 Mar 2008 15:12:09 -0500 Subject: [dba-SQLServer] Append only new records In-Reply-To: <00b901c87e26$95c48340$c14d89c0$@com> References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com> Message-ID: <00db01c87e34$06ca2790$0201a8c0@M90> LOL. Nothing is dirt simple when you are dealing with a hundred million records. I have many different tables, each table has name / address information. I already create a hash of the address fields (HashAddr), the address plus last name (HashFamily) and Address / last name / first name (HashPerson). Any given table will contain millions of records where there are multiple people in a family at the same address. I am looking to carve out just the address (and it's hash) and dump it into an address table, however it needs to be there only once. That will form a "validated address table" where by definition if the address is in there it is valid and deliverable. The hash of the address fields then becomes the PK for that table since it is unique. Having done that I can then do joins on the address hash to see everyone who has ever lived at any address. I can also get relationships between the lists. Of course the address table will have more than a hundred million rows. The obvious is to do a "not in" query to select hashes not in the address table, then append those records into the address table. However with a hundred million records and growing, that kind of operation could take a few seconds. 8~) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 1:36 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records You could always pump them all into a temp table, delete dups, and then move them into the real table. It'd be dirt simple and repeatable. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 03, 2008 3:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Append only new records I am building a table of known validated addresses in the US. For my purposes all I have is Address, city, state, zip and HashAddr. HashAddr is a has which is guaranteed to be unique given the input which is the address fields given. In Access you could append records in at random and those records which did not collide with a unique index goes in, and those that do collide do not go in. Obviously an index on the HashAddress will be the unique index. Is it possible to do the same kind of thing in SQL Server? When I have tried this before (in SQL Server), the whole process aborted if a collision occurred, with no records appended if there was any collision. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2918 (20080303) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pauln at sqlserverbible.com Tue Mar 4 15:05:34 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 4 Mar 2008 14:05:34 -0700 Subject: [dba-SQLServer] Append only new records In-Reply-To: <00db01c87e34$06ca2790$0201a8c0@M90> References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com> <00db01c87e34$06ca2790$0201a8c0@M90> Message-ID: <007401c87e3b$7fd784a0$7f868de0$@com> Yep, SQL Server typically has larger databases. The average sized db for SQL Server is probably 500Gb +. At the last PASS conference when asked how many of you have databases over 1 Tb most hands went up. I normally test any app with millions of rows. This is my last contract job, http://sqlblog.com/blogs/paul_nielsen/archive/2007/12/12/10-lessons-from-35k -tps.aspx in your case I see two points of pain, First, the " many different tables". How many tables have addresses? Is it dynamic or a fixed set of tables. Either way it's scriptable. Secondly, hashes for large sets tend to not be unique. I'd use an bigint identity. The process is not difficult. 1) Insert all the addresses from every table into a single table with an identity. 2) Delete dups. 3) If you dislike the gaps, alter the table to remove the identity and then add a new identity. 4) Add AddressID column to each of the many tables 5) update manytables set mt.addressid = a.addressid from manytables join address on a.address = manytables.address Is really is dirt simple of a onetime conversion process. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 04, 2008 1:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records LOL. Nothing is dirt simple when you are dealing with a hundred million records. I have many different tables, each table has name / address information. I already create a hash of the address fields (HashAddr), the address plus last name (HashFamily) and Address / last name / first name (HashPerson). Any given table will contain millions of records where there are multiple people in a family at the same address. I am looking to carve out just the address (and it's hash) and dump it into an address table, however it needs to be there only once. That will form a "validated address table" where by definition if the address is in there it is valid and deliverable. The hash of the address fields then becomes the PK for that table since it is unique. Having done that I can then do joins on the address hash to see everyone who has ever lived at any address. I can also get relationships between the lists. Of course the address table will have more than a hundred million rows. The obvious is to do a "not in" query to select hashes not in the address table, then append those records into the address table. However with a hundred million records and growing, that kind of operation could take a few seconds. 8~) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 1:36 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records You could always pump them all into a temp table, delete dups, and then move them into the real table. It'd be dirt simple and repeatable. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 03, 2008 3:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Append only new records I am building a table of known validated addresses in the US. For my purposes all I have is Address, city, state, zip and HashAddr. HashAddr is a has which is guaranteed to be unique given the input which is the address fields given. In Access you could append records in at random and those records which did not collide with a unique index goes in, and those that do collide do not go in. Obviously an index on the HashAddress will be the unique index. Is it possible to do the same kind of thing in SQL Server? When I have tried this before (in SQL Server), the whole process aborted if a collision occurred, with no records appended if there was any collision. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2918 (20080303) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2921 (20080304) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Tue Mar 4 16:07:13 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 4 Mar 2008 17:07:13 -0500 Subject: [dba-SQLServer] Append only new records In-Reply-To: <007401c87e3b$7fd784a0$7f868de0$@com> References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com><00db01c87e34$06ca2790$0201a8c0@M90> <007401c87e3b$7fd784a0$7f868de0$@com> Message-ID: <00dc01c87e44$1a209d00$0201a8c0@M90> Every table has addresses. These are marketing lists of name / address from various sources. MOST lists are "static" in that I do not get new versions of the lists, although I do get updates to one of my lists. OTOH, EVERY list has to be NCOA (National Change of Address) processed occasionally, with "occasionally" being defined as every few months. Thus I will get address changes from the NCOA process every few months for each list. My lists contain ~50 million records, ~ 75 million records and ~150 million records plus a bunch of smaller lists, 10 million etc. I can get a new list at any time and need to be able to cross reference them, i.e. which records in list A are also in list B. That is why the Hash idea was so appealing. A autonumber in any given list is only really useful within that list, it does not in any way "match" an autonumber in any other list. However I do in fact use an integer autonumber for a couple of purposes. One thing I do is take the NCOA processed data and store it in a new table, with the PKID then relating back to the original list. The NCOA data adds significant "value" to the address including such things as area code, county, congressional district, lat/long etc. Given that the NCOA has to be performed on a regular basis, and given that I am attempting to track PEOPLE (who move around) not addresses (which obviously do not move) it is useful to keep the NCOA data separate from the original list data which contains demographics information such as race, income, sex, purchasing preferences and so forth. The other usage of the PKID is simply that it allows me to export for the NCOA process and then match the returning records to the original records. But to correlate between lists I really need a hash type of functionality. It is useful to discover that a record in a list about purchasing preferences "matches" a record in another list about mortgages or yet another list about insurance policies. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 4:06 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records Yep, SQL Server typically has larger databases. The average sized db for SQL Server is probably 500Gb +. At the last PASS conference when asked how many of you have databases over 1 Tb most hands went up. I normally test any app with millions of rows. This is my last contract job, http://sqlblog.com/blogs/paul_nielsen/archive/2007/12/12/10-lessons-from-35k -tps.aspx in your case I see two points of pain, First, the " many different tables". How many tables have addresses? Is it dynamic or a fixed set of tables. Either way it's scriptable. Secondly, hashes for large sets tend to not be unique. I'd use an bigint identity. The process is not difficult. 1) Insert all the addresses from every table into a single table with an identity. 2) Delete dups. 3) If you dislike the gaps, alter the table to remove the identity and then add a new identity. 4) Add AddressID column to each of the many tables 5) update manytables set mt.addressid = a.addressid from manytables join address on a.address = manytables.address Is really is dirt simple of a onetime conversion process. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 04, 2008 1:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records LOL. Nothing is dirt simple when you are dealing with a hundred million records. I have many different tables, each table has name / address information. I already create a hash of the address fields (HashAddr), the address plus last name (HashFamily) and Address / last name / first name (HashPerson). Any given table will contain millions of records where there are multiple people in a family at the same address. I am looking to carve out just the address (and it's hash) and dump it into an address table, however it needs to be there only once. That will form a "validated address table" where by definition if the address is in there it is valid and deliverable. The hash of the address fields then becomes the PK for that table since it is unique. Having done that I can then do joins on the address hash to see everyone who has ever lived at any address. I can also get relationships between the lists. Of course the address table will have more than a hundred million rows. The obvious is to do a "not in" query to select hashes not in the address table, then append those records into the address table. However with a hundred million records and growing, that kind of operation could take a few seconds. 8~) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 1:36 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records You could always pump them all into a temp table, delete dups, and then move them into the real table. It'd be dirt simple and repeatable. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 03, 2008 3:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Append only new records I am building a table of known validated addresses in the US. For my purposes all I have is Address, city, state, zip and HashAddr. HashAddr is a has which is guaranteed to be unique given the input which is the address fields given. In Access you could append records in at random and those records which did not collide with a unique index goes in, and those that do collide do not go in. Obviously an index on the HashAddress will be the unique index. Is it possible to do the same kind of thing in SQL Server? When I have tried this before (in SQL Server), the whole process aborted if a collision occurred, with no records appended if there was any collision. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2918 (20080303) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2921 (20080304) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pauln at sqlserverbible.com Tue Mar 4 16:20:02 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 4 Mar 2008 15:20:02 -0700 Subject: [dba-SQLServer] Append only new records In-Reply-To: <00dc01c87e44$1a209d00$0201a8c0@M90> References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com><00db01c87e34$06ca2790$0201a8c0@M90> <007401c87e3b$7fd784a0$7f868de0$@com> <00dc01c87e44$1a209d00$0201a8c0@M90> Message-ID: <002a01c87e45$e7733730$b659a590$@com> Have you considered writing a proc with dynamic SQL so you can pass in the name of the source table (and maybe the column names) as a parameter and it works with any source table? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 04, 2008 3:07 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records Every table has addresses. These are marketing lists of name / address from various sources. MOST lists are "static" in that I do not get new versions of the lists, although I do get updates to one of my lists. OTOH, EVERY list has to be NCOA (National Change of Address) processed occasionally, with "occasionally" being defined as every few months. Thus I will get address changes from the NCOA process every few months for each list. My lists contain ~50 million records, ~ 75 million records and ~150 million records plus a bunch of smaller lists, 10 million etc. I can get a new list at any time and need to be able to cross reference them, i.e. which records in list A are also in list B. That is why the Hash idea was so appealing. A autonumber in any given list is only really useful within that list, it does not in any way "match" an autonumber in any other list. However I do in fact use an integer autonumber for a couple of purposes. One thing I do is take the NCOA processed data and store it in a new table, with the PKID then relating back to the original list. The NCOA data adds significant "value" to the address including such things as area code, county, congressional district, lat/long etc. Given that the NCOA has to be performed on a regular basis, and given that I am attempting to track PEOPLE (who move around) not addresses (which obviously do not move) it is useful to keep the NCOA data separate from the original list data which contains demographics information such as race, income, sex, purchasing preferences and so forth. The other usage of the PKID is simply that it allows me to export for the NCOA process and then match the returning records to the original records. But to correlate between lists I really need a hash type of functionality. It is useful to discover that a record in a list about purchasing preferences "matches" a record in another list about mortgages or yet another list about insurance policies. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 4:06 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records Yep, SQL Server typically has larger databases. The average sized db for SQL Server is probably 500Gb +. At the last PASS conference when asked how many of you have databases over 1 Tb most hands went up. I normally test any app with millions of rows. This is my last contract job, http://sqlblog.com/blogs/paul_nielsen/archive/2007/12/12/10-lessons-from-35k -tps.aspx in your case I see two points of pain, First, the " many different tables". How many tables have addresses? Is it dynamic or a fixed set of tables. Either way it's scriptable. Secondly, hashes for large sets tend to not be unique. I'd use an bigint identity. The process is not difficult. 1) Insert all the addresses from every table into a single table with an identity. 2) Delete dups. 3) If you dislike the gaps, alter the table to remove the identity and then add a new identity. 4) Add AddressID column to each of the many tables 5) update manytables set mt.addressid = a.addressid from manytables join address on a.address = manytables.address Is really is dirt simple of a onetime conversion process. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 04, 2008 1:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records LOL. Nothing is dirt simple when you are dealing with a hundred million records. I have many different tables, each table has name / address information. I already create a hash of the address fields (HashAddr), the address plus last name (HashFamily) and Address / last name / first name (HashPerson). Any given table will contain millions of records where there are multiple people in a family at the same address. I am looking to carve out just the address (and it's hash) and dump it into an address table, however it needs to be there only once. That will form a "validated address table" where by definition if the address is in there it is valid and deliverable. The hash of the address fields then becomes the PK for that table since it is unique. Having done that I can then do joins on the address hash to see everyone who has ever lived at any address. I can also get relationships between the lists. Of course the address table will have more than a hundred million rows. The obvious is to do a "not in" query to select hashes not in the address table, then append those records into the address table. However with a hundred million records and growing, that kind of operation could take a few seconds. 8~) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 1:36 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records You could always pump them all into a temp table, delete dups, and then move them into the real table. It'd be dirt simple and repeatable. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 03, 2008 3:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Append only new records I am building a table of known validated addresses in the US. For my purposes all I have is Address, city, state, zip and HashAddr. HashAddr is a has which is guaranteed to be unique given the input which is the address fields given. In Access you could append records in at random and those records which did not collide with a unique index goes in, and those that do collide do not go in. Obviously an index on the HashAddress will be the unique index. Is it possible to do the same kind of thing in SQL Server? When I have tried this before (in SQL Server), the whole process aborted if a collision occurred, with no records appended if there was any collision. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2918 (20080303) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2921 (20080304) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2921 (20080304) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Tue Mar 4 21:14:22 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 4 Mar 2008 22:14:22 -0500 Subject: [dba-SQLServer] Append only new records In-Reply-To: <002a01c87e45$e7733730$b659a590$@com> References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com><00db01c87e34$06ca2790$0201a8c0@M90> <007401c87e3b$7fd784a0$7f868de0$@com><00dc01c87e44$1a209d00$0201a8c0@M90> <002a01c87e45$e7733730$b659a590$@com> Message-ID: <00de01c87e6f$02d51dd0$0201a8c0@M90> To this point I have been doing it mostly with VB.Net and ADO recordsets. What I have built so far is a system where I define imports and exports using metadata tables in SQL Server. Each import / export metadata table (manually filled in to this point - one time) has information about the SQL Server table that is the source or target, the directories where the import / export files are moving from, etc. I then have a map table (for export) with metadata defining what the fields are in the source table to be exported. Flat file import field metadata is generally provided in an excel spreadsheet or CSV file by the list provider. Like that. That is all working. I can import or export CSV files and flat files simply by defining metadata records and running my program. The process consists of an initial import of a list from a slew of flat files (always flat files, that seems to be the standard in the industry) into sql server. Then an immediate export of just the name / address fields back out to CSV files, to a third party address validation program running on a server here in my office that performs the address validation - CASS and DPV. The validation program is running a watch on directories where I drop the CSV files. Each file has a million records, though I define the max record count in my metadata. The third party validation program performs the validation including uploading some info to an NCOA server over the internet. Back comes NCOA data for whatever records (people) have moved physical locations. The third party validation program reintegrates the NCOA information into fields in the validation records it is assembling. The returning data is then dropped as CSV files into directories which my program is monitoring. My VB.Net program then imports the resulting address validated CSV files (one million record files) back into SQL Server into validation tables which hold just the name / address / validation data (plus the PK of course). >From there I have to discover which addresses are undeliverable using validation codes from the CASS / DPV process and delete those records entirely. They are completely undeliverable, usually bogus or incorrect address info. The NCOA codes tell me when a person has moved from one (valid) address to another (valid) address. So I have to store the original valid address record (that is useful to me) and then update with the new valid address information from the NCOA (where they currently live). Once all the addresses are validated and any NCOA addresses are discovered and written, I create the person, family and address hash codes. I now have two tables, the original data imported from the flat files, and a smaller subset of address validation records (all valid, deliverable and NCOAd), related by a long PKID. One address list is now processed. However... the whole "export to validation, import from validation" piece has to be performed periodically. Of course that is just my code running again, the same code mentioned above. And of course my code also has to log all the processes so that I can bill my clients for the processes performed on their data. It is a rather intricate dance all in all, and it is all orchestrated by VB.Net code that I wrote in Visual Studio and using SQL Server 2005, and of course a third party CASS / DPV / NCOA program running on a server here in my office. The part we were discussing is kind of ancillary to all the stuff mentioned above. Once I have validated and NCOAd addresses, it would be nice to build a validated address table as a precursor to a system to track people movements as well as learning other stuff. For example, if I have a list of mortgages, these include all kinds of "house" information such as number of rooms, square footages, lot size etc, as well as mortgage information - sale price, mortgage payment etc. PLUS the address. I have another, completely unrelated list of people / addresses with perhaps buying preferences for electronics, or soap or cat food. I have another completely unrelated name / address list with income, ethnicity, number of children, and whatever else that list may contain. By having the VALIDATED address as common information I can now correlate completely unrelated lists and gain more information than I can gather from any individual list. EVEN if it is not the same person, I can discover that a person that lives at some address has this kind of house, that SOMEONE who lived there bought this kind of food, drove this kind of car, was this ethnic background etc. In essence simply by knowing that you lived at an address and drove a certain kind of car, by gathering sufficient information about your neighbors I can INFER what kinds of cars people in your neighborhood are LIKELY to drive, even if I have no specific information about the person at any given address. People in my neighborhood don't drive Mercedes or BMWs so why send a mailing for Mercedes or BMWs to my neighborhood? OTOH there are a LOT of dogs in my neighborhood, so it would be a safe bet that a dog food ad would go over well. In theory anyway. Do you use those "shopper cards" at the grocery store that give you a discount on various items in your shopping cart? Well the real purpose is not to give you a discount, but rather to track what you buy. If you scan your card, everything in your cart is associated with your card. Now I (my client really) can buy a list of everything that you purchased. He can then ask me to discover what kind of soap people buy who also buy dog food. By BRAND, by zip plus 4. If you were silly enough to give them a correct address, I can now discover that people who live in this neighborhood buy this kind of dog food and this kind of soap and this kind of soft drinks and this kind of... And so my client can then sell your name and address to Proctor and Gamble to direct mail you a flyer about the exact soap or dog food that you (or your neighbors) buy that is going on sale at the local supermarket. Or send you a flyer about the brand of car that you purchased last (or that your neighbor purchased last). The interesting thing is that even if you were not silly enough to give a real address... your neighbor did. My client likes to say that "junk mail is only junk if you do not want it", and that if he can learn enough about you or even your neighbors, he can target you with the junk mail that you will actually use. Kind of makes sense in a twisted way. At any rate, he pays me to maintain servers with all his lists and I am building a system to allow him to do exactly this kind of stuff. It has been interesting. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 5:20 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records Have you considered writing a proc with dynamic SQL so you can pass in the name of the source table (and maybe the column names) as a parameter and it works with any source table? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 04, 2008 3:07 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records Every table has addresses. These are marketing lists of name / address from various sources. MOST lists are "static" in that I do not get new versions of the lists, although I do get updates to one of my lists. OTOH, EVERY list has to be NCOA (National Change of Address) processed occasionally, with "occasionally" being defined as every few months. Thus I will get address changes from the NCOA process every few months for each list. My lists contain ~50 million records, ~ 75 million records and ~150 million records plus a bunch of smaller lists, 10 million etc. I can get a new list at any time and need to be able to cross reference them, i.e. which records in list A are also in list B. That is why the Hash idea was so appealing. A autonumber in any given list is only really useful within that list, it does not in any way "match" an autonumber in any other list. However I do in fact use an integer autonumber for a couple of purposes. One thing I do is take the NCOA processed data and store it in a new table, with the PKID then relating back to the original list. The NCOA data adds significant "value" to the address including such things as area code, county, congressional district, lat/long etc. Given that the NCOA has to be performed on a regular basis, and given that I am attempting to track PEOPLE (who move around) not addresses (which obviously do not move) it is useful to keep the NCOA data separate from the original list data which contains demographics information such as race, income, sex, purchasing preferences and so forth. The other usage of the PKID is simply that it allows me to export for the NCOA process and then match the returning records to the original records. But to correlate between lists I really need a hash type of functionality. It is useful to discover that a record in a list about purchasing preferences "matches" a record in another list about mortgages or yet another list about insurance policies. John W. Colby Colby Consulting www.ColbyConsulting.com From pauln at sqlserverbible.com Tue Mar 4 21:41:24 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 4 Mar 2008 20:41:24 -0700 Subject: [dba-SQLServer] Append only new records In-Reply-To: <00de01c87e6f$02d51dd0$0201a8c0@M90> References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com><00db01c87e34$06ca2790$0201a8c0@M90> <007401c87e3b$7fd784a0$7f868de0$@com><00dc01c87e44$1a209d00$0201a8c0@M90> <002a01c87e45$e7733730$b659a590$@com> <00de01c87e6f$02d51dd0$0201a8c0@M90> Message-ID: <001701c87e72$ca0dc250$5e2946f0$@com> I built nearly the same type of system for an airline data warehouse a couple years ago using all stored procs + bulk insert. The code was small and it screamed. Bulk Insert is very fast. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 04, 2008 8:14 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records To this point I have been doing it mostly with VB.Net and ADO recordsets. What I have built so far is a system where I define imports and exports using metadata tables in SQL Server. Each import / export metadata table (manually filled in to this point - one time) has information about the SQL Server table that is the source or target, the directories where the import / export files are moving from, etc. I then have a map table (for export) with metadata defining what the fields are in the source table to be exported. Flat file import field metadata is generally provided in an excel spreadsheet or CSV file by the list provider. Like that. That is all working. I can import or export CSV files and flat files simply by defining metadata records and running my program. The process consists of an initial import of a list from a slew of flat files (always flat files, that seems to be the standard in the industry) into sql server. Then an immediate export of just the name / address fields back out to CSV files, to a third party address validation program running on a server here in my office that performs the address validation - CASS and DPV. The validation program is running a watch on directories where I drop the CSV files. Each file has a million records, though I define the max record count in my metadata. The third party validation program performs the validation including uploading some info to an NCOA server over the internet. Back comes NCOA data for whatever records (people) have moved physical locations. The third party validation program reintegrates the NCOA information into fields in the validation records it is assembling. The returning data is then dropped as CSV files into directories which my program is monitoring. My VB.Net program then imports the resulting address validated CSV files (one million record files) back into SQL Server into validation tables which hold just the name / address / validation data (plus the PK of course). >From there I have to discover which addresses are undeliverable using validation codes from the CASS / DPV process and delete those records entirely. They are completely undeliverable, usually bogus or incorrect address info. The NCOA codes tell me when a person has moved from one (valid) address to another (valid) address. So I have to store the original valid address record (that is useful to me) and then update with the new valid address information from the NCOA (where they currently live). Once all the addresses are validated and any NCOA addresses are discovered and written, I create the person, family and address hash codes. I now have two tables, the original data imported from the flat files, and a smaller subset of address validation records (all valid, deliverable and NCOAd), related by a long PKID. One address list is now processed. However... the whole "export to validation, import from validation" piece has to be performed periodically. Of course that is just my code running again, the same code mentioned above. And of course my code also has to log all the processes so that I can bill my clients for the processes performed on their data. It is a rather intricate dance all in all, and it is all orchestrated by VB.Net code that I wrote in Visual Studio and using SQL Server 2005, and of course a third party CASS / DPV / NCOA program running on a server here in my office. The part we were discussing is kind of ancillary to all the stuff mentioned above. Once I have validated and NCOAd addresses, it would be nice to build a validated address table as a precursor to a system to track people movements as well as learning other stuff. For example, if I have a list of mortgages, these include all kinds of "house" information such as number of rooms, square footages, lot size etc, as well as mortgage information - sale price, mortgage payment etc. PLUS the address. I have another, completely unrelated list of people / addresses with perhaps buying preferences for electronics, or soap or cat food. I have another completely unrelated name / address list with income, ethnicity, number of children, and whatever else that list may contain. By having the VALIDATED address as common information I can now correlate completely unrelated lists and gain more information than I can gather from any individual list. EVEN if it is not the same person, I can discover that a person that lives at some address has this kind of house, that SOMEONE who lived there bought this kind of food, drove this kind of car, was this ethnic background etc. In essence simply by knowing that you lived at an address and drove a certain kind of car, by gathering sufficient information about your neighbors I can INFER what kinds of cars people in your neighborhood are LIKELY to drive, even if I have no specific information about the person at any given address. People in my neighborhood don't drive Mercedes or BMWs so why send a mailing for Mercedes or BMWs to my neighborhood? OTOH there are a LOT of dogs in my neighborhood, so it would be a safe bet that a dog food ad would go over well. In theory anyway. Do you use those "shopper cards" at the grocery store that give you a discount on various items in your shopping cart? Well the real purpose is not to give you a discount, but rather to track what you buy. If you scan your card, everything in your cart is associated with your card. Now I (my client really) can buy a list of everything that you purchased. He can then ask me to discover what kind of soap people buy who also buy dog food. By BRAND, by zip plus 4. If you were silly enough to give them a correct address, I can now discover that people who live in this neighborhood buy this kind of dog food and this kind of soap and this kind of soft drinks and this kind of... And so my client can then sell your name and address to Proctor and Gamble to direct mail you a flyer about the exact soap or dog food that you (or your neighbors) buy that is going on sale at the local supermarket. Or send you a flyer about the brand of car that you purchased last (or that your neighbor purchased last). The interesting thing is that even if you were not silly enough to give a real address... your neighbor did. My client likes to say that "junk mail is only junk if you do not want it", and that if he can learn enough about you or even your neighbors, he can target you with the junk mail that you will actually use. Kind of makes sense in a twisted way. At any rate, he pays me to maintain servers with all his lists and I am building a system to allow him to do exactly this kind of stuff. It has been interesting. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 04, 2008 5:20 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records Have you considered writing a proc with dynamic SQL so you can pass in the name of the source table (and maybe the column names) as a parameter and it works with any source table? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 04, 2008 3:07 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Append only new records Every table has addresses. These are marketing lists of name / address from various sources. MOST lists are "static" in that I do not get new versions of the lists, although I do get updates to one of my lists. OTOH, EVERY list has to be NCOA (National Change of Address) processed occasionally, with "occasionally" being defined as every few months. Thus I will get address changes from the NCOA process every few months for each list. My lists contain ~50 million records, ~ 75 million records and ~150 million records plus a bunch of smaller lists, 10 million etc. I can get a new list at any time and need to be able to cross reference them, i.e. which records in list A are also in list B. That is why the Hash idea was so appealing. A autonumber in any given list is only really useful within that list, it does not in any way "match" an autonumber in any other list. However I do in fact use an integer autonumber for a couple of purposes. One thing I do is take the NCOA processed data and store it in a new table, with the PKID then relating back to the original list. The NCOA data adds significant "value" to the address including such things as area code, county, congressional district, lat/long etc. Given that the NCOA has to be performed on a regular basis, and given that I am attempting to track PEOPLE (who move around) not addresses (which obviously do not move) it is useful to keep the NCOA data separate from the original list data which contains demographics information such as race, income, sex, purchasing preferences and so forth. The other usage of the PKID is simply that it allows me to export for the NCOA process and then match the returning records to the original records. But to correlate between lists I really need a hash type of functionality. It is useful to discover that a record in a list about purchasing preferences "matches" a record in another list about mortgages or yet another list about insurance policies. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2922 (20080305) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Sat Mar 8 20:12:45 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sat, 8 Mar 2008 21:12:45 -0500 Subject: [dba-SQLServer] Is AccessD down? Message-ID: <01dd01c8818b$110f6d00$0201a8c0@M90> I don't seem to be getting posts on the Access list. John W. Colby Colby Consulting www.ColbyConsulting.com From markamatte at hotmail.com Mon Mar 10 13:41:34 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Mon, 10 Mar 2008 18:41:34 +0000 Subject: [dba-SQLServer] Did MS Visual Web Dev load SQL2005? In-Reply-To: <00de01c87e6f$02d51dd0$0201a8c0@M90> References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com><00db01c87e34$06ca2790$0201a8c0@M90> <007401c87e3b$7fd784a0$7f868de0$@com><00dc01c87e44$1a209d00$0201a8c0@M90> <002a01c87e45$e7733730$b659a590$@com> <00de01c87e6f$02d51dd0$0201a8c0@M90> Message-ID: Hello All, I installed MS Visual Web Developer...it installed MS SQL Server 2005...or at least put a folder in Programs with the Configuration Manager. I had SQL7 on the machine. I want SQL 2005 on the machine...how do I tell what is there? Do I need to UNinstall SQL7...or just leave it alone? Thanks, Mark A. Matte _________________________________________________________________ Need to know the score, the latest news, or you need your Hotmail?-get your "fix". http://www.msnmobilefix.com/Default.aspx From jlawrenc1 at shaw.ca Mon Mar 10 19:38:40 2008 From: jlawrenc1 at shaw.ca (Jim Lawrence) Date: Mon, 10 Mar 2008 17:38:40 -0700 Subject: [dba-SQLServer] Did MS Visual Web Dev load SQL2005? In-Reply-To: References: <007901c87d7c$5f255d00$0201a8c0@M90> <00b901c87e26$95c48340$c14d89c0$@com> <00db01c87e34$06ca2790$0201a8c0@M90> <007401c87e3b$7fd784a0$7f868de0$@com> <00dc01c87e44$1a209d00$0201a8c0@M90> <002a01c87e45$e7733730$b659a590$@com> <00de01c87e6f$02d51dd0$0201a8c0@M90> Message-ID: <39C05002ACE449B2936EA356CF52B338@creativesystemdesigns.com> Hi Mark: You should not have to. When installing the new SQL 2005 it will discover and ask you what port or pipe you wish to use. If MS SQL 7 is using port 1433 and 1434 (SQL monitor) just choose another couple of ports like 1477 or 1478 as no other major application uses these. HTH Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark A Matte Sent: Monday, March 10, 2008 11:42 AM To: Discussion concerning MS SQL Server Subject: [dba-SQLServer] Did MS Visual Web Dev load SQL2005? Hello All, I installed MS Visual Web Developer...it installed MS SQL Server 2005...or at least put a folder in Programs with the Configuration Manager. I had SQL7 on the machine. I want SQL 2005 on the machine...how do I tell what is there? Do I need to UNinstall SQL7...or just leave it alone? Thanks, Mark A. Matte _________________________________________________________________ Need to know the score, the latest news, or you need your HotmailR-get your "fix". http://www.msnmobilefix.com/Default.aspx _______________________________________________ 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 Mar 13 10:59:17 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 13 Mar 2008 11:59:17 -0400 Subject: [dba-SQLServer] Mirrored servers Message-ID: <000501c88523$327fb940$0201a8c0@M90> I have two servers running Windows 2003 and SQL Server 2005. I would like to be able to have identical databases on both and work on both simultaneously, iow "keep them in sync". If I update a table on ServerA I need it to update on ServerB. If I update a table on ServerB I need it to update on ServerA. Is this possible? I do a fair amount of SQL Server stuff now and it is all running on ServerA. If it dies, then whatever I did is not on ServerB even though Server B is capable. If I somehow cause it to mirror stuff over to ServerB and then it dies, I could work on ServerB, but when I got ServerA working again, now I need to get the information synced back to ServerA. I have read a little about "failover" but that is not precisely what I am looking for. I would like to be able to run jobs on ServerA, then while that is running, run jobs on ServerB. When each finishes, the results need to post back to the other server. Is what I am trying to do possible, and if so where can I go to learn how to set it up. John W. Colby Colby Consulting www.ColbyConsulting.com From Gustav at cactus.dk Thu Mar 13 11:03:37 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 13 Mar 2008 17:03:37 +0100 Subject: [dba-SQLServer] Mirrored servers Message-ID: Hi John Sounds like replication to me. Can't you set that up from the SQL Manager? /gustav >>> jwcolby at colbyconsulting.com 13-03-2008 16:59 >>> I have two servers running Windows 2003 and SQL Server 2005. I would like to be able to have identical databases on both and work on both simultaneously, iow "keep them in sync". If I update a table on ServerA I need it to update on ServerB. If I update a table on ServerB I need it to update on ServerA. Is this possible? I do a fair amount of SQL Server stuff now and it is all running on ServerA. If it dies, then whatever I did is not on ServerB even though Server B is capable. If I somehow cause it to mirror stuff over to ServerB and then it dies, I could work on ServerB, but when I got ServerA working again, now I need to get the information synced back to ServerA. I have read a little about "failover" but that is not precisely what I am looking for. I would like to be able to run jobs on ServerA, then while that is running, run jobs on ServerB. When each finishes, the results need to post back to the other server. Is what I am trying to do possible, and if so where can I go to learn how to set it up. John W. Colby Colby Consulting www.ColbyConsulting.com From fhtapia at gmail.com Thu Mar 13 11:19:13 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 13 Mar 2008 09:19:13 -0700 Subject: [dba-SQLServer] Mirrored servers In-Reply-To: <000501c88523$327fb940$0201a8c0@M90> References: <000501c88523$327fb940$0201a8c0@M90> Message-ID: John, You want to read the section in BOL for database mirroring (btw, its very cool). Keep in mind it could be most instrumental to have a seperate pc as the witness that way you won't have to worry about loosing the witness if server a dies but b is alive and well. On 3/13/08, jwcolby wrote: > I have two servers running Windows 2003 and SQL Server 2005. I would like > to be able to have identical databases on both and work on both > simultaneously, iow "keep them in sync". If I update a table on ServerA I > need it to update on ServerB. If I update a table on ServerB I need it to > update on ServerA. > > Is this possible? I do a fair amount of SQL Server stuff now and it is all > running on ServerA. If it dies, then whatever I did is not on ServerB even > though Server B is capable. If I somehow cause it to mirror stuff over to > ServerB and then it dies, I could work on ServerB, but when I got ServerA > working again, now I need to get the information synced back to ServerA. > > I have read a little about "failover" but that is not precisely what I am > looking for. I would like to be able to run jobs on ServerA, then while > that is running, run jobs on ServerB. When each finishes, the results need > to post back to the other server. > > Is what I am trying to do possible, and if so where can I go to learn how to > set it up. > > John W. Colby > Colby Consulting > 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 Gmail for mobile | mobile.google.com -Francisco http://sqlthis.blogspot.com | Tsql and More... From fuller.artful at gmail.com Thu Mar 13 12:07:13 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 13 Mar 2008 13:07:13 -0400 Subject: [dba-SQLServer] Mirrored servers In-Reply-To: References: <000501c88523$327fb940$0201a8c0@M90> Message-ID: <29f585dd0803131007n56b45afdv845f869e02b1cc28@mail.gmail.com> I agree with Francisco. Three machines is the best way to go with mirroring. The witness machine need not be a server since its requirements are minimal. Pretty much any old box will do as a witness. A. On 3/13/08, Francisco Tapia wrote: > > John, > You want to read the section in BOL for database mirroring (btw, its > very cool). Keep in mind it could be most instrumental to have a > seperate pc as the witness that way you won't have to worry about > loosing the witness if server a dies but b is alive and well. > From ab-mi at post3.tele.dk Thu Mar 13 18:30:19 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Fri, 14 Mar 2008 00:30:19 +0100 Subject: [dba-SQLServer] Mirrored servers In-Reply-To: <20080313160059.LFVN5833.fep27.mail.dk@databaseadvisors.com> Message-ID: <000001c88562$34004020$2101a8c0@AB> Database mirroring is not an option, since you want both databases to be operational. For the scenario given I would definitely choose replication, and more specifically: Peer-To-Peer Transactional Replication, which will give you fully operational databases on both sites and near real-time synchronization. Using this type of replication you have to make sure that conflicts can't arise, since Peer-To-Peer Transaction Replication doesn?t have conflict resolution, as Merge Replication have. You could choose Merge Replication, but then you would have latency of synchronization. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 13. marts 2008 16:59 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Mirrored servers I have two servers running Windows 2003 and SQL Server 2005. I would like to be able to have identical databases on both and work on both simultaneously, iow "keep them in sync". If I update a table on ServerA I need it to update on ServerB. If I update a table on ServerB I need it to update on ServerA. Is this possible? I do a fair amount of SQL Server stuff now and it is all running on ServerA. If it dies, then whatever I did is not on ServerB even though Server B is capable. If I somehow cause it to mirror stuff over to ServerB and then it dies, I could work on ServerB, but when I got ServerA working again, now I need to get the information synced back to ServerA. I have read a little about "failover" but that is not precisely what I am looking for. I would like to be able to run jobs on ServerA, then while that is running, run jobs on ServerB. When each finishes, the results need to post back to the other server. Is what I am trying to do possible, and if so where can I go to learn how to set it up. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 Mar 13 21:05:40 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 13 Mar 2008 22:05:40 -0400 Subject: [dba-SQLServer] Mirrored servers In-Reply-To: <000001c88562$34004020$2101a8c0@AB> References: <20080313160059.LFVN5833.fep27.mail.dk@databaseadvisors.com> <000001c88562$34004020$2101a8c0@AB> Message-ID: <000d01c88577$e7ef9620$0201a8c0@M90> Asger, These are not transactional databases, so I am not too worried about "up to the minute" (or second) synchronization. These databases are huge name lists that I maintain for a company that sells name / address lists to bulk mailers. I routinely use one of the servers, and I do what has turned into a standardized count of people WHERE (a bunch of criteria here). The client asks for counts of how many people fit a criteria list. He calls these things "counts" because that is the terminology in his business, I call them jobs. I have created a database with about 20 odd views. A couple of views pull a specific set of fields from two or three other databases. One view is a criteria view. All of these 3 or 4 views are inner joined to pull a set of names. I then have about 20 "count" views that give me Order by / count information on a fixed set of data items in 20 specific fields. It is these counts that he really cares about. So... I have a "template" database that contains all of these views already designed and working. I just literally (from inside of SQL Server) COPY that template database to a specific name. I then set that one "criteria" view to pull a set of PKIDs, and then I run the ~20 count views, and manually (for now) copy and paste each count "table" (dataset) into a page of a spreadsheet. When I am done I have a spreadsheet with a page for each count dataset. I then email him the count spreadsheet with the 20 odd pages of counts. I go through all this rigmarole because he may come back next week and say "give me 100,000 actual names and addresses based on the count order I gave you last week". I can then go into this count database and run another view that hands me 100,000 of those names. Obviously the counts are his marketing to his client, the order may or may not ever come but if it does I had better be able to pull as many names as the counts say he has, and do so quickly. So as you can see, the business is a copy database, modify a view, run a set of count queries, copy to a spreadsheet and email it. Now I have a database that I have to archive because I may someday get an "order" (as opposed to a count). My objective is twofold. First I want a backup of all these databases off on another machine in case the main server I use goes down. Second if I am busy running a job on one server, I want to be able to run a different job on the other server. But at the end of the day I want both servers to have any work done on either server. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Thursday, March 13, 2008 7:30 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Mirrored servers Database mirroring is not an option, since you want both databases to be operational. For the scenario given I would definitely choose replication, and more specifically: Peer-To-Peer Transactional Replication, which will give you fully operational databases on both sites and near real-time synchronization. Using this type of replication you have to make sure that conflicts can't arise, since Peer-To-Peer Transaction Replication doesn't have conflict resolution, as Merge Replication have. You could choose Merge Replication, but then you would have latency of synchronization. Asger From ebarro at verizon.net Fri Mar 14 01:48:02 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 13 Mar 2008 23:48:02 -0700 Subject: [dba-SQLServer] Mirrored servers In-Reply-To: <000001c88562$34004020$2101a8c0@AB> Message-ID: <0JXP00JQXK3IS4Z1@vms173003.mailsrvcs.net> John, One annoying side effect of replication is the introduction of a GUID field to EVERY table that is part of the subscription and it is needed for replication to work. So, if your table structures cannot accommodate a new GUID field then you might want to reconsider going the route of replication. Replication also consumes a lot of resources on the processing side since it has to take a snapshot of the data at pre-defined times. Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Thursday, March 13, 2008 4:30 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Mirrored servers Database mirroring is not an option, since you want both databases to be operational. For the scenario given I would definitely choose replication, and more specifically: Peer-To-Peer Transactional Replication, which will give you fully operational databases on both sites and near real-time synchronization. Using this type of replication you have to make sure that conflicts can't arise, since Peer-To-Peer Transaction Replication doesn?t have conflict resolution, as Merge Replication have. You could choose Merge Replication, but then you would have latency of synchronization. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 13. marts 2008 16:59 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Mirrored servers I have two servers running Windows 2003 and SQL Server 2005. I would like to be able to have identical databases on both and work on both simultaneously, iow "keep them in sync". If I update a table on ServerA I need it to update on ServerB. If I update a table on ServerB I need it to update on ServerA. Is this possible? I do a fair amount of SQL Server stuff now and it is all running on ServerA. If it dies, then whatever I did is not on ServerB even though Server B is capable. If I somehow cause it to mirror stuff over to ServerB and then it dies, I could work on ServerB, but when I got ServerA working again, now I need to get the information synced back to ServerA. I have read a little about "failover" but that is not precisely what I am looking for. I would like to be able to run jobs on ServerA, then while that is running, run jobs on ServerB. When each finishes, the results need to post back to the other server. Is what I am trying to do possible, and if so where can I go to learn how to set it up. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 From markamatte at hotmail.com Fri Mar 14 10:09:46 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Fri, 14 Mar 2008 15:09:46 +0000 Subject: [dba-SQLServer] Moving VBA to SQL Server In-Reply-To: <0JXP00JQXK3IS4Z1@vms173003.mailsrvcs.net> References: <000001c88562$34004020$2101a8c0@AB> <0JXP00JQXK3IS4Z1@vms173003.mailsrvcs.net> Message-ID: Hello All, I currently have an MDB that does the following: 1. Checks FTP site to see if there are files.(does not know name of files) CONTINUE checking until there are files 2. Get FTP files. 3. Unzips FTP files. 4. Imports file. 5. Runs SQL stored in tables against new data. 6. Saves/emails results of SQL. 7. Cleans up and waits for 30 minutes. This works like a charm in Access...I plan on moving to SQL Server, creating a site to go with it and have it hosted. I need this thing to run every 30 minutes. Its been suggested that I use VB scripts since I am so familiar with VBA. I'm a little confused on the approach. Q1. Are these 6 different scripts...1 large script...some scripts...some SP? Q2. How do I launch/manage these tasks? They all have to run...but in order. Q3. If multiple Scripts and SP...how does 1 know the other is done? ...there are more questions...but this is more than enough for me to chew right now. I'm not really looking for code (would be nice if it landed in my inbox)...but more for suggested approaches and direction. Any thoughts/ideas/guidence? Thanks, Mark A. Matte _________________________________________________________________ Shed those extra pounds with MSN and The Biggest Loser! http://biggestloser.msn.com/ From ebarro at verizon.net Fri Mar 14 13:11:48 2008 From: ebarro at verizon.net (Eric Barro) Date: Fri, 14 Mar 2008 11:11:48 -0700 Subject: [dba-SQLServer] Moving VBA to SQL Server In-Reply-To: Message-ID: <0JXQ00IDYFWUHJ63@vms044.mailsrvcs.net> Mark, Create a scheduled job in SQL that has the 6 steps. Schedule the job to run every 30 minutes and you're done. Steps 1-3 would most probably be VBA scripts. Steps 4-6 would most probably be SQL stored procedures. Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark A Matte Sent: Friday, March 14, 2008 8:10 AM To: Discussion concerning MS SQL Server Subject: [dba-SQLServer] Moving VBA to SQL Server Hello All, I currently have an MDB that does the following: 1. Checks FTP site to see if there are files.(does not know name of files) CONTINUE checking until there are files 2. Get FTP files. 3. Unzips FTP files. 4. Imports file. 5. Runs SQL stored in tables against new data. 6. Saves/emails results of SQL. 7. Cleans up and waits for 30 minutes. This works like a charm in Access...I plan on moving to SQL Server, creating a site to go with it and have it hosted. I need this thing to run every 30 minutes. Its been suggested that I use VB scripts since I am so familiar with VBA. I'm a little confused on the approach. Q1. Are these 6 different scripts...1 large script...some scripts...some SP? Q2. How do I launch/manage these tasks? They all have to run...but in order. Q3. If multiple Scripts and SP...how does 1 know the other is done? ...there are more questions...but this is more than enough for me to chew right now. I'm not really looking for code (would be nice if it landed in my inbox)...but more for suggested approaches and direction. Any thoughts/ideas/guidence? Thanks, Mark A. Matte _________________________________________________________________ Shed those extra pounds with MSN and The Biggest Loser! http://biggestloser.msn.com/ _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ab-mi at post3.tele.dk Fri Mar 14 16:49:51 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Fri, 14 Mar 2008 22:49:51 +0100 Subject: [dba-SQLServer] Mirrored servers In-Reply-To: <20080314020805.PCMC10334.fep25.mail.dk@databaseadvisors.com> Message-ID: <001501c8861d$69b87910$2101a8c0@AB> John, One thing I forgot to mention is that replication is always "article based", meaning that you only get synchronization of objects you have included in your publication - new objects (tables, views etc.) that you create in the database won't be propagated to the replica. - For that reason replication may not be a choice in your case. Database Mirroring on the other hand is "database based", meaning that the whole database is duplicated, and that new objects are propagated to the mirror as well. But in a mirror-scenario you have a "principal database" which is operational, and a "mirror database" which is in a recovering (non-operational) state. You can easily switch the role of the two databases but you can't have both databases operational (run jobs on both) as the same time. An Active-Active Clustering solution would certainly do, but probably would explode your budget too... If you want new objects propagated in an active-active scenario I don't know of an affordable solution. Maybe other listers do? Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 14. marts 2008 03:06 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] Mirrored servers Asger, These are not transactional databases, so I am not too worried about "up to the minute" (or second) synchronization. These databases are huge name lists that I maintain for a company that sells name / address lists to bulk mailers. I routinely use one of the servers, and I do what has turned into a standardized count of people WHERE (a bunch of criteria here). The client asks for counts of how many people fit a criteria list. He calls these things "counts" because that is the terminology in his business, I call them jobs. I have created a database with about 20 odd views. A couple of views pull a specific set of fields from two or three other databases. One view is a criteria view. All of these 3 or 4 views are inner joined to pull a set of names. I then have about 20 "count" views that give me Order by / count information on a fixed set of data items in 20 specific fields. It is these counts that he really cares about. So... I have a "template" database that contains all of these views already designed and working. I just literally (from inside of SQL Server) COPY that template database to a specific name. I then set that one "criteria" view to pull a set of PKIDs, and then I run the ~20 count views, and manually (for now) copy and paste each count "table" (dataset) into a page of a spreadsheet. When I am done I have a spreadsheet with a page for each count dataset. I then email him the count spreadsheet with the 20 odd pages of counts. I go through all this rigmarole because he may come back next week and say "give me 100,000 actual names and addresses based on the count order I gave you last week". I can then go into this count database and run another view that hands me 100,000 of those names. Obviously the counts are his marketing to his client, the order may or may not ever come but if it does I had better be able to pull as many names as the counts say he has, and do so quickly. So as you can see, the business is a copy database, modify a view, run a set of count queries, copy to a spreadsheet and email it. Now I have a database that I have to archive because I may someday get an "order" (as opposed to a count). My objective is twofold. First I want a backup of all these databases off on another machine in case the main server I use goes down. Second if I am busy running a job on one server, I want to be able to run a different job on the other server. But at the end of the day I want both servers to have any work done on either server. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Thursday, March 13, 2008 7:30 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Mirrored servers Database mirroring is not an option, since you want both databases to be operational. For the scenario given I would definitely choose replication, and more specifically: Peer-To-Peer Transactional Replication, which will give you fully operational databases on both sites and near real-time synchronization. Using this type of replication you have to make sure that conflicts can't arise, since Peer-To-Peer Transaction Replication doesn't have conflict resolution, as Merge Replication have. You could choose Merge Replication, but then you would have latency of synchronization. Asger _______________________________________________ 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 Tue Mar 18 12:50:17 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 18 Mar 2008 13:50:17 -0400 Subject: [dba-SQLServer] SQL Server date functions Message-ID: <004f01c88920$876cc370$0201a8c0@M90> I am pulling a TopN kind of thing and marking those records with GetDate() which places a date and time in a date field. Now I want to pull all the records with today's date. The first problem is that GetDate() pulls the date and time. The second problem is what to place in the filter. I am not finding a date() kind of thing like you have with Access. How do I pull all records with today's date in a date field (that also contains the time)? John W. Colby Colby Consulting www.ColbyConsulting.com From pauln at sqlserverbible.com Tue Mar 18 13:04:24 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 18 Mar 2008 12:04:24 -0600 Subject: [dba-SQLServer] SQL Server date functions In-Reply-To: <004f01c88920$876cc370$0201a8c0@M90> References: <004f01c88920$876cc370$0201a8c0@M90> Message-ID: <007b01c88922$80bad380$82307a80$@com> Cast() or convert() I'd recommend converting to the date only as the data goes in. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 18, 2008 11:50 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] SQL Server date functions I am pulling a TopN kind of thing and marking those records with GetDate() which places a date and time in a date field. Now I want to pull all the records with today's date. The first problem is that GetDate() pulls the date and time. The second problem is what to place in the filter. I am not finding a date() kind of thing like you have with Access. How do I pull all records with today's date in a date field (that also contains the time)? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2957 (20080318) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From Elizabeth.J.Doering at wellsfargo.com Tue Mar 18 13:06:38 2008 From: Elizabeth.J.Doering at wellsfargo.com (Elizabeth.J.Doering at wellsfargo.com) Date: Tue, 18 Mar 2008 13:06:38 -0500 Subject: [dba-SQLServer] SQL Server date functions References: <004f01c88920$876cc370$0201a8c0@M90> Message-ID: John, Select myfield from mytable where mydatefield > getdate()-1 Pulls everything in the last 24 hours. You could come up with more elegant variations with dateadd or datediff to get exactly the correct number of hours. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 18, 2008 12:50 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] SQL Server date functions I am pulling a TopN kind of thing and marking those records with GetDate() which places a date and time in a date field. Now I want to pull all the records with today's date. The first problem is that GetDate() pulls the date and time. The second problem is what to place in the filter. I am not finding a date() kind of thing like you have with Access. How do I pull all records with today's date in a date field (that also contains the time)? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From robert at webedb.com Tue Mar 18 13:20:27 2008 From: robert at webedb.com (Robert L. Stewart) Date: Tue, 18 Mar 2008 13:20:27 -0500 Subject: [dba-SQLServer] SQL Server date functions In-Reply-To: References: Message-ID: <200803181821.m2IILk8x018469@databaseadvisors.com> date between '1/1/2008 00:00:00' and '1/2/2008 00:00:00' It is best to strip the time off when doing what you are doing. Check the CONVERT function. Robert At 01:00 PM 3/18/2008, you wrote: >Date: Tue, 18 Mar 2008 13:50:17 -0400 >From: "jwcolby" >Subject: [dba-SQLServer] SQL Server date functions >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <004f01c88920$876cc370$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >I am pulling a TopN kind of thing and marking those records with GetDate() >which places a date and time in a date field. Now I want to pull all the >records with today's date. The first problem is that GetDate() pulls the >date and time. The second problem is what to place in the filter. I am not >finding a date() kind of thing like you have with Access. > >How do I pull all records with today's date in a date field (that also >contains the time)? > >John W. Colby >Colby Consulting >www.ColbyConsulting.com > > > >------------------------------ > >_______________________________________________ >dba-SQLServer mailing list >dba-SQLServer at databaseadvisors.com >http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > > >End of dba-SQLServer Digest, Vol 61, Issue 10 >********************************************* From fuller.artful at gmail.com Tue Mar 18 13:30:47 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Tue, 18 Mar 2008 14:30:47 -0400 Subject: [dba-SQLServer] SQL Server date functions In-Reply-To: <004f01c88920$876cc370$0201a8c0@M90> References: <004f01c88920$876cc370$0201a8c0@M90> Message-ID: <29f585dd0803181130o6459b327ke13bc959c162ab5a@mail.gmail.com> Here you go, JC. CREATE FUNCTION [dbo].[fn_JustDate] ( @date datetime ) RETURNS varchar(10) AS BEGIN RETURN ( CONVERT(varchar(10), at date,101) ) END Call it in your Where clause, passing the date column in question and presto. Arthur On 3/18/08, jwcolby wrote: > > I am pulling a TopN kind of thing and marking those records with GetDate() > which places a date and time in a date field. Now I want to pull all the > records with today's date. The first problem is that GetDate() pulls the > date and time. The second problem is what to place in the filter. I am > not > finding a date() kind of thing like you have with Access. > > How do I pull all records with today's date in a date field (that also > contains the time)? > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From markamatte at hotmail.com Tue Mar 18 13:35:26 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Tue, 18 Mar 2008 18:35:26 +0000 Subject: [dba-SQLServer] SQL Server date functions In-Reply-To: References: <004f01c88920$876cc370$0201a8c0@M90> Message-ID: Not sure if it is the best...but a number of the older reporting systems I recently inherited...use DATEPART for month, day, and year...on the fields with date and time....and then add criteria to each part. Mark A. Matte http://msdn2.microsoft.com/en-us/library/ms174420.aspx ****************** SELECT DATEPART(m, MyDateTime), DATEPART(d, MyDateTime), DATEPART(yy, MyDateTime) ****************** > Date: Tue, 18 Mar 2008 13:06:38 -0500 > From: Elizabeth.J.Doering at wellsfargo.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] SQL Server date functions > > John, > > Select myfield from mytable where mydatefield> getdate()-1 > > Pulls everything in the last 24 hours. > > You could come up with more elegant variations with dateadd or datediff > to get exactly the correct number of hours. > > HTH, > > > Liz > > > Liz Doering > elizabeth.j.doering at wellsfargo.com > 612.667.2447 > > > This message may contain confidential and/or privileged information. If > you are not the addressee or authorized to receive this for the > addressee, you must not use, copy, disclose, or take any action based on > this message or any information herein. If you have received this > message in error, please advise the sender immediately by reply e-mail > and delete this message. Thank you for your cooperation. > > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Tuesday, March 18, 2008 12:50 PM > To: 'Discussion concerning MS SQL Server' > Subject: [dba-SQLServer] SQL Server date functions > > I am pulling a TopN kind of thing and marking those records with > GetDate() which places a date and time in a date field. Now I want to > pull all the records with today's date. The first problem is that > GetDate() pulls the date and time. The second problem is what to place > in the filter. I am not finding a date() kind of thing like you have > with Access. > > How do I pull all records with today's date in a date field (that also > contains the time)? > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > 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 > _________________________________________________________________ Connect and share in new ways with Windows Live. http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008 From fuller.artful at gmail.com Tue Mar 18 13:40:34 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Tue, 18 Mar 2008 14:40:34 -0400 Subject: [dba-SQLServer] SQL Server date functions In-Reply-To: <29f585dd0803181130o6459b327ke13bc959c162ab5a@mail.gmail.com> References: <004f01c88920$876cc370$0201a8c0@M90> <29f585dd0803181130o6459b327ke13bc959c162ab5a@mail.gmail.com> Message-ID: <29f585dd0803181140x7ea3edddt34db31d57006530@mail.gmail.com> Just for completeness, JC, here's a function to grab just the time part, called (gasp) TimePart(). Where do I come up with these names? CREATE FUNCTION [dbo].[TimePart] ( @fDate datetime ) RETURNS varchar(10) AS BEGIN RETURN ( CONVERT(varchar(7),right(@fDate,7),101) ) END Arthur From jwcolby at colbyconsulting.com Tue Mar 18 13:41:13 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 18 Mar 2008 14:41:13 -0400 Subject: [dba-SQLServer] SQL Server date functions In-Reply-To: <29f585dd0803181130o6459b327ke13bc959c162ab5a@mail.gmail.com> References: <004f01c88920$876cc370$0201a8c0@M90> <29f585dd0803181130o6459b327ke13bc959c162ab5a@mail.gmail.com> Message-ID: <006301c88927$a4dbd7a0$0201a8c0@M90> Cool, thanks! John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Tuesday, March 18, 2008 2:31 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Server date functions Here you go, JC. CREATE FUNCTION [dbo].[fn_JustDate] ( @date datetime ) RETURNS varchar(10) AS BEGIN RETURN ( CONVERT(varchar(10), at date,101) ) END Call it in your Where clause, passing the date column in question and presto. Arthur On 3/18/08, jwcolby wrote: > > I am pulling a TopN kind of thing and marking those records with > GetDate() which places a date and time in a date field. Now I want to > pull all the records with today's date. The first problem is that > GetDate() pulls the date and time. The second problem is what to > place in the filter. I am not finding a date() kind of thing like you > have with Access. > > How do I pull all records with today's date in a date field (that also > contains the time)? > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > 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 From David at sierranevada.com Tue Mar 18 14:09:08 2008 From: David at sierranevada.com (David Lewis) Date: Tue, 18 Mar 2008 12:09:08 -0700 Subject: [dba-SQLServer] Dates and times In-Reply-To: References: Message-ID: John: You need to strip the time portion off the date, then convert it back to a date, then do your compare. For example: DECLARE @dt DATETIME SET @dt = ' 2008-03-24 10:19:02' SET @dt=CONVERT(DATETIME,(CONVERT(VARCHAR, at dt,112))) PRINT CONVERT(VARCHAR, at dt) This will return Mar 24 2008 12:00AM The 12:00AM is the default time for any date that has no time associated with it. When you do your compare of today's date with the date in the table, you will have to transform both dates as above. I am pulling a TopN kind of thing and marking those records with GetDate() which places a date and time in a date field. Now I want to pull all the records with today's date. The first problem is that GetDate() pulls the date and time. The second problem is what to place in the filter. I am not finding a date() kind of thing like you have with Access. How do I pull all records with today's date in a date field (that also contains the time)? John W. Colby Colby Consulting www.ColbyConsulting.com ------------------------------ _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver End of dba-SQLServer Digest, Vol 61, Issue 10 ********************************************* 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 pauln at sqlserverbible.com Tue Mar 18 14:19:45 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 18 Mar 2008 13:19:45 -0600 Subject: [dba-SQLServer] SQL Server date functions In-Reply-To: <004f01c88920$876cc370$0201a8c0@M90> References: <004f01c88920$876cc370$0201a8c0@M90> Message-ID: <00d401c8892d$073beac0$15b3c040$@com> Now that I think about it I did a study a couple years ago of the fastest possible way to extract the date from datetime. This is what I found at the time (no pun in 10 did) SELECT Convert(CHAR(10), CURRENT_TIMESTAMP, 101 ) -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 18, 2008 11:50 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] SQL Server date functions I am pulling a TopN kind of thing and marking those records with GetDate() which places a date and time in a date field. Now I want to pull all the records with today's date. The first problem is that GetDate() pulls the date and time. The second problem is what to place in the filter. I am not finding a date() kind of thing like you have with Access. How do I pull all records with today's date in a date field (that also contains the time)? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2957 (20080318) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fhtapia at gmail.com Tue Mar 18 14:30:27 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 18 Mar 2008 12:30:27 -0700 Subject: [dba-SQLServer] database mirroring problem Message-ID: No sooner did I chime in to use database mirroring that a colleague of mine asked for help on setting his two servers. I created an instance on server B, and have disabled symantec and the windows firewall on both servers (reboot included) I made sure that both servers (all three instances are running with SP2 (sql server 2005). But I am not able to see the 2nd instance on the 2nd server for some reason. Have any of you ran into this error before? -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From James at fcidms.com Tue Mar 18 15:08:25 2008 From: James at fcidms.com (James Barash) Date: Tue, 18 Mar 2008 16:08:25 -0400 Subject: [dba-SQLServer] database mirroring problem In-Reply-To: Message-ID: <016f01c88933$d3334870$6a00a8c0@fci.local> Are you sure the server is setup for Remote Connections? This is turned off by default on a new installation and I believe it is instance specific. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Tuesday, March 18, 2008 3:30 PM To: Discussion concerning MS SQL Server Subject: [dba-SQLServer] database mirroring problem No sooner did I chime in to use database mirroring that a colleague of mine asked for help on setting his two servers. I created an instance on server B, and have disabled symantec and the windows firewall on both servers (reboot included) I made sure that both servers (all three instances are running with SP2 (sql server 2005). But I am not able to see the 2nd instance on the 2nd server for some reason. Have any of you ran into this error before? -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From markamatte at hotmail.com Tue Mar 18 15:46:01 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Tue, 18 Mar 2008 20:46:01 +0000 Subject: [dba-SQLServer] Duplicate records In-Reply-To: <016f01c88933$d3334870$6a00a8c0@fci.local> References: <016f01c88933$d3334870$6a00a8c0@fci.local> Message-ID: Hello All, I have a large table that occasionally duplicates make it into. The 2 fields that make the record unique are Case_ID and Note_Seq_Nbr. The duplicates are identical...so I have no primary key. I used the code below. It doesn't run very fast...but it does the job of removing just the extra records... Any thoughts,comments, or suggestions on making it faster/better...or a totally different approach? Thanks, Mark A. Matte **********************BEGIN************************ --By Mark A. Matte 3/18/2008 declare @CaseID decimal(15,0), at NoteNum int, at NoteCount int declare MyCursor cursor for Select case_id,note_seq_nbr,count(*) as CT from tblCaseNote_temp group by case_id,note_seq_nbr having count(*)>1 order by case_id,note_seq_nbr open mycursor fetch next from mycursor into @CaseID, at NoteNum, at NoteCount while (@@fetch_status =0) Begin delete top(@noteCount-1) from tblCaseNote_Temp where case_id=@CaseID and note_seq_nbr=@noteNum fetch next from mycursor into @CaseID, at NoteNum, at NoteCount End Close mycursor deallocate mycursor ***********************END************************* _________________________________________________________________ Need to know the score, the latest news, or you need your Hotmail?-get your "fix". http://www.msnmobilefix.com/Default.aspx From fhtapia at gmail.com Tue Mar 18 16:19:02 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 18 Mar 2008 14:19:02 -0700 Subject: [dba-SQLServer] database mirroring problem In-Reply-To: <016f01c88933$d3334870$6a00a8c0@fci.local> References: <016f01c88933$d3334870$6a00a8c0@fci.local> Message-ID: I checked the configuration (surface scan tool) and it is setup identically to server/default instance. Typically that's all I do and everything just works. This 2nd instance is not behaving as I expect. On Tue, Mar 18, 2008 at 1:08 PM, James Barash wrote: > Are you sure the server is setup for Remote Connections? This is turned > off > by default on a new installation and I believe it is instance specific. > > James Barash > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco > Tapia > Sent: Tuesday, March 18, 2008 3:30 PM > To: Discussion concerning MS SQL Server > Subject: [dba-SQLServer] database mirroring problem > > No sooner did I chime in to use database mirroring that a colleague of > mine > asked for help on setting his two servers. I created an instance on > server > B, and have disabled symantec and the windows firewall on both servers > (reboot included) I made sure that both servers (all three instances are > running with SP2 (sql server 2005). But I am not able to see the 2nd > instance on the 2nd server for some reason. > > Have any of you ran into this error before? > > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > 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 > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From fhtapia at gmail.com Tue Mar 18 16:42:07 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 18 Mar 2008 14:42:07 -0700 Subject: [dba-SQLServer] Duplicate records In-Reply-To: References: <016f01c88933$d3334870$6a00a8c0@fci.local> Message-ID: Cursors are slow, you could choose to place an index to prevent duplicates so duplicate information just never makes it into the table? On Tue, Mar 18, 2008 at 1:46 PM, Mark A Matte wrote: > > Hello All, > > I have a large table that occasionally duplicates make it into. The 2 > fields that make the record unique are Case_ID and Note_Seq_Nbr. The > duplicates are identical...so I have no primary key. I used the code below. > It doesn't run very fast...but it does the job of removing just the extra > records... > > Any thoughts,comments, or suggestions on making it faster/better...or a > totally different approach? > > Thanks, > > Mark A. Matte > > > > **********************BEGIN************************ > --By Mark A. Matte 3/18/2008 > declare @CaseID decimal(15,0), at NoteNum int, at NoteCount int > declare MyCursor cursor > for Select case_id,note_seq_nbr,count(*) as CT > from tblCaseNote_temp > group by case_id,note_seq_nbr > having count(*)>1 > order by case_id,note_seq_nbr > open mycursor > fetch next from mycursor > into @CaseID, at NoteNum, at NoteCount > while (@@fetch_status =0) > > Begin > delete top(@noteCount-1) from tblCaseNote_Temp where > case_id=@CaseID and note_seq_nbr=@noteNum > fetch next from mycursor > into @CaseID, at NoteNum, at NoteCount > End > Close mycursor > deallocate mycursor > ***********************END************************* > _________________________________________________________________ > Need to know the score, the latest news, or you need your Hotmail(R)-get > your "fix". > http://www.msnmobilefix.com/Default.aspx > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From markamatte at hotmail.com Tue Mar 18 17:32:55 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Tue, 18 Mar 2008 22:32:55 +0000 Subject: [dba-SQLServer] Duplicate records In-Reply-To: References: <016f01c88933$d3334870$6a00a8c0@fci.local> Message-ID: I get the data in a 2+gig text file...how do import without dups...I tried that first...and it just stopped the import? > Date: Tue, 18 Mar 2008 14:42:07 -0700 > From: fhtapia at gmail.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] Duplicate records > > Cursors are slow, you could choose to place an index to prevent duplicates > so duplicate information just never makes it into the table? > > > > On Tue, Mar 18, 2008 at 1:46 PM, Mark A Matte > wrote: > >> >> Hello All, >> >> I have a large table that occasionally duplicates make it into. The 2 >> fields that make the record unique are Case_ID and Note_Seq_Nbr. The >> duplicates are identical...so I have no primary key. I used the code below. >> It doesn't run very fast...but it does the job of removing just the extra >> records... >> >> Any thoughts,comments, or suggestions on making it faster/better...or a >> totally different approach? >> >> Thanks, >> >> Mark A. Matte >> >> >> >> **********************BEGIN************************ >> --By Mark A. Matte 3/18/2008 >> declare @CaseID decimal(15,0), at NoteNum int, at NoteCount int >> declare MyCursor cursor >> for Select case_id,note_seq_nbr,count(*) as CT >> from tblCaseNote_temp >> group by case_id,note_seq_nbr >> having count(*)>1 >> order by case_id,note_seq_nbr >> open mycursor >> fetch next from mycursor >> into @CaseID, at NoteNum, at NoteCount >> while (@@fetch_status =0) >> >> Begin >> delete top(@noteCount-1) from tblCaseNote_Temp where >> case_id=@CaseID and note_seq_nbr=@noteNum >> fetch next from mycursor >> into @CaseID, at NoteNum, at NoteCount >> End >> Close mycursor >> deallocate mycursor >> ***********************END************************* >> _________________________________________________________________ >> Need to know the score, the latest news, or you need your Hotmail(R)-get >> your "fix". >> http://www.msnmobilefix.com/Default.aspx >> _______________________________________________ >> dba-SQLServer mailing list >> dba-SQLServer at databaseadvisors.com >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >> http://www.databaseadvisors.com >> >> > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Shed those extra pounds with MSN and The Biggest Loser! http://biggestloser.msn.com/ From pauln at sqlserverbible.com Tue Mar 18 23:17:59 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 18 Mar 2008 22:17:59 -0600 Subject: [dba-SQLServer] Duplicate records In-Reply-To: References: <016f01c88933$d3334870$6a00a8c0@fci.local> Message-ID: <001801c88978$37edeec0$a7c9cc40$@com> I'd do the BulkINsert into a staging table then eliminate the dups as part of the cleanup. Here are two popular ways to eliminate dups... Use Tempdb drop table dups go CREATE TABLE dbo.dups ( col1 INT, col2 CHAR(5), col3 CHAR(5) ) go INSERT dbo.dups (col1, col2, col3) -- 1 VALUES (1, 'abc', 'Paul') INSERT dbo.dups (col1, col2, col3) -- 2 VALUES (1, 'abc', 'Paul') --dup INSERT dbo.dups (col1, col2, col3) -- 3 VALUES (2, 'abc', 'Paul') INSERT dbo.dups (col1, col2, col3) -- 4 VALUES (2, 'xyz', 'Sue') INSERT dbo.dups (col1, col2, col3) -- 5 VALUES (2, 'xyz', 'Sue') -- dup INSERT dbo.dups (col1, col2, col3) -- 6 VALUES (2, 'xyz', 'Sue') -- dup INSERT dbo.dups (col1, col2, col3) -- 7 VALUES (3, 'xyz', 'Sue') go -- eliminate dups - select distinct method SELECT DISTINCT * INTO nodups FROM dups SELECT * FROM nodups -- eliminate dups group by adding a pk ALTER TABLE dbo.dups ADD pk INT NOT NULL IDENTITY PRIMARY KEY -- identify dups SELECT * FROM dbo.dups WHERE PK NOT IN ( SELECT min(pk) FROM dups GROUP BY col1, col2, col3 ) -- remove dups DELETE dbo.dups WHERE PK NOT IN ( SELECT min(pk) FROM dups GROUP BY col1, col2, col3 ) SELECT * FROM dbo.dups -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark A Matte Sent: Tuesday, March 18, 2008 4:33 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Duplicate records I get the data in a 2+gig text file...how do import without dups...I tried that first...and it just stopped the import? > Date: Tue, 18 Mar 2008 14:42:07 -0700 > From: fhtapia at gmail.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] Duplicate records > > Cursors are slow, you could choose to place an index to prevent duplicates > so duplicate information just never makes it into the table? > > > > On Tue, Mar 18, 2008 at 1:46 PM, Mark A Matte > wrote: > >> >> Hello All, >> >> I have a large table that occasionally duplicates make it into. The 2 >> fields that make the record unique are Case_ID and Note_Seq_Nbr. The >> duplicates are identical...so I have no primary key. I used the code below. >> It doesn't run very fast...but it does the job of removing just the extra >> records... >> >> Any thoughts,comments, or suggestions on making it faster/better...or a >> totally different approach? >> >> Thanks, >> >> Mark A. Matte >> >> >> >> **********************BEGIN************************ >> --By Mark A. Matte 3/18/2008 >> declare @CaseID decimal(15,0), at NoteNum int, at NoteCount int >> declare MyCursor cursor >> for Select case_id,note_seq_nbr,count(*) as CT >> from tblCaseNote_temp >> group by case_id,note_seq_nbr >> having count(*)>1 >> order by case_id,note_seq_nbr >> open mycursor >> fetch next from mycursor >> into @CaseID, at NoteNum, at NoteCount >> while (@@fetch_status =0) >> >> Begin >> delete top(@noteCount-1) from tblCaseNote_Temp where >> case_id=@CaseID and note_seq_nbr=@noteNum >> fetch next from mycursor >> into @CaseID, at NoteNum, at NoteCount >> End >> Close mycursor >> deallocate mycursor >> ***********************END************************* >> _________________________________________________________________ >> Need to know the score, the latest news, or you need your Hotmail(R)-get >> your "fix". >> http://www.msnmobilefix.com/Default.aspx >> _______________________________________________ >> dba-SQLServer mailing list >> dba-SQLServer at databaseadvisors.com >> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >> http://www.databaseadvisors.com >> >> > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Shed those extra pounds with MSN and The Biggest Loser! http://biggestloser.msn.com/ _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2958 (20080318) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From markamatte at hotmail.com Wed Mar 19 09:21:22 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Wed, 19 Mar 2008 14:21:22 +0000 Subject: [dba-SQLServer] Duplicate records In-Reply-To: <001801c88978$37edeec0$a7c9cc40$@com> References: <016f01c88933$d3334870$6a00a8c0@fci.local> <001801c88978$37edeec0$a7c9cc40$@com> Message-ID: Thanks for the suggestions. I know cursors are slow...but I'm not going through every record...just the dups. Other than potential speed issues...anyone see anything that deserves caution here? I kinda like 'find them...then delete' approach Thanks, Mark A. Matte **********************BEGIN************************--By Mark A. Matte 3/18/2008declare @CaseID decimal(15,0), at NoteNum int, at NoteCount int declare MyCursor cursor for Select case_id,note_seq_nbr,count(*) as CT from tblCaseNote_temp group by case_id,note_seq_nbr having count(*)>1 order by case_id,note_seq_nbr open mycursor fetch next from mycursor into @CaseID, at NoteNum, at NoteCount while (@@fetch_status =0) Begin delete top(@noteCount-1) from tblCaseNote_Temp where case_id=@CaseID and note_seq_nbr=@noteNum fetch next from mycursor into @CaseID, at NoteNum, at NoteCount End Close mycursor deallocate mycursor ***********************END*************************> From: pauln at sqlserverbible.com> To: dba-sqlserver at databaseadvisors.com> Date: Tue, 18 Mar 2008 22:17:59 -0600> Subject: Re: [dba-SQLServer] Duplicate records> > > I'd do the BulkINsert into a staging table then eliminate the dups as part> of the cleanup.> > Here are two popular ways to eliminate dups...> > > Use Tempdb> > drop table dups> go> CREATE TABLE dbo.dups (> col1 INT,> col2 CHAR(5),> col3 CHAR(5)> )> go> INSERT dbo.dups (col1, col2, col3) -- 1> VALUES (1, 'abc', 'Paul')> INSERT dbo.dups (col1, col2, col3) -- 2> VALUES (1, 'abc', 'Paul') --dup> INSERT dbo.dups (col1, col2, col3) -- 3> VALUES (2, 'abc', 'Paul')> INSERT dbo.dups (col1, col2, col3) -- 4> VALUES (2, 'xyz', 'Sue')> INSERT dbo.dups (col1, col2, col3) -- 5> VALUES (2, 'xyz', 'Sue') -- dup> INSERT dbo.dups (col1, col2, col3) -- 6> VALUES (2, 'xyz', 'Sue') -- dup> INSERT dbo.dups (col1, col2, col3) -- 7> VALUES (3, 'xyz', 'Sue')> go> > -- eliminate dups - select distinct method> > SELECT DISTINCT *> INTO nodups> FROM dups > > SELECT * FROM nodups> > -- eliminate dups group by adding a pk> > ALTER TABLE dbo.dups> ADD pk INT NOT NULL IDENTITY PRIMARY KEY> > -- identify dups> SELECT * > FROM dbo.dups> WHERE PK NOT IN (> SELECT min(pk) > FROM dups> GROUP BY col1, col2, col3> )> > -- remove dups> DELETE dbo.dups> WHERE PK NOT IN (> SELECT min(pk) > FROM dups> GROUP BY col1, col2, col3> )> > SELECT * FROM dbo.dups> > > > > -----Original Message-----> From: dba-sqlserver-bounces at databaseadvisors.com> [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark A> Matte> Sent: Tuesday, March 18, 2008 4:33 PM> To: Discussion concerning MS SQL Server> Subject: Re: [dba-SQLServer] Duplicate records> > > I get the data in a 2+gig text file...how do import without dups...I tried> that first...and it just stopped the import?> > > > Date: Tue, 18 Mar 2008 14:42:07 -0700> > From: fhtapia at gmail.com> > To: dba-sqlserver at databaseadvisors.com> > Subject: Re: [dba-SQLServer] Duplicate records> >> > Cursors are slow, you could choose to place an index to prevent duplicates> > so duplicate information just never makes it into the table?> >> >> >> > On Tue, Mar 18, 2008 at 1:46 PM, Mark A Matte > > wrote:> >> >>> >> Hello All,> >>> >> I have a large table that occasionally duplicates make it into. The 2> >> fields that make the record unique are Case_ID and Note_Seq_Nbr. The> >> duplicates are identical...so I have no primary key. I used the code> below.> >> It doesn't run very fast...but it does the job of removing just the extra> >> records...> >>> >> Any thoughts,comments, or suggestions on making it faster/better...or a> >> totally different approach?> >>> >> Thanks,> >>> >> Mark A. Matte _________________________________________________________________ Need to know the score, the latest news, or you need your Hotmail?-get your "fix". http://www.msnmobilefix.com/Default.aspx From pauln at sqlserverbible.com Wed Mar 19 09:59:18 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 19 Mar 2008 08:59:18 -0600 Subject: [dba-SQLServer] Duplicate records In-Reply-To: References: <016f01c88933$d3334870$6a00a8c0@fci.local> <001801c88978$37edeec0$a7c9cc40$@com> Message-ID: <002401c889d1$cf442920$6dcc7b60$@com> A cursor is like going to the bank and depositing 1 million dollars, one dollar at a time, with a deposit ticket for each dollar. It not only that cursors are paaaaaainfully slow, it's that thinking about solving problems in the mindset of cursors leads to more sloppy code. Db developers think in terms of sets. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark A Matte Sent: Wednesday, March 19, 2008 8:21 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Duplicate records Thanks for the suggestions. I know cursors are slow...but I'm not going through every record...just the dups. Other than potential speed issues...anyone see anything that deserves caution here? I kinda like 'find them...then delete' approach Thanks, Mark A. Matte **********************BEGIN************************--By Mark A. Matte 3/18/2008declare @CaseID decimal(15,0), at NoteNum int, at NoteCount int declare MyCursor cursor for Select case_id,note_seq_nbr,count(*) as CT from tblCaseNote_temp group by case_id,note_seq_nbr having count(*)>1 order by case_id,note_seq_nbr open mycursor fetch next from mycursor into @CaseID, at NoteNum, at NoteCount while (@@fetch_status =0) Begin delete top(@noteCount-1) from tblCaseNote_Temp where case_id=@CaseID and note_seq_nbr=@noteNum fetch next from mycursor into @CaseID, at NoteNum, at NoteCount End Close mycursor deallocate mycursor ***********************END*************************> From: pauln at sqlserverbible.com> To: dba-sqlserver at databaseadvisors.com> Date: Tue, 18 Mar 2008 22:17:59 -0600> Subject: Re: [dba-SQLServer] Duplicate records> > > I'd do the BulkINsert into a staging table then eliminate the dups as part> of the cleanup.> > Here are two popular ways to eliminate dups...> > > Use Tempdb> > drop table dups> go> CREATE TABLE dbo.dups (> col1 INT,> col2 CHAR(5),> col3 CHAR(5)> )> go> INSERT dbo.dups (col1, col2, col3) -- 1> VALUES (1, 'abc', 'Paul')> INSERT dbo.dups (col1, col2, col3) -- 2> VALUES (1, 'abc', 'Paul') --dup> INSERT dbo.dups (col1, col2, col3) -- 3> VALUES (2, 'abc', 'Paul')> INSERT dbo.dups (col1, col2, col3) -- 4> VALUES (2, 'xyz', 'Sue')> INSERT dbo.dups (col1, col2, col3) -- 5> VALUES (2, 'xyz', 'Sue') -- dup> INSERT dbo.dups (col1, col2, col3) -- 6> VALUES (2, 'xyz', 'Sue') -- dup> INSERT dbo.dups (col1, col2, col3) -- 7> VALUES (3, 'xyz', 'Sue')> go> > -- eliminate dups - select distinct method> > SELECT DISTINCT *> INTO nodups> FROM dups > > SELECT * FROM nodups> > -- eliminate dups group by adding a pk> > ALTER TABLE dbo.dups> ADD pk INT NOT NULL IDENTITY PRIMARY KEY> > -- identify dups> SELECT * > FROM dbo.dups> WHERE PK NOT IN (> SELECT min(pk) > FROM dups> GROUP BY col1, col2, col3> )> > -- remove dups> DELETE dbo.dups> WHERE PK NOT IN (> SELECT min(pk) > FROM dups> GROUP BY col1, col2, col3> )> > SELECT * FROM dbo.dups> > > > > -----Original Message-----> From: dba-sqlserver-bounces at databaseadvisors.com> [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark A> Matte> Sent: Tuesday, March 18, 2008 4:33 PM> To: Discussion concerning MS SQL Server> Subject: Re: [dba-SQLServer] Duplicate records> > > I get the data in a 2+gig text file...how do import without dups...I tried> that first...and it just stopped the import?> > > > Date: Tue, 18 Mar 2008 14:42:07 -0700> > From: fhtapia at gmail.com> > To: dba-sqlserver at databaseadvisors.com> > Subject: Re: [dba-SQLServer] Duplicate records> >> > Cursors are slow, you could choose to place an index to prevent duplicates> > so duplicate information just never makes it into the table?> >> >> >> > On Tue, Mar 18, 2008 at 1:46 PM, Mark A Matte > > wrote:> >> >>> >> Hello All,> >>> >> I have a large table that occasionally duplicates make it into. The 2> >> fields that make the record unique are Case_ID and Note_Seq_Nbr. The> >> duplicates are identical...so I have no primary key. I used the code> below.> >> It doesn't run very fast...but it does the job of removing just the extra> >> records...> >>> >> Any thoughts,comments, or suggestions on making it faster/better...or a> >> totally different approach?> >>> >> Thanks,> >>> >> Mark A. Matte _________________________________________________________________ Need to know the score, the latest news, or you need your HotmailR-get your "fix". http://www.msnmobilefix.com/Default.aspx _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2959 (20080319) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From robert at webedb.com Wed Mar 19 15:22:13 2008 From: robert at webedb.com (Robert L. Stewart) Date: Wed, 19 Mar 2008 15:22:13 -0500 Subject: [dba-SQLServer] Duplicate records In-Reply-To: References: Message-ID: <200803192024.m2JKOjHE018748@databaseadvisors.com> Mark, As other have said, cursors are slow. After you get it cleaned up, I would put a unique index on the 2 columns so that the problem is solved permanently. Robert At 09:21 AM 3/19/2008, you wrote: >Date: Tue, 18 Mar 2008 20:46:01 +0000 >From: Mark A Matte >Subject: [dba-SQLServer] Duplicate records >To: Discussion concerning MS SQL Server > >Message-ID: >Content-Type: text/plain; charset="iso-8859-1" > > >Hello All, > >I have a large table that occasionally duplicates make it into. The >2 fields that make the record unique are Case_ID and >Note_Seq_Nbr. The duplicates are identical...so I have no primary >key. I used the code below. It doesn't run very fast...but it does >the job of removing just the extra records... > >Any thoughts,comments, or suggestions on making it >faster/better...or a totally different approach? > >Thanks, > >Mark A. Matte From markamatte at hotmail.com Wed Mar 19 15:41:22 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Wed, 19 Mar 2008 20:41:22 +0000 Subject: [dba-SQLServer] Duplicate records In-Reply-To: <200803192024.m2JKOjHE018748@databaseadvisors.com> References: <200803192024.m2JKOjHE018748@databaseadvisors.com> Message-ID: Unfortunately the data comes in with dups...I have the final table indexed...I just have to clean it before inserting. Just looking at different approaches. Thanks, Mark A. Matte > Date: Wed, 19 Mar 2008 15:22:13 -0500 > To: dba-sqlserver at databaseadvisors.com > From: robert at webedb.com > Subject: Re: [dba-SQLServer] Duplicate records > > Mark, > > As other have said, cursors are slow. > > After you get it cleaned up, I would put a unique index on the 2 columns > so that the problem is solved permanently. > > Robert > > At 09:21 AM 3/19/2008, you wrote: >>Date: Tue, 18 Mar 2008 20:46:01 +0000 >>From: Mark A Matte >>Subject: [dba-SQLServer] Duplicate records >>To: Discussion concerning MS SQL Server >> >>Message-ID: >>Content-Type: text/plain; charset="iso-8859-1" >> >> >>Hello All, >> >>I have a large table that occasionally duplicates make it into. The >>2 fields that make the record unique are Case_ID and >>Note_Seq_Nbr. The duplicates are identical...so I have no primary >>key. I used the code below. It doesn't run very fast...but it does >>the job of removing just the extra records... >> >>Any thoughts,comments, or suggestions on making it >>faster/better...or a totally different approach? >> >>Thanks, >> >>Mark A. Matte > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Climb to the top of the charts!?Play the word scramble challenge with star power. http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan From pauln at sqlserverbible.com Wed Mar 19 17:28:28 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 19 Mar 2008 16:28:28 -0600 Subject: [dba-SQLServer] Duplicate records In-Reply-To: References: <200803192024.m2JKOjHE018748@databaseadvisors.com> Message-ID: <010e01c88a10$8eb44db0$ac1ce910$@com> Hi Mark, I've done this many times. Use BulkInsert to bring the data into a staging table. Then clean it up during the move to the real tables by adding the PK and using the min(pk) method I sent earlier. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Mark A Matte Sent: Wednesday, March 19, 2008 2:41 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Duplicate records Unfortunately the data comes in with dups...I have the final table indexed...I just have to clean it before inserting. Just looking at different approaches. Thanks, Mark A. Matte > Date: Wed, 19 Mar 2008 15:22:13 -0500 > To: dba-sqlserver at databaseadvisors.com > From: robert at webedb.com > Subject: Re: [dba-SQLServer] Duplicate records > > Mark, > > As other have said, cursors are slow. > > After you get it cleaned up, I would put a unique index on the 2 columns > so that the problem is solved permanently. > > Robert > > At 09:21 AM 3/19/2008, you wrote: >>Date: Tue, 18 Mar 2008 20:46:01 +0000 >>From: Mark A Matte >>Subject: [dba-SQLServer] Duplicate records >>To: Discussion concerning MS SQL Server >> >>Message-ID: >>Content-Type: text/plain; charset="iso-8859-1" >> >> >>Hello All, >> >>I have a large table that occasionally duplicates make it into. The >>2 fields that make the record unique are Case_ID and >>Note_Seq_Nbr. The duplicates are identical...so I have no primary >>key. I used the code below. It doesn't run very fast...but it does >>the job of removing just the extra records... >> >>Any thoughts,comments, or suggestions on making it >>faster/better...or a totally different approach? >> >>Thanks, >> >>Mark A. Matte > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Climb to the top of the charts!?Play the word scramble challenge with star power. http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2960 (20080319) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Wed Mar 19 18:11:46 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 Mar 2008 19:11:46 -0400 Subject: [dba-SQLServer] Appending strings where there are nulls Message-ID: <002c01c88a16$9aebd700$0201a8c0@M90> I am trying to build up a street address from a set of fields. Any given field may have a null. If I just use + then anywhere there is a null in the source I get a null as a result. What is the syntax to append fields to build an aliased field but avoid the null issue? John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Wed Mar 19 18:28:50 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 Mar 2008 19:28:50 -0400 Subject: [dba-SQLServer] SQL Nightmares Message-ID: <002d01c88a18$fd542ee0$0201a8c0@M90> I have another (different) database from hell. This one has data fields like HOUSENUMBER StreetName StreetUnit 00000006 000012th Place As you can see, if I do a simple append, then I get something like 00000006 000012th Place. I can tell you that won't fly. So I need to strip off leading zeros, pretty much in ALL my fields, but at the very least in a fixed set of fields. How do I do this in SQL, bearing in mind that this table has 90 million records and taking a week for one field is out of the question. John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Wed Mar 19 18:30:12 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 Mar 2008 19:30:12 -0400 Subject: [dba-SQLServer] Appending strings where there are nulls In-Reply-To: <002c01c88a16$9aebd700$0201a8c0@M90> References: <002c01c88a16$9aebd700$0201a8c0@M90> Message-ID: <002e01c88a19$2e071250$0201a8c0@M90> LOL, the OhNoSecond strikes again. One answer is ISNULL(Value,'ReplacementValue'). Now whether this will work for a million records in near real time is another question. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 19, 2008 7:12 PM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Appending strings where there are nulls I am trying to build up a street address from a set of fields. Any given field may have a null. If I just use + then anywhere there is a null in the source I get a null as a result. What is the syntax to append fields to build an aliased field but avoid the null issue? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fuller.artful at gmail.com Wed Mar 19 18:31:46 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Wed, 19 Mar 2008 19:31:46 -0400 Subject: [dba-SQLServer] Appending strings where there are nulls In-Reply-To: <002c01c88a16$9aebd700$0201a8c0@M90> References: <002c01c88a16$9aebd700$0201a8c0@M90> Message-ID: <29f585dd0803191631v6983d93fl6251b218ab7e9c3b@mail.gmail.com> + Isnull({mycolumn},'') A. On 3/19/08, jwcolby wrote: > > I am trying to build up a street address from a set of fields. Any given > field may have a null. If I just use + then anywhere there is a null in > the > source I get a null as a result. > > What is the syntax to append fields to build an aliased field but avoid > the > null issue? > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fuller.artful at gmail.com Wed Mar 19 18:43:05 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Wed, 19 Mar 2008 19:43:05 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <002d01c88a18$fd542ee0$0201a8c0@M90> References: <002d01c88a18$fd542ee0$0201a8c0@M90> Message-ID: <29f585dd0803191643i15bba0f7q6c17221b3c9dd57e@mail.gmail.com> Here you go: -- ================================================ -- Template generated from Template Explorer using: -- Create Scalar Function (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Arthur Fuller -- Create date: 19-Mar-08 -- Description: Strip leading zeroes from a char value -- ============================================= CREATE FUNCTION StripZero ( -- Add the parameters for the function here @Value_str varchar(1000) ) RETURNS varchar(1000) AS BEGIN DECLARE @Result varchar(1000) SELECT @Result = Replace(@Value_str,'0','') RETURN @Result END GO -- sample call: select dbo.stripzero('000123fgh') -- returns -- 123fgh Will that do, JC? A. On 3/19/08, jwcolby wrote: > > I have another (different) database from hell. This one has data fields > like > > HOUSENUMBER StreetName StreetUnit > 00000006 000012th Place > > As you can see, if I do a simple append, then I get something like > > 00000006 000012th Place. > > I can tell you that won't fly. So I need to strip off leading zeros, > pretty > much in ALL my fields, but at the very least in a fixed set of > fields. How > do I do this in SQL, bearing in mind that this table has 90 million > records > and taking a week for one field is out of the question. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fuller.artful at gmail.com Wed Mar 19 18:45:50 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Wed, 19 Mar 2008 19:45:50 -0400 Subject: [dba-SQLServer] Appending strings where there are nulls In-Reply-To: <002e01c88a19$2e071250$0201a8c0@M90> References: <002c01c88a16$9aebd700$0201a8c0@M90> <002e01c88a19$2e071250$0201a8c0@M90> Message-ID: <29f585dd0803191645o4b28ee7ered4a56732c28adee@mail.gmail.com> I sense another article coming on... The Database From Hell, The SQL. :) A. On 3/19/08, jwcolby wrote: > > LOL, the OhNoSecond strikes again. One answer is > ISNULL(Value,'ReplacementValue'). > > Now whether this will work for a million records in near real time is > another question. > From pauln at sqlserverbible.com Wed Mar 19 18:52:55 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 19 Mar 2008 17:52:55 -0600 Subject: [dba-SQLServer] Appending strings where there are nulls In-Reply-To: <002e01c88a19$2e071250$0201a8c0@M90> References: <002c01c88a16$9aebd700$0201a8c0@M90> <002e01c88a19$2e071250$0201a8c0@M90> Message-ID: <005301c88a1c$5b2ef2e0$118cd8a0$@com> Yes, IsNull() in building strings in the output columns is very fast. Using IsNull() on a column in the where clause is slow. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 19, 2008 5:30 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Appending strings where there are nulls LOL, the OhNoSecond strikes again. One answer is ISNULL(Value,'ReplacementValue'). Now whether this will work for a million records in near real time is another question. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 19, 2008 7:12 PM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Appending strings where there are nulls I am trying to build up a street address from a set of fields. Any given field may have a null. If I just use + then anywhere there is a null in the source I get a null as a result. What is the syntax to append fields to build an aliased field but avoid the null issue? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 __________ NOD32 2960 (20080319) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Wed Mar 19 20:09:17 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 Mar 2008 21:09:17 -0400 Subject: [dba-SQLServer] Appending strings where there are nulls In-Reply-To: <29f585dd0803191645o4b28ee7ered4a56732c28adee@mail.gmail.com> References: <002c01c88a16$9aebd700$0201a8c0@M90><002e01c88a19$2e071250$0201a8c0@M90> <29f585dd0803191645o4b28ee7ered4a56732c28adee@mail.gmail.com> Message-ID: <003201c88a27$070ab900$0201a8c0@M90> >The Database From Hell, The SQL. ROTFL. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Wednesday, March 19, 2008 7:46 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Appending strings where there are nulls I sense another article coming on... The Database From Hell, The SQL. :) A. On 3/19/08, jwcolby wrote: > > LOL, the OhNoSecond strikes again. One answer is > ISNULL(Value,'ReplacementValue'). > > Now whether this will work for a million records in near real time is > another question. > _______________________________________________ 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 Mar 19 21:11:04 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 19 Mar 2008 22:11:04 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <29f585dd0803191643i15bba0f7q6c17221b3c9dd57e@mail.gmail.com> References: <002d01c88a18$fd542ee0$0201a8c0@M90> <29f585dd0803191643i15bba0f7q6c17221b3c9dd57e@mail.gmail.com> Message-ID: <003701c88a2f$a882f5b0$0201a8c0@M90> I don't know. It needs to leave the trailing zeros. IOW 000120 = 120 NOT 12 REPLACE in VB simply replaces every occurrence of a zero, not what is needed here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Wednesday, March 19, 2008 7:43 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares Here you go: -- ================================================ -- Template generated from Template Explorer using: -- Create Scalar Function (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Arthur Fuller -- Create date: 19-Mar-08 -- Description: Strip leading zeroes from a char value -- ============================================= CREATE FUNCTION StripZero ( -- Add the parameters for the function here @Value_str varchar(1000) ) RETURNS varchar(1000) AS BEGIN DECLARE @Result varchar(1000) SELECT @Result = Replace(@Value_str,'0','') RETURN @Result END GO -- sample call: select dbo.stripzero('000123fgh') -- returns -- 123fgh Will that do, JC? A. On 3/19/08, jwcolby wrote: > > I have another (different) database from hell. This one has data > fields like > > HOUSENUMBER StreetName StreetUnit > 00000006 000012th Place > > As you can see, if I do a simple append, then I get something like > > 00000006 000012th Place. > > I can tell you that won't fly. So I need to strip off leading zeros, > pretty much in ALL my fields, but at the very least in a fixed set of > fields. How do I do this in SQL, bearing in mind that this table has > 90 million records and taking a week for one field is out of the > question. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > 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 From pauln at sqlserverbible.com Wed Mar 19 22:08:17 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 19 Mar 2008 21:08:17 -0600 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <002d01c88a18$fd542ee0$0201a8c0@M90> References: <002d01c88a18$fd542ee0$0201a8c0@M90> Message-ID: <005701c88a37$a5860fc0$f0922f40$@com> Hi John, For the house number... select cast('000120' as int) for the streetname... declare @col VARCHAR(25) set @col = '00000000012st' select right(@col,len(@col)-patindex ('%[^0]%', at col)+1) -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 19, 2008 5:29 PM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] SQL Nightmares I have another (different) database from hell. This one has data fields like HOUSENUMBER StreetName StreetUnit 00000006 000012th Place As you can see, if I do a simple append, then I get something like 00000006 000012th Place. I can tell you that won't fly. So I need to strip off leading zeros, pretty much in ALL my fields, but at the very least in a fixed set of fields. How do I do this in SQL, bearing in mind that this table has 90 million records and taking a week for one field is out of the question. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2960 (20080319) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From Chris.Foote at uk.thalesgroup.com Thu Mar 20 03:12:33 2008 From: Chris.Foote at uk.thalesgroup.com (Foote, Chris) Date: Thu, 20 Mar 2008 08:12:33 -0000 Subject: [dba-SQLServer] Appending strings where there are nulls Message-ID: <7303A459C921B5499AF732CCEEAD2B7F064D1420@craws161660.int.rdel.co.uk> ROFLMAO! Nice one Arthur! Chris F > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com]On Behalf Of Arthur > Fuller > Sent: Wednesday, March 19, 2008 11:46 PM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Appending strings where there are nulls > > > I sense another article coming on... The Database From Hell, > The SQL. :) > A. From jwcolby at colbyconsulting.com Thu Mar 20 06:46:37 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 07:46:37 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <005701c88a37$a5860fc0$f0922f40$@com> References: <002d01c88a18$fd542ee0$0201a8c0@M90> <005701c88a37$a5860fc0$f0922f40$@com> Message-ID: <000701c88a80$0e3b6680$0201a8c0@M90> I really need a method of updating a field using a udf or something. That way I could tell it to run and just feed it field names to run it on. Unfortunately UDFs are something I have never done. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Wednesday, March 19, 2008 11:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] SQL Nightmares Hi John, For the house number... select cast('000120' as int) for the streetname... declare @col VARCHAR(25) set @col = '00000000012st' select right(@col,len(@col)-patindex ('%[^0]%', at col)+1) -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 19, 2008 5:29 PM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] SQL Nightmares I have another (different) database from hell. This one has data fields like HOUSENUMBER StreetName StreetUnit 00000006 000012th Place As you can see, if I do a simple append, then I get something like 00000006 000012th Place. I can tell you that won't fly. So I need to strip off leading zeros, pretty much in ALL my fields, but at the very least in a fixed set of fields. How do I do this in SQL, bearing in mind that this table has 90 million records and taking a week for one field is out of the question. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2960 (20080319) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fuller.artful at gmail.com Thu Mar 20 07:12:39 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 08:12:39 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <000701c88a80$0e3b6680$0201a8c0@M90> References: <002d01c88a18$fd542ee0$0201a8c0@M90> <005701c88a37$a5860fc0$f0922f40$@com> <000701c88a80$0e3b6680$0201a8c0@M90> Message-ID: <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> I've written quite a few UDFs, JC. I'll let you in on a little secret: templates. While you're in Management Studio, open the Template Viewer (from the View menu, or press Ctrl+Alt+T). You'll get a long list of the templates available. The one you want is the Scalar UDF (Create Scalar function from new menu) template. Double-click it and presto, you'll have the skeleton of a template. You'll see a strange-looking bunch of markers in the template( etc.). Don't bother trying to delete and replace these. Instead, from the Query menu, select Specify Values for Template Parameters. A dialog will pop up enabling you to fill in your name, creation date, name and type of the parameters, and return type of the function. Fill these in and then click OK and you're back in the templated function. It should be straightforward from here on in. The important parts are the RETURNS and SELECT lines. Put your processing instructions on the SELECT line, then assign the results to @Result or whatever you changed its name to. Typically, I add one line beneath the function body that tests it, so that I can immediately see if it worked. As soon as it does, I comment that last line out. One last thing, not of immediate relevance but for general purposes. Another item on the Functions node is for creating multi-statement table-valued functions. This template creates a table and shows how to build a Common Table Expression (CTE) then use it in a SELECT. You may not need this one right now, but you will soon enough. Recalling the old line of Picasso's. He showed Gertrude Stein his portrait of her, and she said "It doesn't look like me." Picasso replied, "It will." Arthur On 3/20/08, jwcolby wrote: > > I really need a method of updating a field using a udf or something. That > way I could tell it to run and just feed it field names to run it on. > Unfortunately UDFs are something I have never done. > > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul > Nielsen > Sent: Wednesday, March 19, 2008 11:08 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] SQL Nightmares > > > Hi John, > > For the house number... > select cast('000120' as int) > > > for the streetname... > declare @col VARCHAR(25) > set @col = '00000000012st' > select right(@col,len(@col)-patindex ('%[^0]%', at col)+1) > > -Paul > > > > > > > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Wednesday, March 19, 2008 5:29 PM > To: dba-sqlserver at databaseadvisors.com > Subject: [dba-SQLServer] SQL Nightmares > > I have another (different) database from hell. This one has data fields > like > > HOUSENUMBER StreetName StreetUnit > 00000006 000012th Place > > As you can see, if I do a simple append, then I get something like > > 00000006 000012th Place. > > I can tell you that won't fly. So I need to strip off leading zeros, > pretty > much in ALL my fields, but at the very least in a fixed set of > fields. How > do I do this in SQL, bearing in mind that this table has 90 million > records > and taking a week for one field is out of the question. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > __________ NOD32 2960 (20080319) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > > _______________________________________________ > 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 > > From jwcolby at colbyconsulting.com Thu Mar 20 07:25:06 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 08:25:06 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> References: <002d01c88a18$fd542ee0$0201a8c0@M90><005701c88a37$a5860fc0$f0922f40$@com><000701c88a80$0e3b6680$0201a8c0@M90> <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> Message-ID: <000801c88a85$6ee27f00$0201a8c0@M90> Wow, that is cool. Now for the questions: 1) Where do I store the functions? It seems like many things are useful across databases. 2) You mentioned placing a line below the function to test. I assume that you just run the function in the same manner that you would a query? Everything in the window gets executed and the one line below the function calls the function and thus returns a value? More questions to follow. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 8:13 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares I've written quite a few UDFs, JC. I'll let you in on a little secret: templates. While you're in Management Studio, open the Template Viewer (from the View menu, or press Ctrl+Alt+T). You'll get a long list of the templates available. The one you want is the Scalar UDF (Create Scalar function from new menu) template. Double-click it and presto, you'll have the skeleton of a template. You'll see a strange-looking bunch of markers in the template( etc.). Don't bother trying to delete and replace these. Instead, Name> from the Query menu, select Specify Values for Template Parameters. A dialog will pop up enabling you to fill in your name, creation date, name and type of the parameters, and return type of the function. Fill these in and then click OK and you're back in the templated function. It should be straightforward from here on in. The important parts are the RETURNS and SELECT lines. Put your processing instructions on the SELECT line, then assign the results to @Result or whatever you changed its name to. Typically, I add one line beneath the function body that tests it, so that I can immediately see if it worked. As soon as it does, I comment that last line out. One last thing, not of immediate relevance but for general purposes. Another item on the Functions node is for creating multi-statement table-valued functions. This template creates a table and shows how to build a Common Table Expression (CTE) then use it in a SELECT. You may not need this one right now, but you will soon enough. Recalling the old line of Picasso's. He showed Gertrude Stein his portrait of her, and she said "It doesn't look like me." Picasso replied, "It will." Arthur On 3/20/08, jwcolby wrote: > > I really need a method of updating a field using a udf or something. > That way I could tell it to run and just feed it field names to run it on. > Unfortunately UDFs are something I have never done. > > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com From jwcolby at colbyconsulting.com Thu Mar 20 07:42:02 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 08:42:02 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> References: <002d01c88a18$fd542ee0$0201a8c0@M90><005701c88a37$a5860fc0$f0922f40$@com><000701c88a80$0e3b6680$0201a8c0@M90> <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> Message-ID: <000901c88a87$cc9ba6b0$0201a8c0@M90> It doesn't seem to like the Right( part of the function. Right is not correctly colored. John W. Colby Colby Consulting www.ColbyConsulting.com On 3/20/08, jwcolby wrote: > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul > Nielsen > Sent: Wednesday, March 19, 2008 11:08 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] SQL Nightmares > > > Hi John, > > For the house number... > select cast('000120' as int) > > > for the streetname... > declare @col VARCHAR(25) > set @col = '00000000012st' > select right(@col,len(@col)-patindex ('%[^0]%', at col)+1) > > -Paul > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of > jwcolby > Sent: Wednesday, March 19, 2008 5:29 PM > To: dba-sqlserver at databaseadvisors.com > Subject: [dba-SQLServer] SQL Nightmares > > I have another (different) database from hell. This one has data > fields like > > HOUSENUMBER StreetName StreetUnit > 00000006 000012th Place > > As you can see, if I do a simple append, then I get something like > > 00000006 000012th Place. > > I can tell you that won't fly. So I need to strip off leading zeros, > pretty much in ALL my fields, but at the very least in a fixed set of > fields. How do I do this in SQL, bearing in mind that this table has > 90 million records and taking a week for one field is out of the > question. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com From fuller.artful at gmail.com Thu Mar 20 07:46:52 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 08:46:52 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <000801c88a85$6ee27f00$0201a8c0@M90> References: <002d01c88a18$fd542ee0$0201a8c0@M90> <005701c88a37$a5860fc0$f0922f40$@com> <000701c88a80$0e3b6680$0201a8c0@M90> <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> <000801c88a85$6ee27f00$0201a8c0@M90> Message-ID: <29f585dd0803200546v28ebfc73p1e52abb2cb1fe11c@mail.gmail.com> My last line would typically look like this, after adding the comment: -- SELECT col1, MyUDF( col2, col3) FROM someplace Now, given that you've run it once, and thus created the function, you can't comment out the line above and run the code again because you'll get an error that the function already exists. You could change the CREATE line to ALTER and re-run the code, or alternatively save the query to a text file. On my machine and probably yours, the default directory is Projects. You can create a new directory under that called GlobalFuncs or something, and save the file there. Then whenever you need to include this function in a new database, switch databases, then File | Open this text file and re-run the query. True, you can sidestep this by placing your re-usable UDFs in the master db, but this is discouraged for reasons that ought to be obvious. Far better, IMO, to save all these functions (and globally useful sprocs too) as text files, then re-run them in each db that needs them. For one thing, I'm not a big fan of touching the master under any circumstances. For another, I'm not a big fan of code that gets loaded when it may never be used. The old signal-to-noise ratio thing. Finally, there definitely are funcs and sprocs that you would want to include in every db you create. A cool way to do this is to add them to the model db, which is used as the template for each new db you create. Thus adding anything to model db means that you "inherit" it in all new dbs. hth, Arthur On 3/20/08, jwcolby wrote: > > Wow, that is cool. Now for the questions: > > 1) Where do I store the functions? It seems like many things are useful > across databases. > 2) You mentioned placing a line below the function to test. I assume that > you just run the function in the same manner that you would a query? > Everything in the window gets executed and the one line below the function > calls the function and thus returns a value? > > More questions to follow. ;-) > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur > Fuller > Sent: Thursday, March 20, 2008 8:13 AM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] SQL Nightmares > > > I've written quite a few UDFs, JC. I'll let you in on a little secret: > templates. While you're in Management Studio, open the Template Viewer > (from > the View menu, or press Ctrl+Alt+T). You'll get a long list of the > templates > available. The one you want is the Scalar UDF (Create Scalar function from > new menu) template. Double-click it and presto, you'll have the skeleton > of > a template. > > You'll see a strange-looking bunch of markers in the template( Name> etc.). Don't bother trying to delete and replace these. Instead, > > Name> from > > the Query menu, select Specify Values for Template Parameters. A dialog > will > pop up enabling you to fill in your name, creation date, name and type of > the parameters, and return type of the function. Fill these in and then > click OK and you're back in the templated function. It should be > straightforward from here on in. The important parts are the RETURNS and > SELECT lines. Put your processing instructions on the SELECT line, then > assign the results to @Result or whatever you changed its name to. > > Typically, I add one line beneath the function body that tests it, so that > I > can immediately see if it worked. As soon as it does, I comment that last > line out. > > One last thing, not of immediate relevance but for general purposes. > Another > item on the Functions node is for creating multi-statement table-valued > functions. This template creates a table and shows how to build a Common > Table Expression (CTE) then use it in a SELECT. You may not need this one > right now, but you will soon enough. > > Recalling the old line of Picasso's. He showed Gertrude Stein his portrait > of her, and she said "It doesn't look like me." Picasso replied, "It > will." > > Arthur > > On 3/20/08, jwcolby wrote: > > > > I really need a method of updating a field using a udf or something. > > That way I could tell it to run and just feed it field names to run it > on. > > Unfortunately UDFs are something I have never done. > > > > > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fuller.artful at gmail.com Thu Mar 20 07:48:36 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 08:48:36 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <000901c88a87$cc9ba6b0$0201a8c0@M90> References: <002d01c88a18$fd542ee0$0201a8c0@M90> <005701c88a37$a5860fc0$f0922f40$@com> <000701c88a80$0e3b6680$0201a8c0@M90> <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> <000901c88a87$cc9ba6b0$0201a8c0@M90> Message-ID: <29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com> I just successfully ran this: SELECT RIGHT('abcde', 3) and got back 'cde' as expected. A. On 3/20/08, jwcolby wrote: > > It doesn't seem to like the Right( part of the function. Right is not > correctly colored. > From robert at webedb.com Thu Mar 20 07:49:31 2008 From: robert at webedb.com (Robert L. Stewart) Date: Thu, 20 Mar 2008 07:49:31 -0500 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: References: Message-ID: <200803201251.m2KCpr2J026682@databaseadvisors.com> John, For those things that are a number, simply use the CONVERT function. Give me a little while today and I will send a function for things like 00012th. Robert At 07:42 AM 3/20/2008, you wrote: >Date: Wed, 19 Mar 2008 22:11:04 -0400 >From: "jwcolby" >Subject: Re: [dba-SQLServer] SQL Nightmares >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <003701c88a2f$a882f5b0$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >I don't know. It needs to leave the trailing zeros. IOW > >000120 = 120 > >NOT 12 > >REPLACE in VB simply replaces every occurrence of a zero, not what is needed >here. > >John W. Colby From jwcolby at colbyconsulting.com Thu Mar 20 07:57:13 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 08:57:13 -0400 Subject: [dba-SQLServer] Diving off the deep end Message-ID: <000a01c88a89$eb1a6f70$0201a8c0@M90> I THINK THAT WE NEED TO BACK UP A FEW STEPS. If you will be patient with me I think I can get at least a result fairly quickly but the examples given assume a knowledge that I don't have. For example, suppose I want to use the right function. In the query window (not knowing anything about what I am doing) I type in: Right("hello",2) Expecting to get back "lo" I "compile" that and immediately get back an error message: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'right'. As you can see, what we have here (to quote a certain Steve McQueen movie) is a failure to communicate. I look up right() in BOL and it shows exactly what I have typed in, but I am obviously expected to know something else. So what is it that I am expected to know? John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Thu Mar 20 08:06:31 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 09:06:31 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com> References: <002d01c88a18$fd542ee0$0201a8c0@M90><005701c88a37$a5860fc0$f0922f40$@com><000701c88a80$0e3b6680$0201a8c0@M90><29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com><000901c88a87$cc9ba6b0$0201a8c0@M90> <29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com> Message-ID: <000e01c88a8b$37c31c40$0201a8c0@M90> Ahh... SELECT... This is why I find BOL so unhelpful. The example does not show SELECT right("Hello",2) It shows Right("hello",2) An example should run, exactly as displayed. In fact, when I typed in SELECT right("Hello",2) (which is essentially what is on BOL) I then get another error message: Msg 207, Level 16, State 1, Line 1 Invalid column name 'hello'. BOL says to use ". Now when I change the " to a ' the statement works. I am sure that once I am an expert on the syntax then BOL will be highly useful. I can see that this is going to be a long morning. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 8:49 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares I just successfully ran this: SELECT RIGHT('abcde', 3) and got back 'cde' as expected. A. On 3/20/08, jwcolby wrote: > > It doesn't seem to like the Right( part of the function. Right is not > correctly colored. > _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ssharkins at gmail.com Thu Mar 20 08:09:49 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Thu, 20 Mar 2008 09:09:49 -0400 Subject: [dba-SQLServer] SQL Nightmares References: <002d01c88a18$fd542ee0$0201a8c0@M90><005701c88a37$a5860fc0$f0922f40$@com><000701c88a80$0e3b6680$0201a8c0@M90><29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com><000901c88a87$cc9ba6b0$0201a8c0@M90><29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com> <000e01c88a8b$37c31c40$0201a8c0@M90> Message-ID: <00cd01c88a8b$b334ac40$4b3a8343@SusanOne> SELECT right("Hello",2) AS TestColumn ???? Not sure John, but I use Query window to run expressions all the time, so I know that it does work. :) Susan H. From fuller.artful at gmail.com Thu Mar 20 08:14:15 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 09:14:15 -0400 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <000a01c88a89$eb1a6f70$0201a8c0@M90> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> Message-ID: <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> First problem is the double quotes, which SQL interprets as a reference to a column. Second problem is that the statement must begin with the word SELECT. After that you're good to go: SELECT Right( 'John W. Colby', 3 ) ==> 'lby' Third issue: don't compile the query. Just run it. hth, A. On 3/20/08, jwcolby wrote: > > I THINK THAT WE NEED TO BACK UP A FEW STEPS. > From jwcolby at colbyconsulting.com Thu Mar 20 08:15:53 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 09:15:53 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <00cd01c88a8b$b334ac40$4b3a8343@SusanOne> References: <002d01c88a18$fd542ee0$0201a8c0@M90><005701c88a37$a5860fc0$f0922f40$@com><000701c88a80$0e3b6680$0201a8c0@M90><29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com><000901c88a87$cc9ba6b0$0201a8c0@M90><29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com><000e01c88a8b$37c31c40$0201a8c0@M90> <00cd01c88a8b$b334ac40$4b3a8343@SusanOne> Message-ID: <000f01c88a8c$8734d420$0201a8c0@M90> I can only tell you what happens when I do something. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Thursday, March 20, 2008 9:10 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares SELECT right("Hello",2) AS TestColumn ???? Not sure John, but I use Query window to run expressions all the time, so I know that it does work. :) Susan H. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ssharkins at gmail.com Thu Mar 20 08:22:07 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Thu, 20 Mar 2008 09:22:07 -0400 Subject: [dba-SQLServer] SQL Nightmares References: <002d01c88a18$fd542ee0$0201a8c0@M90><005701c88a37$a5860fc0$f0922f40$@com><000701c88a80$0e3b6680$0201a8c0@M90><29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com><000901c88a87$cc9ba6b0$0201a8c0@M90><29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com><000e01c88a8b$37c31c40$0201a8c0@M90><00cd01c88a8b$b334ac40$4b3a8343@SusanOne> <000f01c88a8c$8734d420$0201a8c0@M90> Message-ID: <00fa01c88a8d$6c34a370$4b3a8343@SusanOne> I know -- I understand. I am continually frustrated by SQL Server. I don't use it often enough to have anything memorized and I'm constantly making mistakes that drive me nuts. My other suggestions is to change the double quotes to single quotes. I'm powering up my SQL Server system. Susan H. >I can only tell you what happens when I do something. ver] SQL Nightmares > > SELECT right("Hello",2) AS TestColumn > > ???? > > Not sure John, but I use Query window to run expressions all the time, so > I > know that it does work. :) From jwcolby at colbyconsulting.com Thu Mar 20 08:26:32 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 09:26:32 -0400 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> Message-ID: <001001c88a8e$03e97600$0201a8c0@M90> Right, figured that out. By "compile" I meant "parse". Now... CREATE FUNCTION StripLeadingZeros ( @StrToStrip varchar(200) ) RETURNS varchar(200) AS BEGIN -- Declare the return variable here DECLARE @strTemp varchar(200) -- Add the T-SQL statements to compute the return value here select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) -- Return the result of the function RETURN @strTemp END Parses correctly but returns an error: Msg 444, Level 16, State 3, Procedure StripLeadingZeros, Line 17 Select statements included within a function cannot return data to a client. So it seems that the statement: select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Needs to "return" the data to a variable. However if I modify that to: @strTemp = select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Then it no longer parses, returning: Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 Incorrect syntax near '@strTemp'. Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 Must declare the scalar variable "@strTemp". Modifying it to: @strTemp = right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Returns a parse error: Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 Incorrect syntax near '@strTemp'. Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 Must declare the scalar variable "@strTemp". I need to not only get the data out of the string, but place it in a variable and return that variable which is what I am trying to do here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 9:14 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Diving off the deep end First problem is the double quotes, which SQL interprets as a reference to a column. Second problem is that the statement must begin with the word SELECT. After that you're good to go: SELECT Right( 'John W. Colby', 3 ) ==> 'lby' Third issue: don't compile the query. Just run it. hth, A. On 3/20/08, jwcolby wrote: > > I THINK THAT WE NEED TO BACK UP A FEW STEPS. > _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fuller.artful at gmail.com Thu Mar 20 08:33:04 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 09:33:04 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <00cd01c88a8b$b334ac40$4b3a8343@SusanOne> References: <002d01c88a18$fd542ee0$0201a8c0@M90> <005701c88a37$a5860fc0$f0922f40$@com> <000701c88a80$0e3b6680$0201a8c0@M90> <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> <000901c88a87$cc9ba6b0$0201a8c0@M90> <29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com> <000e01c88a8b$37c31c40$0201a8c0@M90> <00cd01c88a8b$b334ac40$4b3a8343@SusanOne> Message-ID: <29f585dd0803200633t3cf244d8wf6682679ad27d0bd@mail.gmail.com> It's the double-quotes. All strings in SQL other than column names must be delimited with single-quotes. On 3/20/08, Susan Harkins wrote: > > SELECT right("Hello",2) AS TestColumn > > ???? > > Not sure John, but I use Query window to run expressions all the time, so > I > know that it does work. :) > > Susan H. > From fuller.artful at gmail.com Thu Mar 20 08:34:40 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 09:34:40 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <000e01c88a8b$37c31c40$0201a8c0@M90> References: <002d01c88a18$fd542ee0$0201a8c0@M90> <005701c88a37$a5860fc0$f0922f40$@com> <000701c88a80$0e3b6680$0201a8c0@M90> <29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com> <000901c88a87$cc9ba6b0$0201a8c0@M90> <29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com> <000e01c88a8b$37c31c40$0201a8c0@M90> Message-ID: <29f585dd0803200634w66e2422dha28a063852688f27@mail.gmail.com> Here is your whole function (at least as I understood the requirement). This was written using the template I mentioned earlier. -- ================================================ -- Template generated from Template Explorer using: -- Create Scalar Function (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Arthur Fuller -- Create date: 2008/03/20 -- Description: Remove leading zeroes from a string -- ============================================= CREATE FUNCTION dbo.ZeroLtrim ( -- Add the parameters for the function here @str Varchar(100) ) RETURNS Varchar(100) AS BEGIN -- Declare the return variable here DECLARE @Result Varchar(100) WHILE LEFT(@str,1) = '0' BEGIN SET @str = SUBSTRING(@str,2,LEN(@str)-1) END -- Add the T-SQL statements to compute the return value here SELECT @Result = @str -- Return the result of the function RETURN @Result END GO SELECT dbo.ZeroLTrim('0000012th Street') -- returns '12th Street' On 3/20/08, jwcolby wrote: > > Ahh... SELECT... > > This is why I find BOL so unhelpful. The example does not show > > SELECT right("Hello",2) > > It shows > > Right("hello",2) > > An example should run, exactly as displayed. > > In fact, when I typed in > > SELECT right("Hello",2) (which is essentially what is on BOL) I then get > another error message: > > Msg 207, Level 16, State 1, Line 1 > Invalid column name 'hello'. > > BOL says to use ". Now when I change the " to a ' the statement works. > > I am sure that once I am an expert on the syntax then BOL will be highly > useful. > > I can see that this is going to be a long morning. > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur > Fuller > > Sent: Thursday, March 20, 2008 8:49 AM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] SQL Nightmares > > > I just successfully ran this: > > SELECT RIGHT('abcde', 3) > and got back 'cde' as expected. > > A. > > On 3/20/08, jwcolby wrote: > > > > It doesn't seem to like the Right( part of the function. Right is not > > correctly colored. > > > > _______________________________________________ > 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 > > From ssharkins at gmail.com Thu Mar 20 08:40:03 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Thu, 20 Mar 2008 09:40:03 -0400 Subject: [dba-SQLServer] SQL Nightmares References: <002d01c88a18$fd542ee0$0201a8c0@M90><005701c88a37$a5860fc0$f0922f40$@com><000701c88a80$0e3b6680$0201a8c0@M90><29f585dd0803200512g442b80cch717e47f94bcb0519@mail.gmail.com><000901c88a87$cc9ba6b0$0201a8c0@M90><29f585dd0803200548j730bfef2ic7c702e63d0aeafb@mail.gmail.com><000e01c88a8b$37c31c40$0201a8c0@M90><00cd01c88a8b$b334ac40$4b3a8343@SusanOne> <29f585dd0803200633t3cf244d8wf6682679ad27d0bd@mail.gmail.com> Message-ID: <011d01c88a8f$ea32e6e0$4b3a8343@SusanOne> Yeah, I saw that and suggested he change them -- my fault because I'm so stuck in VBA and it always takes me a while to adjust when I change. Sorry about that JC. Susan H. > It's the double-quotes. All strings in SQL other than column names must be > delimited with single-quotes. From pauln at sqlserverbible.com Thu Mar 20 08:54:50 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 07:54:50 -0600 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <001001c88a8e$03e97600$0201a8c0@M90> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> <001001c88a8e$03e97600$0201a8c0@M90> Message-ID: <017901c88a91$f8679c90$e936d5b0$@com> Keep it simple. you don't need to create a function for updating from a this parsing, just put the expression in your select/update statement. Update table1 Set col1 = right(t2.col2,len(t2.col2)-patindex('%[^0]%', t2.col2)+1) from table1 t1 join table2 t2 on t1.pk = t2.pk - Paul www.sqlserverbible.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 20, 2008 7:27 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end Right, figured that out. By "compile" I meant "parse". Now... CREATE FUNCTION StripLeadingZeros ( @StrToStrip varchar(200) ) RETURNS varchar(200) AS BEGIN -- Declare the return variable here DECLARE @strTemp varchar(200) -- Add the T-SQL statements to compute the return value here select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) -- Return the result of the function RETURN @strTemp END Parses correctly but returns an error: Msg 444, Level 16, State 3, Procedure StripLeadingZeros, Line 17 Select statements included within a function cannot return data to a client. So it seems that the statement: select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Needs to "return" the data to a variable. However if I modify that to: @strTemp = select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Then it no longer parses, returning: Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 Incorrect syntax near '@strTemp'. Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 Must declare the scalar variable "@strTemp". Modifying it to: @strTemp = right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Returns a parse error: Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 Incorrect syntax near '@strTemp'. Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 Must declare the scalar variable "@strTemp". I need to not only get the data out of the string, but place it in a variable and return that variable which is what I am trying to do here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 9:14 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Diving off the deep end First problem is the double quotes, which SQL interprets as a reference to a column. Second problem is that the statement must begin with the word SELECT. After that you're good to go: SELECT Right( 'John W. Colby', 3 ) ==> 'lby' Third issue: don't compile the query. Just run it. hth, A. On 3/20/08, jwcolby wrote: > > I THINK THAT WE NEED TO BACK UP A FEW STEPS. > _______________________________________________ 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 __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fuller.artful at gmail.com Thu Mar 20 09:04:30 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 10:04:30 -0400 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <001001c88a8e$03e97600$0201a8c0@M90> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> <001001c88a8e$03e97600$0201a8c0@M90> Message-ID: <29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> When assigning to a variable you must begin the statement with either SET @VAR = 'ABC' or SELECT @var = 'abc'. A. From robert at webedb.com Thu Mar 20 09:16:34 2008 From: robert at webedb.com (Robert L. Stewart) Date: Thu, 20 Mar 2008 09:16:34 -0500 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: References: Message-ID: <200803201417.m2KEH6rV020732@databaseadvisors.com> John, Try this: CREATE FUNCTION StripLeadingZeros ( @StrToStrip varchar(200) ) RETURNS varchar(200) AS BEGIN -- Declare the return variable here DECLARE @strTemp varchar(200) -- Add the T-SQL statements to compute the return value here set @strTemp = right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) -- Return the result of the function RETURN @strTemp END Robert At 08:26 AM 3/20/2008, you wrote: >Date: Thu, 20 Mar 2008 09:26:32 -0400 >From: "jwcolby" >Subject: Re: [dba-SQLServer] Diving off the deep end >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <001001c88a8e$03e97600$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >Right, figured that out. By "compile" I meant "parse". > >Now... > >CREATE FUNCTION StripLeadingZeros >( >@StrToStrip varchar(200) >) >RETURNS varchar(200) >AS >BEGIN > -- Declare the return variable here > DECLARE @strTemp varchar(200) > > -- Add the T-SQL statements to compute the return value here > select right(@StrToStrip,len(@StrToStrip)-patindex >('%[^0]%', at StrToStrip)+1) > -- Return the result of the function > RETURN @strTemp > >END > >Parses correctly but returns an error: > >Msg 444, Level 16, State 3, Procedure StripLeadingZeros, Line 17 >Select statements included within a function cannot return data to a client. > >So it seems that the statement: > > select right(@StrToStrip,len(@StrToStrip)-patindex >('%[^0]%', at StrToStrip)+1) > >Needs to "return" the data to a variable. However if I modify that to: > > @strTemp = select right(@StrToStrip,len(@StrToStrip)-patindex >('%[^0]%', at StrToStrip)+1) > >Then it no longer parses, returning: > >Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 >Incorrect syntax near '@strTemp'. >Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 >Must declare the scalar variable "@strTemp". > >Modifying it to: > > @strTemp = right(@StrToStrip,len(@StrToStrip)-patindex >('%[^0]%', at StrToStrip)+1) > >Returns a parse error: > >Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 >Incorrect syntax near '@strTemp'. >Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 >Must declare the scalar variable "@strTemp". > >I need to not only get the data out of the string, but place it in a >variable and return that variable which is what I am trying to do here. > >John W. Colby From jwcolby at colbyconsulting.com Thu Mar 20 09:18:58 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 10:18:58 -0400 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <017901c88a91$f8679c90$e936d5b0$@com> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com><001001c88a8e$03e97600$0201a8c0@M90> <017901c88a91$f8679c90$e936d5b0$@com> Message-ID: <001a01c88a95$56d048b0$0201a8c0@M90> We have ignition. I want a function for a couple of reasons, first because I want to be able to do this in row after row, in table after table. I want to be able to build update queries that can just call the function etc. I am there, at least for this one function. Thanks for your help. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 9:55 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end Keep it simple. you don't need to create a function for updating from a this parsing, just put the expression in your select/update statement. Update table1 Set col1 = right(t2.col2,len(t2.col2)-patindex('%[^0]%', t2.col2)+1) from table1 t1 join table2 t2 on t1.pk = t2.pk - Paul www.sqlserverbible.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 20, 2008 7:27 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end Right, figured that out. By "compile" I meant "parse". Now... CREATE FUNCTION StripLeadingZeros ( @StrToStrip varchar(200) ) RETURNS varchar(200) AS BEGIN -- Declare the return variable here DECLARE @strTemp varchar(200) -- Add the T-SQL statements to compute the return value here select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) -- Return the result of the function RETURN @strTemp END Parses correctly but returns an error: Msg 444, Level 16, State 3, Procedure StripLeadingZeros, Line 17 Select statements included within a function cannot return data to a client. So it seems that the statement: select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Needs to "return" the data to a variable. However if I modify that to: @strTemp = select right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Then it no longer parses, returning: Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 Incorrect syntax near '@strTemp'. Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 Must declare the scalar variable "@strTemp". Modifying it to: @strTemp = right(@StrToStrip,len(@StrToStrip)-patindex ('%[^0]%', at StrToStrip)+1) Returns a parse error: Msg 102, Level 15, State 1, Procedure StripLeadingZeros, Line 18 Incorrect syntax near '@strTemp'. Msg 137, Level 15, State 2, Procedure StripLeadingZeros, Line 20 Must declare the scalar variable "@strTemp". I need to not only get the data out of the string, but place it in a variable and return that variable which is what I am trying to do here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 9:14 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Diving off the deep end First problem is the double quotes, which SQL interprets as a reference to a column. Second problem is that the statement must begin with the word SELECT. After that you're good to go: SELECT Right( 'John W. Colby', 3 ) ==> 'lby' Third issue: don't compile the query. Just run it. hth, A. On 3/20/08, jwcolby wrote: > > I THINK THAT WE NEED TO BACK UP A FEW STEPS. > _______________________________________________ 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 __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 Mar 20 09:19:40 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 10:19:40 -0400 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> References: <000a01c88a89$eb1a6f70$0201a8c0@M90><29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com><001001c88a8e$03e97600$0201a8c0@M90> <29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> Message-ID: <001b01c88a95$6ff58260$0201a8c0@M90> That was the key. I have a working function. Now to build a working update query. Thanks for your help. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 10:05 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Diving off the deep end When assigning to a variable you must begin the statement with either SET @VAR = 'ABC' or SELECT @var = 'abc'. A. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From adtp at airtelmail.in Thu Mar 20 10:43:02 2008 From: adtp at airtelmail.in (A.D.Tejpal) Date: Thu, 20 Mar 2008 21:13:02 +0530 Subject: [dba-SQLServer] SQL Nightmares References: <002d01c88a18$fd542ee0$0201a8c0@M90><29f585dd0803191643i15bba0f7q6c17221b3c9dd57e@mail.gmail.com> <003701c88a2f$a882f5b0$0201a8c0@M90> Message-ID: <009f01c88aa1$60552660$3b57a27a@personald6374f> John, In access desktop, the following expression will strip leading zeros from a digital string, leaving the trailing zeroes intact (HouseNum is the text type field carrying the string to be processed): Mid([HouseNum],(InStr([HouseNum],Replace([HouseNum],"0","")))) Sample SQL for displaying the stripped values (as HNum) along with the original ones, would be as follows (T_JC is the name of data table): ====================================== SELECT T_JC.HouseNum, Mid([HouseNum],(InStr([HouseNum],Replace([HouseNum],"0","")))) AS HNum FROM T_JC; ====================================== Typical results: --------------- HouseNum HNum 00001200 1200 00000123000 123000 Best wishes, A.D.Tejpal ------------ ----- Original Message ----- From: jwcolby To: 'Discussion concerning MS SQL Server' Sent: Thursday, March 20, 2008 07:41 Subject: Re: [dba-SQLServer] SQL Nightmares I don't know. It needs to leave the trailing zeros. IOW 000120 = 120 NOT 12 REPLACE in VB simply replaces every occurrence of a zero, not what is needed here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Wednesday, March 19, 2008 7:43 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares Here you go: -- ================================================ -- Template generated from Template Explorer using: -- Create Scalar Function (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Arthur Fuller -- Create date: 19-Mar-08 -- Description: Strip leading zeroes from a char value -- ============================================= CREATE FUNCTION StripZero ( -- Add the parameters for the function here @Value_str varchar(1000) ) RETURNS varchar(1000) AS BEGIN DECLARE @Result varchar(1000) SELECT @Result = Replace(@Value_str,'0','') RETURN @Result END GO -- sample call: select dbo.stripzero('000123fgh') -- returns -- 123fgh Will that do, JC? A. On 3/19/08, jwcolby wrote: > > I have another (different) database from hell. This one has data > fields like > > HOUSENUMBER StreetName StreetUnit > 00000006 000012th Place > > As you can see, if I do a simple append, then I get something like > > 00000006 000012th Place. > > I can tell you that won't fly. So I need to strip off leading zeros, > pretty much in ALL my fields, but at the very least in a fixed set of > fields. How do I do this in SQL, bearing in mind that this table has > 90 million records and taking a week for one field is out of the > question. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com From pauln at sqlserverbible.com Thu Mar 20 10:51:12 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 09:51:12 -0600 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> <001001c88a8e$03e97600$0201a8c0@M90> <29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> Message-ID: <01df01c88aa2$39be7fa0$ad3b7ee0$@com> Just to clarify, if the statement accesses a data source (has a from clause) use select, if not use set. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 8:05 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Diving off the deep end When assigning to a variable you must begin the statement with either SET @VAR = 'ABC' or SELECT @var = 'abc'. A. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Thu Mar 20 10:57:35 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 09:57:35 -0600 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <009f01c88aa1$60552660$3b57a27a@personald6374f> References: <002d01c88a18$fd542ee0$0201a8c0@M90><29f585dd0803191643i15bba0f7q6c17221b3c9dd57e@mail.gmail.com> <003701c88a2f$a882f5b0$0201a8c0@M90> <009f01c88aa1$60552660$3b57a27a@personald6374f> Message-ID: <01e901c88aa3$1dd96d30$598c4790$@com> Just curious, why use Access for this function when the data is already in SQL Server? -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of A.D.Tejpal Sent: Thursday, March 20, 2008 9:43 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares John, In access desktop, the following expression will strip leading zeros from a digital string, leaving the trailing zeroes intact (HouseNum is the text type field carrying the string to be processed): Mid([HouseNum],(InStr([HouseNum],Replace([HouseNum],"0","")))) Sample SQL for displaying the stripped values (as HNum) along with the original ones, would be as follows (T_JC is the name of data table): ====================================== SELECT T_JC.HouseNum, Mid([HouseNum],(InStr([HouseNum],Replace([HouseNum],"0","")))) AS HNum FROM T_JC; ====================================== Typical results: --------------- HouseNum HNum 00001200 1200 00000123000 123000 Best wishes, A.D.Tejpal ------------ ----- Original Message ----- From: jwcolby To: 'Discussion concerning MS SQL Server' Sent: Thursday, March 20, 2008 07:41 Subject: Re: [dba-SQLServer] SQL Nightmares I don't know. It needs to leave the trailing zeros. IOW 000120 = 120 NOT 12 REPLACE in VB simply replaces every occurrence of a zero, not what is needed here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Wednesday, March 19, 2008 7:43 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares Here you go: -- ================================================ -- Template generated from Template Explorer using: -- Create Scalar Function (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Arthur Fuller -- Create date: 19-Mar-08 -- Description: Strip leading zeroes from a char value -- ============================================= CREATE FUNCTION StripZero ( -- Add the parameters for the function here @Value_str varchar(1000) ) RETURNS varchar(1000) AS BEGIN DECLARE @Result varchar(1000) SELECT @Result = Replace(@Value_str,'0','') RETURN @Result END GO -- sample call: select dbo.stripzero('000123fgh') -- returns -- 123fgh Will that do, JC? A. On 3/19/08, jwcolby wrote: > > I have another (different) database from hell. This one has data > fields like > > HOUSENUMBER StreetName StreetUnit > 00000006 000012th Place > > As you can see, if I do a simple append, then I get something like > > 00000006 000012th Place. > > I can tell you that won't fly. So I need to strip off leading zeros, > pretty much in ALL my fields, but at the very least in a fixed set of > fields. How do I do this in SQL, bearing in mind that this table has > 90 million records and taking a week for one field is out of the > question. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Thu Mar 20 11:10:47 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 12:10:47 -0400 Subject: [dba-SQLServer] SQL Nightmares In-Reply-To: <009f01c88aa1$60552660$3b57a27a@personald6374f> References: <002d01c88a18$fd542ee0$0201a8c0@M90><29f585dd0803191643i15bba0f7q6c17221b3c9dd57e@mail.gmail.com><003701c88a2f$a882f5b0$0201a8c0@M90> <009f01c88aa1$60552660$3b57a27a@personald6374f> Message-ID: <002d01c88aa4$f60bd7a0$0201a8c0@M90> Thanks A.D. I try not to use Access for these databases simply because they contain so many records. VBA is interpreted and running stuff on 90 million records would just overwhelm Access' capabilities I think. I am doing this straight in SQL Server 2005 and UDFs. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of A.D.Tejpal Sent: Thursday, March 20, 2008 11:43 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares John, In access desktop, the following expression will strip leading zeros from a digital string, leaving the trailing zeroes intact (HouseNum is the text type field carrying the string to be processed): Mid([HouseNum],(InStr([HouseNum],Replace([HouseNum],"0","")))) Sample SQL for displaying the stripped values (as HNum) along with the original ones, would be as follows (T_JC is the name of data table): ====================================== SELECT T_JC.HouseNum, Mid([HouseNum],(InStr([HouseNum],Replace([HouseNum],"0","")))) AS HNum FROM T_JC; ====================================== Typical results: --------------- HouseNum HNum 00001200 1200 00000123000 123000 Best wishes, A.D.Tejpal ------------ ----- Original Message ----- From: jwcolby To: 'Discussion concerning MS SQL Server' Sent: Thursday, March 20, 2008 07:41 Subject: Re: [dba-SQLServer] SQL Nightmares I don't know. It needs to leave the trailing zeros. IOW 000120 = 120 NOT 12 REPLACE in VB simply replaces every occurrence of a zero, not what is needed here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Wednesday, March 19, 2008 7:43 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL Nightmares Here you go: -- ================================================ -- Template generated from Template Explorer using: -- Create Scalar Function (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Arthur Fuller -- Create date: 19-Mar-08 -- Description: Strip leading zeroes from a char value -- ============================================= CREATE FUNCTION StripZero ( -- Add the parameters for the function here @Value_str varchar(1000) ) RETURNS varchar(1000) AS BEGIN DECLARE @Result varchar(1000) SELECT @Result = Replace(@Value_str,'0','') RETURN @Result END GO -- sample call: select dbo.stripzero('000123fgh') -- returns -- 123fgh Will that do, JC? A. On 3/19/08, jwcolby wrote: > > I have another (different) database from hell. This one has data > fields like > > HOUSENUMBER StreetName StreetUnit > 00000006 000012th Place > > As you can see, if I do a simple append, then I get something like > > 00000006 000012th Place. > > I can tell you that won't fly. So I need to strip off leading zeros, > pretty much in ALL my fields, but at the very least in a fixed set of > fields. How do I do this in SQL, bearing in mind that this table has > 90 million records and taking a week for one field is out of the > question. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com _______________________________________________ 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 Mar 20 11:14:26 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 12:14:26 -0400 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <01df01c88aa2$39be7fa0$ad3b7ee0$@com> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> <001001c88a8e$03e97600$0201a8c0@M90><29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> <01df01c88aa2$39be7fa0$ad3b7ee0$@com> Message-ID: <002e01c88aa5$78e35360$0201a8c0@M90> I'm getting there. I now have a query running stripping the leading zeros from three fields that I will then need to append together to get a single address field. So much of this stuff is easy enough if you do it all the time. My problem is that I am just spread too thin. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 11:51 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end Just to clarify, if the statement accesses a data source (has a from clause) use select, if not use set. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 8:05 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Diving off the deep end When assigning to a variable you must begin the statement with either SET @VAR = 'ABC' or SELECT @var = 'abc'. A. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 Mar 20 11:14:52 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 12:14:52 -0400 Subject: [dba-SQLServer] StripLeadingZeros - timing Message-ID: <002f01c88aa5$884f8990$0201a8c0@M90> I just rebuilt the stored procedure in the database that I needed to run it in. That at least got my update query running. It took 38 seconds to do just one column, the first million records. Only 91 million more to go. John W. Colby Colby Consulting www.ColbyConsulting.com From pauln at sqlserverbible.com Thu Mar 20 11:24:39 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 10:24:39 -0600 Subject: [dba-SQLServer] StripLeadingZeros - timing In-Reply-To: <002f01c88aa5$884f8990$0201a8c0@M90> References: <002f01c88aa5$884f8990$0201a8c0@M90> Message-ID: <021201c88aa6$e64588a0$b2d099e0$@com> I'm curious to hear if it makes any difference it the parsing expression is in a function, or right in the update statement. Typically scalar functions used in the columns has very little overhead (compared to table valued functions that pass the data back via tempdb) -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 20, 2008 10:15 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] StripLeadingZeros - timing I just rebuilt the stored procedure in the database that I needed to run it in. That at least got my update query running. It took 38 seconds to do just one column, the first million records. Only 91 million more to go. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Thu Mar 20 11:29:39 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 10:29:39 -0600 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <002e01c88aa5$78e35360$0201a8c0@M90> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> <001001c88a8e$03e97600$0201a8c0@M90><29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> <01df01c88aa2$39be7fa0$ad3b7ee0$@com> <002e01c88aa5$78e35360$0201a8c0@M90> Message-ID: <021301c88aa7$98e14210$caa3c630$@com> You can strip, concatenate, and update all in one query IN the airline reservation system, in one query I pivoted the 200 incoming comma delimited flights into a table using a UDF, left joined with the existing flight cache, parsed the flight data, calculated the number of legs in the flight and inserted the result into a table variable. In SQL Server it's generally better to do as much as possible in as few set-based operations as possible. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 20, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end I'm getting there. I now have a query running stripping the leading zeros from three fields that I will then need to append together to get a single address field. So much of this stuff is easy enough if you do it all the time. My problem is that I am just spread too thin. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 11:51 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end Just to clarify, if the statement accesses a data source (has a from clause) use select, if not use set. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 8:05 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Diving off the deep end When assigning to a variable you must begin the statement with either SET @VAR = 'ABC' or SELECT @var = 'abc'. A. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2963 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Thu Mar 20 11:38:27 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 12:38:27 -0400 Subject: [dba-SQLServer] Diving off the deep end In-Reply-To: <021301c88aa7$98e14210$caa3c630$@com> References: <000a01c88a89$eb1a6f70$0201a8c0@M90> <29f585dd0803200614w562586e6scfb3b01a6a711cf4@mail.gmail.com> <001001c88a8e$03e97600$0201a8c0@M90><29f585dd0803200704s6d1c1ba3s3a7a5490b5f657e2@mail.gmail.com> <01df01c88aa2$39be7fa0$ad3b7ee0$@com><002e01c88aa5$78e35360$0201a8c0@M90> <021301c88aa7$98e14210$caa3c630$@com> Message-ID: <003101c88aa8$d3938b60$0201a8c0@M90> >You can strip, concatenate, and update all in one query Yea, I suppose. I wanted to clean up the fields themselves, and given how little I really know I thought it best to just do the data cleanup in one step, then build a new column and do the append in a second step. I could be here all day trying to get anything more complex that this done "all in one step". Besides, I really need to take the time to learn the pieces. Thanks to everyone who has helped out this morning. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 12:30 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end You can strip, concatenate, and update all in one query IN the airline reservation system, in one query I pivoted the 200 incoming comma delimited flights into a table using a UDF, left joined with the existing flight cache, parsed the flight data, calculated the number of legs in the flight and inserted the result into a table variable. In SQL Server it's generally better to do as much as possible in as few set-based operations as possible. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 20, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Diving off the deep end I'm getting there. I now have a query running stripping the leading zeros from three fields that I will then need to append together to get a single address field. So much of this stuff is easy enough if you do it all the time. My problem is that I am just spread too thin. John W. Colby Colby Consulting www.ColbyConsulting.com From accessd at shaw.ca Thu Mar 20 13:40:10 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 20 Mar 2008 11:40:10 -0700 Subject: [dba-SQLServer] Rocky's new Book In-Reply-To: References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> Message-ID: Hi All: Rocky has a new book on how to develop an application into a product. See description and link on the DBA web site at http://www.DatabaseAdvisors.com and/or link to Apress books at http://www.apress.com/book/view/1590599713 Jim From ssharkins at gmail.com Thu Mar 20 13:40:41 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Thu, 20 Mar 2008 14:40:41 -0400 Subject: [dba-SQLServer] Rocky's new Book References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> Message-ID: <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> The content's bleeding over "box" borders in both FireFox and IE -- anyone seeing this? Susan H. > Hi All: > > Rocky has a new book on how to develop an application into a product. See > description and link on the DBA web site at > http://www.DatabaseAdvisors.com From garykjos at gmail.com Thu Mar 20 13:52:58 2008 From: garykjos at gmail.com (Gary Kjos) Date: Thu, 20 Mar 2008 13:52:58 -0500 Subject: [dba-SQLServer] Rocky's new Book In-Reply-To: <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> Message-ID: No, looks OK to me in FF at least. On Thu, Mar 20, 2008 at 1:40 PM, Susan Harkins wrote: > The content's bleeding over "box" borders in both FireFox and IE -- anyone > seeing this? > > > Susan H. > > > > > Hi All: > > > > Rocky has a new book on how to develop an application into a product. See > > description and link on the DBA web site at > > http://www.DatabaseAdvisors.com > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- Gary Kjos garykjos at gmail.com From pauln at sqlserverbible.com Thu Mar 20 13:58:50 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 12:58:50 -0600 Subject: [dba-SQLServer] Rocky's new Book In-Reply-To: References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> Message-ID: <02aa01c88abc$703cd9e0$50b68da0$@com> Ordered. And I recommend "Eric Sink on the Business of Software" as well. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Thursday, March 20, 2008 12:40 PM To: 'Access Developers discussion and problem solving'; dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Rocky's new Book Hi All: Rocky has a new book on how to develop an application into a product. See description and link on the DBA web site at http://www.DatabaseAdvisors.com and/or link to Apress books at http://www.apress.com/book/view/1590599713 Jim _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2964 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Thu Mar 20 14:05:16 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 13:05:16 -0600 Subject: [dba-SQLServer] Rocky's new Book In-Reply-To: <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> Message-ID: <02ab01c88abd$564d07c0$02e71740$@com> Yes, if the width is too narrow, the text bleeds out the bottom of the box. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Thursday, March 20, 2008 12:41 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Rocky's new Book The content's bleeding over "box" borders in both FireFox and IE -- anyone seeing this? Susan H. > Hi All: > > Rocky has a new book on how to develop an application into a product. See > description and link on the DBA web site at > http://www.DatabaseAdvisors.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2964 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From mwp.reid at qub.ac.uk Thu Mar 20 14:05:50 2008 From: mwp.reid at qub.ac.uk (Martin W Reid) Date: Thu, 20 Mar 2008 19:05:50 +0000 Subject: [dba-SQLServer] Rocky's new Book In-Reply-To: <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> , <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> Message-ID: Fine here on IE7 Martin Martin WP Reid Information Services Queen's University Riddel Hall 185 Stranmillis Road Belfast BT9 5EE Tel : 02890974465 Email : mwp.reid at qub.ac.uk ________________________________________ From: dba-sqlserver-bounces at databaseadvisors.com [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins [ssharkins at gmail.com] Sent: 20 March 2008 18:40 To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Rocky's new Book The content's bleeding over "box" borders in both FireFox and IE -- anyone seeing this? Susan H. > Hi All: > > Rocky has a new book on how to develop an application into a product. See > description and link on the DBA web site at > 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 fuller.artful at gmail.com Thu Mar 20 16:03:53 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 16:03:53 -0500 Subject: [dba-SQLServer] Rocky's new Book In-Reply-To: References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> Message-ID: <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> Congratulations, Rocky! May wads of filthy lucre infest your bank account. A. From pauln at sqlserverbible.com Thu Mar 20 16:37:27 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 15:37:27 -0600 Subject: [dba-SQLServer] Access limitations In-Reply-To: <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> Message-ID: <037201c88ad2$98eb45a0$cac1d0e0$@com> As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul From jwcolby at colbyconsulting.com Thu Mar 20 20:22:33 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 20 Mar 2008 21:22:33 -0400 Subject: [dba-SQLServer] Access limitations In-Reply-To: <037201c88ad2$98eb45a0$cac1d0e0$@com> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> Message-ID: <005301c88af2$0be317d0$0201a8c0@M90> I have a database with about a gig of data. However I broke it down into several back ends because it is subject to corruptions and having it broken down allows compacting / repairing just the corrupted be. I have about 25-40 users in it every day. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 5:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fuller.artful at gmail.com Thu Mar 20 22:38:52 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 22:38:52 -0500 Subject: [dba-SQLServer] Access limitations In-Reply-To: <005301c88af2$0be317d0$0201a8c0@M90> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> <005301c88af2$0be317d0$0201a8c0@M90> Message-ID: <29f585dd0803202038i19468c78xee94c48897b05371@mail.gmail.com> I think that I was one of the earliest adopters of the ADP approach, which lets you talk directly to SQL Server from Access. In that scenario, all that lives in Access are the forms and reports. So you get the best of both worlds -- RAD in Access and performance and scalability in SQL Server. In the biggest such app I did, I had over 70 simultaneous users hitting a SQL db that was about 3.5 gigs. In a test scenario, I had an Access ADP hitting a 20 gig db with no issues. A. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 5:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ 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 From pauln at sqlserverbible.com Thu Mar 20 22:54:20 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 21:54:20 -0600 Subject: [dba-SQLServer] Access limitations In-Reply-To: <29f585dd0803202038i19468c78xee94c48897b05371@mail.gmail.com> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> <005301c88af2$0be317d0$0201a8c0@M90> <29f585dd0803202038i19468c78xee94c48897b05371@mail.gmail.com> Message-ID: <006601c88b07$3f3eeea0$bdbccbe0$@com> Hi Arthur, I agree ADP is great. But it's a front-end to SQL Server so you're really testing SQL Server (which regularly handles multi-terabyte databases and thousands of concurrent connections), not the Jet Engine. I'm wondering how far you can push the Jet engine. In your use of ADP, did you use a database abstraction layer in SQL Server (all procs all the time)? Or ad-hoc SQL? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 9:39 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Access limitations I think that I was one of the earliest adopters of the ADP approach, which lets you talk directly to SQL Server from Access. In that scenario, all that lives in Access are the forms and reports. So you get the best of both worlds -- RAD in Access and performance and scalability in SQL Server. In the biggest such app I did, I had over 70 simultaneous users hitting a SQL db that was about 3.5 gigs. In a test scenario, I had an Access ADP hitting a 20 gig db with no issues. A. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 5:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2965 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fuller.artful at gmail.com Thu Mar 20 23:07:52 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 23:07:52 -0500 Subject: [dba-SQLServer] Access limitations In-Reply-To: <006601c88b07$3f3eeea0$bdbccbe0$@com> References: <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> <005301c88af2$0be317d0$0201a8c0@M90> <29f585dd0803202038i19468c78xee94c48897b05371@mail.gmail.com> <006601c88b07$3f3eeea0$bdbccbe0$@com> Message-ID: <29f585dd0803202107t759f657ble35cf6e2c4107bd5@mail.gmail.com> Sprocs and Views and UDFs all the time. No dynamic SQL ever. Whenever I hear those words, I reach for my Glock :) Admittedly, there are very rare occasions when dynamic SQL is the only way to go, but those occasions are extremely rare. More often than not, it's used because people either don't know how to program TSQL or because they haven't been shown how easy SQL injection is. A. On 3/20/08, Paul Nielsen wrote: > > Hi Arthur, > > I agree ADP is great. But it's a front-end to SQL Server so you're really > testing SQL Server (which regularly handles multi-terabyte databases and > thousands of concurrent connections), not the Jet Engine. I'm wondering > how > far you can push the Jet engine. > > In your use of ADP, did you use a database abstraction layer in SQL Server > (all procs all the time)? Or ad-hoc SQL? > > -Paul > From accessd at shaw.ca Thu Mar 20 23:16:48 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 20 Mar 2008 21:16:48 -0700 Subject: [dba-SQLServer] Access limitations In-Reply-To: <037201c88ad2$98eb45a0$cac1d0e0$@com> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> Message-ID: Paul: If you use a combination of Access FE, ADO-OLE and a nice SQL server as a BE, a couple hundred users with 100,000 rows is not a stretch. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 2:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pauln at sqlserverbible.com Thu Mar 20 23:17:54 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Thu, 20 Mar 2008 22:17:54 -0600 Subject: [dba-SQLServer] Access limitations In-Reply-To: References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> Message-ID: <001e01c88b0a$89c286a0$9d4793e0$@com> Sure, but like I just told Arthur, that's not Access, that's SQL Server with a front-end. I've pushed SQL Server to several thousand users and hundreds of millions of rows in Tb+ databases (at 35K tps). But that doesn't test Access. My question is how far can you safely push Access with just the jet engine? It is interesting though that the answers keep coming back as Access+SQL server. Is that due to the demographics of this group, or is the Access developer community moving beyond Access as a BE? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Thursday, March 20, 2008 10:17 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Access limitations Paul: If you use a combination of Access FE, ADO-OLE and a nice SQL server as a BE, a couple hundred users with 100,000 rows is not a stretch. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 2:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ 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 __________ NOD32 2965 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From accessd at shaw.ca Thu Mar 20 23:28:24 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 20 Mar 2008 21:28:24 -0700 Subject: [dba-SQLServer] Access limitations In-Reply-To: <006601c88b07$3f3eeea0$bdbccbe0$@com> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> <005301c88af2$0be317d0$0201a8c0@M90> <29f585dd0803202038i19468c78xee94c48897b05371@mail.gmail.com> <006601c88b07$3f3eeea0$bdbccbe0$@com> Message-ID: Hi Paul: The Jet-Engine is fine but it is very limited (2 GB maximum) for the data usage. Near the maximum size limits thing start to fall apart. The last couple of Access apps I have put together I just dropped MDB and replace it with SQL Express/ADO-OLE. (MySQL and PostgreSQL are other excellent choices.) Once had a Access DB with one MS SQL DB and 2 Oracle DBs attached... try that with anything else... up and running in a couple of hours) Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 8:54 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Access limitations Hi Arthur, I agree ADP is great. But it's a front-end to SQL Server so you're really testing SQL Server (which regularly handles multi-terabyte databases and thousands of concurrent connections), not the Jet Engine. I'm wondering how far you can push the Jet engine. In your use of ADP, did you use a database abstraction layer in SQL Server (all procs all the time)? Or ad-hoc SQL? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 9:39 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Access limitations I think that I was one of the earliest adopters of the ADP approach, which lets you talk directly to SQL Server from Access. In that scenario, all that lives in Access are the forms and reports. So you get the best of both worlds -- RAD in Access and performance and scalability in SQL Server. In the biggest such app I did, I had over 70 simultaneous users hitting a SQL db that was about 3.5 gigs. In a test scenario, I had an Access ADP hitting a 20 gig db with no issues. A. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 5:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2965 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.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 Thu Mar 20 23:30:44 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 20 Mar 2008 21:30:44 -0700 Subject: [dba-SQLServer] Access limitations In-Reply-To: <29f585dd0803202107t759f657ble35cf6e2c4107bd5@mail.gmail.com> References: <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> <005301c88af2$0be317d0$0201a8c0@M90> <29f585dd0803202038i19468c78xee94c48897b05371@mail.gmail.com> <006601c88b07$3f3eeea0$bdbccbe0$@com> <29f585dd0803202107t759f657ble35cf6e2c4107bd5@mail.gmail.com> Message-ID: Beside of the obvious ability for a site to be hacked that use dynamic SQL, the performance hit can be dramatic as many non-compiled SQL chucks are having to be managed. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Thursday, March 20, 2008 9:08 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Access limitations Sprocs and Views and UDFs all the time. No dynamic SQL ever. Whenever I hear those words, I reach for my Glock :) Admittedly, there are very rare occasions when dynamic SQL is the only way to go, but those occasions are extremely rare. More often than not, it's used because people either don't know how to program TSQL or because they haven't been shown how easy SQL injection is. A. On 3/20/08, Paul Nielsen wrote: > > Hi Arthur, > > I agree ADP is great. But it's a front-end to SQL Server so you're really > testing SQL Server (which regularly handles multi-terabyte databases and > thousands of concurrent connections), not the Jet Engine. I'm wondering > how > far you can push the Jet engine. > > In your use of ADP, did you use a database abstraction layer in SQL Server > (all procs all the time)? Or ad-hoc SQL? > > -Paul > _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fuller.artful at gmail.com Thu Mar 20 23:30:47 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Thu, 20 Mar 2008 23:30:47 -0500 Subject: [dba-SQLServer] Access limitations In-Reply-To: References: <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> <005301c88af2$0be317d0$0201a8c0@M90> <29f585dd0803202038i19468c78xee94c48897b05371@mail.gmail.com> <006601c88b07$3f3eeea0$bdbccbe0$@com> <29f585dd0803202107t759f657ble35cf6e2c4107bd5@mail.gmail.com> Message-ID: <29f585dd0803202130s3cd2d1b6k1f4f235d00e473ab@mail.gmail.com> I don't think any of my MDB apps ever cracked the 1GB size, so I leave that to others. I did get close to that size, but you could say I cheated because I used replication, with a replica on each local PC and the main replica on a server, and fairly rapid syncrhonizations. The big advantage this approach gave me was almost no network traffic, at least as compared to the traffic incurred by populating listboxes and combo boxes from a server-located BE. There were a couple of hundred tables but obviously only a few of them were hit frequently, and the traffic between locals and the main MDB was reduced to a few KB per syncrhonization -- peanuts compared to the traditional FE/BE setup. A. On 3/20/08, Jim Lawrence wrote: > > Beside of the obvious ability for a site to be hacked that use dynamic > SQL, > the performance hit can be dramatic as many non-compiled SQL chucks are > having to be managed. > > Jim > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur > Fuller > Sent: Thursday, March 20, 2008 9:08 PM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Access limitations > > Sprocs and Views and UDFs all the time. No dynamic SQL ever. Whenever I > hear > those words, I reach for my Glock :) Admittedly, there are very rare > occasions when dynamic SQL is the only way to go, but those occasions are > extremely rare. More often than not, it's used because people either don't > know how to program TSQL or because they haven't been shown how easy SQL > injection is. > > A. > > > On 3/20/08, Paul Nielsen wrote: > > > > Hi Arthur, > > > > I agree ADP is great. But it's a front-end to SQL Server so you're > really > > testing SQL Server (which regularly handles multi-terabyte databases and > > thousands of concurrent connections), not the Jet Engine. I'm wondering > > how > > far you can push the Jet engine. > > > > In your use of ADP, did you use a database abstraction layer in SQL > Server > > (all procs all the time)? Or ad-hoc SQL? > > > > -Paul > > > _______________________________________________ > 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 > > From Gustav at cactus.dk Fri Mar 21 04:33:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 21 Mar 2008 10:33:08 +0100 Subject: [dba-SQLServer] Access limitations Message-ID: Hi Paul That depends. Which is no answer ... Problem is, I guess, that no one pushes it that far. You can without doubt have 255 well-behaved users reading from one 1 GB mdb file, but in real life users are not well-behaved, workstations when counted in hundreds fail from time to time, and hardly no database is for reading only. Writing, indeed updating, slows things down. In the scenarios we've experienced, when you have a user count of a dozen or so your client does run some kind of business and the costs to set up a database server are not prohibiting in any way; a tiny standard entry level server will do and you can use MySQL or the like if the license fee must be zero or SQL Server 2005 Express if no single database is large. Even if you can get away running a shared JET file, backup of this can cause trouble. Users do not always close down workstations or may be working around the clock. You cannot reliably perform a backup of the mdb file while users are attaching it. This single topic may end the discussion with the client. /gustav >>> pauln at sqlserverbible.com 21-03-2008 05:17 >>> Sure, but like I just told Arthur, that's not Access, that's SQL Server with a front-end. I've pushed SQL Server to several thousand users and hundreds of millions of rows in Tb+ databases (at 35K tps). But that doesn't test Access. My question is how far can you safely push Access with just the jet engine? It is interesting though that the answers keep coming back as Access+SQL server. Is that due to the demographics of this group, or is the Access developer community moving beyond Access as a BE? -Paul From jwcolby at colbyconsulting.com Fri Mar 21 08:13:44 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 21 Mar 2008 09:13:44 -0400 Subject: [dba-SQLServer] Access limitations In-Reply-To: <037201c88ad2$98eb45a0$cac1d0e0$@com> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> Message-ID: <000c01c88b55$652c1d10$0201a8c0@M90> One problem with Access as a front end is that it is very easy to do things that are illegal in SQL Server, such as referencing form controls directly in the SQL, referencing VBA functions (and your own functions) directly in the SQL etc. The JET engine handles that but of course it "understands" Access. Trying to MOVE one of those kinds of apps to SQL Server can be very time consuming. I program "to the metal" and though I never reference controls and forms directly anymore, my apps do a lot of stuff that doesn't port easily. Also, using SQL Server efficiently via bound forms and controls using SQL Server was difficult before Office 2002. If you are able to start with Access and SQL Server (or express) on a new project you can take Access much farther than is otherwise possible. JET has some rather severe problems including almost useless row level locking, memos causing corruption, indexes causing page locking and the like. And yet it is also fast and easy to use, at least for the first gig of data and 25 users. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 5:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ 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 Fri Mar 21 12:52:12 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Fri, 21 Mar 2008 10:52:12 -0700 Subject: [dba-SQLServer] Access limitations In-Reply-To: <001e01c88b0a$89c286a0$9d4793e0$@com> References: <0F978DF74B416B44A351B9143EB0FD33046E3F54@MUKPBCC1XMB0103.collab.barclayscorp.com> <02cc01c88ab9$f2432a50$4b3a8343@SusanOne> <29f585dd0803201403n6e54aed9w88754ee8febef82a@mail.gmail.com> <037201c88ad2$98eb45a0$cac1d0e0$@com> <001e01c88b0a$89c286a0$9d4793e0$@com> Message-ID: <75E23368E7804E6DB026F9F070507463@creativesystemdesigns.com> Hi Paul: Just a couple of GB and that is it. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 9:18 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Access limitations Sure, but like I just told Arthur, that's not Access, that's SQL Server with a front-end. I've pushed SQL Server to several thousand users and hundreds of millions of rows in Tb+ databases (at 35K tps). But that doesn't test Access. My question is how far can you safely push Access with just the jet engine? It is interesting though that the answers keep coming back as Access+SQL server. Is that due to the demographics of this group, or is the Access developer community moving beyond Access as a BE? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Thursday, March 20, 2008 10:17 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Access limitations Paul: If you use a combination of Access FE, ADO-OLE and a nice SQL server as a BE, a couple hundred users with 100,000 rows is not a stretch. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Thursday, March 20, 2008 2:37 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Access limitations As a SQL Server only guy, I'm unfamiliar with how far you can scale Access today and still expect it to behave well and be stable. But this group might know. How large can an Access database become before you begin to feel nervous? And how many concurrent users? Assume you have great hardware and a networking infrastructure. -Paul _______________________________________________ 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 __________ NOD32 2965 (20080320) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 Sat Mar 22 22:57:14 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sat, 22 Mar 2008 23:57:14 -0400 Subject: [dba-SQLServer] Throw away your db servers... Message-ID: <002001c88c99$fb265f20$0201a8c0@M90> http://www.sqlsummit.com/Articles/UltraSPARC_RC.htm John W. Colby Colby Consulting www.ColbyConsulting.com From accessd at shaw.ca Sun Mar 23 00:08:52 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sat, 22 Mar 2008 22:08:52 -0700 Subject: [dba-SQLServer] Throw away your db servers... In-Reply-To: <002001c88c99$fb265f20$0201a8c0@M90> References: <002001c88c99$fb265f20$0201a8c0@M90> Message-ID: Hi John: Are there any free samples? Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Saturday, March 22, 2008 8:57 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Throw away your db servers... http://www.sqlsummit.com/Articles/UltraSPARC_RC.htm John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 Sun Mar 23 22:05:11 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sun, 23 Mar 2008 23:05:11 -0400 Subject: [dba-SQLServer] Throw away your db servers... In-Reply-To: References: <002001c88c99$fb265f20$0201a8c0@M90> Message-ID: <000a01c88d5b$e01c23a0$0201a8c0@M90> ROTFL. Seems unlikely. My guess is that is vaporware at this point. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Sunday, March 23, 2008 1:09 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Throw away your db servers... Hi John: Are there any free samples? Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Saturday, March 22, 2008 8:57 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Throw away your db servers... http://www.sqlsummit.com/Articles/UltraSPARC_RC.htm John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 From jwcolby at colbyconsulting.com Mon Mar 24 09:36:32 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 10:36:32 -0400 Subject: [dba-SQLServer] SQL to create Integer Random Message-ID: <002201c88dbc$74c0ce60$0201a8c0@M90> I need to create a field that is an integer, and which is then filled with a random number when the rows are populated. In Access you could set up an autonumber with random. Is it possible to do something like this in SQL Server? If now can I do a function in an aliased field, where that random number is then inserted into the integer field? John W. Colby Colby Consulting www.ColbyConsulting.com From pauln at sqlserverbible.com Mon Mar 24 09:51:46 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Mon, 24 Mar 2008 10:51:46 -0400 Subject: [dba-SQLServer] SQL to create Integer Random In-Reply-To: <002201c88dbc$74c0ce60$0201a8c0@M90> References: <002201c88dbc$74c0ce60$0201a8c0@M90> Message-ID: <001201c88dbe$971f9070$c55eb150$@com> John, It is important that random number for the row is permanent? Or is the intention that you're able to randomly select row? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 24, 2008 10:37 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] SQL to create Integer Random I need to create a field that is an integer, and which is then filled with a random number when the rows are populated. In Access you could set up an autonumber with random. Is it possible to do something like this in SQL Server? If now can I do a function in an aliased field, where that random number is then inserted into the integer field? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2968 (20080324) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fuller.artful at gmail.com Mon Mar 24 09:54:25 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 24 Mar 2008 10:54:25 -0400 Subject: [dba-SQLServer] SQL to create Integer Random In-Reply-To: <002201c88dbc$74c0ce60$0201a8c0@M90> References: <002201c88dbc$74c0ce60$0201a8c0@M90> Message-ID: <29f585dd0803240754pe9f982y2a3e900f268c4c42@mail.gmail.com> I'm not sure why you want it inserted, but if you just want ordering there is an easy way. Order By RowID(). You could physically insert that too if you wanted. A. From pauln at sqlserverbible.com Mon Mar 24 10:10:30 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Mon, 24 Mar 2008 11:10:30 -0400 Subject: [dba-SQLServer] SQL to create Integer Random In-Reply-To: <29f585dd0803240754pe9f982y2a3e900f268c4c42@mail.gmail.com> References: <002201c88dbc$74c0ce60$0201a8c0@M90> <29f585dd0803240754pe9f982y2a3e900f268c4c42@mail.gmail.com> Message-ID: <003401c88dc1$35cef7e0$a16ce7a0$@com> 2 points, IN a transaction, I've seen SQL Server generate just one newid() and insert the same value into every row. When selecting random rwos (a common usage of newid()), it's good to combine the order by newid() with a tablesample option. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Monday, March 24, 2008 10:54 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL to create Integer Random I'm not sure why you want it inserted, but if you just want ordering there is an easy way. Order By RowID(). You could physically insert that too if you wanted. A. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2968 (20080324) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From robert at webedb.com Mon Mar 24 10:12:10 2008 From: robert at webedb.com (Robert L. Stewart) Date: Mon, 24 Mar 2008 10:12:10 -0500 Subject: [dba-SQLServer] Access limitations In-Reply-To: References: Message-ID: <200803241517.m2OFH5C5023851@databaseadvisors.com> Paul, Personally, 100 meg is the limit I have defined. If it got that big, I moved it to the MSDE. Now, I do not use Jet for a database at all. I stick strictly with SQL 2005 of some flavor. Robert At 11:30 PM 3/20/2008, you wrote: >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul >Nielsen >Sent: Thursday, March 20, 2008 5:37 PM >To: 'Discussion concerning MS SQL Server' >Subject: [dba-SQLServer] Access limitations > >As a SQL Server only guy, I'm unfamiliar with how far you can scale Access >today and still expect it to behave well and be stable. But this group might >know. How large can an Access database become before you begin to feel >nervous? And how many concurrent users? Assume you have great hardware and a >networking infrastructure. > >-Paul From jwcolby at colbyconsulting.com Mon Mar 24 10:55:43 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 11:55:43 -0400 Subject: [dba-SQLServer] SQL to create Integer Random In-Reply-To: <001201c88dbe$971f9070$c55eb150$@com> References: <002201c88dbc$74c0ce60$0201a8c0@M90> <001201c88dbe$971f9070$c55eb150$@com> Message-ID: <002c01c88dc7$8c053920$0201a8c0@M90> It has to be permanent random number. I have to select the top N records but they have to be random records within the table. I also have to date stamp the records selected to indicate that they have been selected and on which date. The way I normally attack this is to create a random int field and a SelectedDate field, and populate the random int field. I then update the top N date field (sorted by random int field where date = null). I then select those with today's data and ship them out, but ordered by Zip / +4. Mailing label orders. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Monday, March 24, 2008 10:52 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] SQL to create Integer Random John, It is important that random number for the row is permanent? Or is the intention that you're able to randomly select row? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 24, 2008 10:37 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] SQL to create Integer Random I need to create a field that is an integer, and which is then filled with a random number when the rows are populated. In Access you could set up an autonumber with random. Is it possible to do something like this in SQL Server? If now can I do a function in an aliased field, where that random number is then inserted into the integer field? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2968 (20080324) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fuller.artful at gmail.com Mon Mar 24 14:28:21 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 24 Mar 2008 15:28:21 -0400 Subject: [dba-SQLServer] SQL to create Integer Random In-Reply-To: <002c01c88dc7$8c053920$0201a8c0@M90> References: <002201c88dbc$74c0ce60$0201a8c0@M90> <001201c88dbe$971f9070$c55eb150$@com> <002c01c88dc7$8c053920$0201a8c0@M90> Message-ID: <29f585dd0803241228q4d0d5ec3te6173f332ef51819@mail.gmail.com> Create a column of data type uniqueidentifier and give it the default NewID(). That should do it. A. On Mon, Mar 24, 2008 at 11:55 AM, jwcolby wrote: > It has to be permanent random number. I have to select the top N records > but they have to be random records within the table. I also have to date > stamp the records selected to indicate that they have been selected and on > which date. > > The way I normally attack this is to create a random int field and a > SelectedDate field, and populate the random int field. I then update the > top N date field (sorted by random int field where date = null). I then > select those with today's data and ship them out, but ordered by Zip / +4. > > Mailing label orders. > > > From jwcolby at colbyconsulting.com Mon Mar 24 14:58:35 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 15:58:35 -0400 Subject: [dba-SQLServer] SQL to create Integer Random In-Reply-To: <29f585dd0803241228q4d0d5ec3te6173f332ef51819@mail.gmail.com> References: <002201c88dbc$74c0ce60$0201a8c0@M90><001201c88dbe$971f9070$c55eb150$@com><002c01c88dc7$8c053920$0201a8c0@M90> <29f585dd0803241228q4d0d5ec3te6173f332ef51819@mail.gmail.com> Message-ID: <004701c88de9$72454da0$0201a8c0@M90> Exactly right. You have to perform two casts() to make it happen though. I will post the exact syntaxt as soon as I am finished with the order. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Monday, March 24, 2008 3:28 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] SQL to create Integer Random Create a column of data type uniqueidentifier and give it the default NewID(). That should do it. A. On Mon, Mar 24, 2008 at 11:55 AM, jwcolby wrote: > It has to be permanent random number. I have to select the top N > records but they have to be random records within the table. I also > have to date stamp the records selected to indicate that they have > been selected and on which date. > > The way I normally attack this is to create a random int field and a > SelectedDate field, and populate the random int field. I then update > the top N date field (sorted by random int field where date = null). > I then select those with today's data and ship them out, but ordered by Zip / +4. > > Mailing label orders. > > > _______________________________________________ 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 Mon Mar 24 15:21:54 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 16:21:54 -0400 Subject: [dba-SQLServer] Storing sql in database and other stuff Message-ID: <005401c88dec$b3dea3d0$0201a8c0@M90> Guys, here is the deal. I have a sequence of steps which need to be performed in an rather exact order to get an order filled. These steps include running a bunch of action queries in a specific order. At the moment I have built the queries and have them stored in a directory but I KNOW that somehow I actually saved the queries inside of my database one time. I think maybe I saved them as stored procedures though I am not sure. So, I need to figure out how to save the queries inside of my database, then I need to build a stored procedure to run all of these queries (or stored procedures?) in order. If I can accomplish that then building an order will drop to an hour instead many hours. So, how do I store the queries inside of a database? John W. Colby Colby Consulting www.ColbyConsulting.com From markamatte at hotmail.com Mon Mar 24 15:39:59 2008 From: markamatte at hotmail.com (Mark A Matte) Date: Mon, 24 Mar 2008 20:39:59 +0000 Subject: [dba-SQLServer] Storing sql in database and other stuff In-Reply-To: <005401c88dec$b3dea3d0$0201a8c0@M90> References: <005401c88dec$b3dea3d0$0201a8c0@M90> Message-ID: John, I did something similar...I need to run over 100 queries, in order...and did not want to have to do it individually. A number of people fussed about 'dynamic' SQl statements...but what I did was store the 'where clause' of my statements in a table...Pulled them in with query analyzer using a cursor...looped through each one and passed it to a stored procedure that built the rest of my SQl statement...then executed it. Saved a lot of time this way. I'd be interested in any faster solutions. I used the char(34) in the SP...because I had single quotes in some of my criteria. Hope it helps, Mark A. Matte ********CALL SP********** declare @ID nvarchar(255) declare MyCursor cursor for select CriteriaSQL from tblcriteria where requestname = 'MyName' open mycursor fetch next from mycursor into @ID while (@@fetch_status =0) Begin exec Select_Records_1 @ID fetch next from mycursor into @ID End Close mycursor deallocate mycursor ********End SP********** ********Start SP********** CREATE PROCEDURE [Select_Records_1] @ID nvarchar(255) AS declare @sql as varchar(1000) declare @ID2 as nvarchar(255) declare @nsql as nchar(3000) select @ID2=replace(replace(@ID,nchar(34),"x"),nchar(37),"x") set @sql='insert into tblFrontWash_ID(case_id, Criteria) SELECT case_id, ' + char(34) + at ID2 + char(34) + ' from tblCase where creation_date between ' + char(34) + '1/1/2006' + char(34) +' and ' + char(34) +'11/1/2007' + char(34) +' and ' + at ID set @nsql=@sql set nocount on exec sp_executesql @nsql set nocount off ********End SP********** > From: jwcolby at colbyconsulting.com > To: dba-sqlserver at databaseadvisors.com > Date: Mon, 24 Mar 2008 16:21:54 -0400 > Subject: [dba-SQLServer] Storing sql in database and other stuff > > Guys, here is the deal. > > I have a sequence of steps which need to be performed in an rather exact > order to get an order filled. These steps include running a bunch of action > queries in a specific order. At the moment I have built the queries and > have them stored in a directory but I KNOW that somehow I actually saved the > queries inside of my database one time. I think maybe I saved them as > stored procedures though I am not sure. > > So, I need to figure out how to save the queries inside of my database, then > I need to build a stored procedure to run all of these queries (or stored > procedures?) in order. If I can accomplish that then building an order will > drop to an hour instead many hours. > > So, how do I store the queries inside of a database? > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > _________________________________________________________________ Test your Star IQ http://club.live.com/red_carpet_reveal.aspx?icid=redcarpet_HMTAGMAR From jwcolby at colbyconsulting.com Mon Mar 24 16:27:26 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 17:27:26 -0400 Subject: [dba-SQLServer] Stringing USPs together Message-ID: <005901c88df5$dbd74000$0201a8c0@M90> I am building a bunch of user stored procedures, which will eventually be strung together in another usp. However in order to do this I need to have the USP ask me a question or two, like the name of the database. Or is there a variable that gives me the name of the database that the usp is in? If I need to get variables into a usp how do I do so? By that I mean how do I get the USP to ask me a question and accept my answer and store it to a variable? John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Mon Mar 24 16:45:14 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 17:45:14 -0400 Subject: [dba-SQLServer] I want one (but wouldn't know how to use it) Message-ID: <005a01c88df8$58ab8260$0201a8c0@M90> I just ran across this. Imports a terabyte in an hour. http://blogs.msdn.com/sqlcat/archive/2006/05/19/602142.aspx Couldn't afford it either obviously. John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Mon Mar 24 17:17:17 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 18:17:17 -0400 Subject: [dba-SQLServer] Returning a dataset Message-ID: <005b01c88dfc$d280f1c0$0201a8c0@M90> A stored procedure can return a data set correct? Is that data set updateable? I need to run a stored procedure, where I pass in the Value for the TOP N (the N part) and then build up a SQL statement and execute that inside of the sp. That sp needs to return the data set to another SP, and that SP has to update a field in the data set returned by the first sp. Is this possible? ATM I have a view called TopN, which returns a date field. I have a query that updates that date field to today's date. The problem is that the TopN view is hard coded with a number (30000 for today's order) but that value could be any number. So I need to turn the view into a SP where I can pass in the number of records to update and then pass the set up date fields back to an update SP to do the update. John W. Colby Colby Consulting www.ColbyConsulting.com From fahooper at trapo.com Mon Mar 24 17:39:50 2008 From: fahooper at trapo.com (Fred Hooper) Date: Mon, 24 Mar 2008 18:39:50 -0400 Subject: [dba-SQLServer] Storing sql in database and other stuff In-Reply-To: <005401c88dec$b3dea3d0$0201a8c0@M90> Message-ID: <000801c88dff$f8f19d20$a917c048@fred6998b25045> A stored procedure can have a large number of queries. I recently created five that replaced 400 Access queries. E.g. Update foo Set fld1 = 2; Update foo2 Set fld1 = 3 Where fld2=1; Etc. They will run in the order you type them. You can also use if statements if some alternatives are needed. I used If Month(GetDate()) = 11 then Begin Series of statements to process a new budget End; -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 24, 2008 4:22 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Storing sql in database and other stuff Guys, here is the deal. I have a sequence of steps which need to be performed in an rather exact order to get an order filled. These steps include running a bunch of action queries in a specific order. At the moment I have built the queries and have them stored in a directory but I KNOW that somehow I actually saved the queries inside of my database one time. I think maybe I saved them as stored procedures though I am not sure. So, I need to figure out how to save the queries inside of my database, then I need to build a stored procedure to run all of these queries (or stored procedures?) in order. If I can accomplish that then building an order will drop to an hour instead many hours. So, how do I store the queries inside of a database? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fahooper at trapo.com Mon Mar 24 17:48:48 2008 From: fahooper at trapo.com (Fred Hooper) Date: Mon, 24 Mar 2008 18:48:48 -0400 Subject: [dba-SQLServer] Stringing USPs together In-Reply-To: <005901c88df5$dbd74000$0201a8c0@M90> Message-ID: <000901c88e01$394cb8e0$a917c048@fred6998b25045> You create the stored procedure with an input parameter. Then, when you call the sp you provide the parameter. E.g. Exec sp_process_a_database DatabaseName The "DatabaseName" is assigned to the parameter and then processed. Unfortunately, that parameter can't be used for a field, table or database, as this information is needed to optimize the execution plan. So if you want to use it for one of these you'll need to use dynamic sql, which is just a different container than a DoCmd.RunSql, because it can't do anything with an execution plan. If you're just using the sp for different databases, don't fully specify tables and you can create the same sp in different databases. Fred -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 24, 2008 5:27 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Stringing USPs together I am building a bunch of user stored procedures, which will eventually be strung together in another usp. However in order to do this I need to have the USP ask me a question or two, like the name of the database. Or is there a variable that gives me the name of the database that the usp is in? If I need to get variables into a usp how do I do so? By that I mean how do I get the USP to ask me a question and accept my answer and store it to a variable? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 Mon Mar 24 19:19:58 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 24 Mar 2008 20:19:58 -0400 Subject: [dba-SQLServer] Stringing USPs together In-Reply-To: <000901c88e01$394cb8e0$a917c048@fred6998b25045> References: <005901c88df5$dbd74000$0201a8c0@M90> <000901c88e01$394cb8e0$a917c048@fred6998b25045> Message-ID: <005c01c88e0d$f65fc650$0201a8c0@M90> Most of the queries I need to run are one liners. Make table. Make table. Append table. Update field. Update field. SELECT data. There are a couple of areas that need input though. For example I need to import data from a csv file. If the data comes in then continue else. I could hard code the path but I would rather not. The full procedure is: . Create an order directory in the path PSM\Orders\ using the order number as the directory name. . Copy the order spreadsheet to the directory . Copy the count workbook to the order directory . Copy the order page into the count workbook . Copy the Count database with all of its views for counting and building the order, named to the PSM order number. . Check for and build indexes on any fields in tblHSID used in WHERE clauses that do not have one already. . Create views which reference the tables used for the order, for example HSID and ZipCodeWorld (automatically done now with the count database) o vHSID - HSID selection data fields o vAZHSID - HSID Accuzipped o vZCWZipsUsed - Zip Code World zips used (no prisons, military etc) . Create the individual where clause views and test. Often the queries use WHERE clauses with many different fields including age bands, income bands and then other individual fields such as skiing or dogs or boats etc. . Join all of the individual selection queries by PK to create the big selection criteria query, pulling PK for use later. . Create a ZipCodeWorld query if we will be narrowing by zips, CBSA etc. pulling just the zip to join to the select query. . Output to Accuzip . Input from Accuzip. Name table "tblOrderRaw" . Create tblOrder with the same structure as tblOrderRaw . Add HashAddr field, varbinary(200) . Add DateUsed field, DateTime . Add RandomNum field, Integer (random) . Copy all valid records to tblOrder. DPV='YN' and DPVNotes = 'AABB'. Delete PO boxes and blank addresses. Cleans up after Accuzip process. . Update HashAddr field in tblOrder with update query . Run dedup query on tblOrder. This dedupes the data. . Create vOrderSortByRandomNum. This provides the random selection. . Create vOrderNewTopN in the SQL database based on the vOrderSortByRandomNum. This selects the top N records not already marked as used. . Copy qUpdOrderNewTopN - Selects a Top(N) number of records and marks them as used . Copy Access database to order directory . Modify to point to the current database in sql server. This Access database is used only for creating the flat file export and will go away when the export out of SQL Server is up and running. . Export using the export spec in Access Even in this document, some steps are still several steps in one. And of course some of this stuff just isn't a good candidate for SQL Server to do (make directories, copy files to subdirectories, insert pages in spreadsheets etc. And of course this isn't one big automateable process, sometimes I have to go modify views in the middle. Stuff like that. But if I can get the last 1/2 automated I will be miles ahead of where I am now. The processes after "Input from Accuzip" is pretty much all automateable in one big script. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Fred Hooper Sent: Monday, March 24, 2008 6:49 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Stringing USPs together You create the stored procedure with an input parameter. Then, when you call the sp you provide the parameter. E.g. Exec sp_process_a_database DatabaseName The "DatabaseName" is assigned to the parameter and then processed. Unfortunately, that parameter can't be used for a field, table or database, as this information is needed to optimize the execution plan. So if you want to use it for one of these you'll need to use dynamic sql, which is just a different container than a DoCmd.RunSql, because it can't do anything with an execution plan. If you're just using the sp for different databases, don't fully specify tables and you can create the same sp in different databases. Fred From fuller.artful at gmail.com Tue Mar 25 05:24:23 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Tue, 25 Mar 2008 06:24:23 -0400 Subject: [dba-SQLServer] I want one (but wouldn't know how to use it) In-Reply-To: <005a01c88df8$58ab8260$0201a8c0@M90> References: <005a01c88df8$58ab8260$0201a8c0@M90> Message-ID: <29f585dd0803250324y46e52e19r2895c0667773a7d0@mail.gmail.com> I can't afford it either. :) On 3/24/08, jwcolby wrote: > > I just ran across this. Imports a terabyte in an hour. > > http://blogs.msdn.com/sqlcat/archive/2006/05/19/602142.aspx > > Couldn't afford it either obviously. > From fuller.artful at gmail.com Tue Mar 25 05:41:03 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Tue, 25 Mar 2008 06:41:03 -0400 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: <005b01c88dfc$d280f1c0$0201a8c0@M90> References: <005b01c88dfc$d280f1c0$0201a8c0@M90> Message-ID: <29f585dd0803250341u3ac0906eo23fb5e3b3c8ef9f8@mail.gmail.com> Depends what you mean by data set. Result set is the more common term in SQL circles, but that may be what you mean. Update, delete and insert sprocs don't really return result sets, although they do tell you how many rows were affected. Select sprocs always return result sets, although said set may consist of zero rows. TOP n also depends on which version of SQL Server you are using. In 2005 and 2008, TOP accepts an argument so you don't have to construct the statement, you can just pass in a variable and plug it into the code: CREATE PROCEDURE myProc (@n int) AS SELECT TOP @n [PERCENT] * FROM someTables -- percent is optional ... etc. Arthur On 3/24/08, jwcolby wrote: > > A stored procedure can return a data set correct? Is that data set > updateable? > > I need to run a stored procedure, where I pass in the Value for the TOP N > (the N part) and then build up a SQL statement and execute that inside of > the sp. That sp needs to return the data set to another SP, and that SP > has > to update a field in the data set returned by the first sp. > > Is this possible? > > ATM I have a view called TopN, which returns a date field. I have a query > that updates that date field to today's date. The problem is that the > TopN > view is hard coded with a number (30000 for today's order) but that value > could be any number. So I need to turn the view into a SP where I can > pass > in the number of records to update and then pass the set up date fields > back > to an update SP to do the update. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > 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 Tue Mar 25 07:15:48 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 08:15:48 -0400 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: <29f585dd0803250341u3ac0906eo23fb5e3b3c8ef9f8@mail.gmail.com> References: <005b01c88dfc$d280f1c0$0201a8c0@M90> <29f585dd0803250341u3ac0906eo23fb5e3b3c8ef9f8@mail.gmail.com> Message-ID: <006101c88e71$f6a2c450$0201a8c0@M90> Arthur, >TOP n also depends on which version of SQL Server you are using. In 2005 and 2008, TOP accepts an argument so you don't have to construct the statement, you can just pass in >a variable and plug it into the code: >CREATE PROCEDURE myProc (@n int) >AS > SELECT TOP @n [PERCENT] * FROM someTables -- percent is optional > ... etc. OH now THAT is cool. So what is the syntax for returning the dataset? Is the select statement just implicitly assigned as the output? John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Tuesday, March 25, 2008 6:41 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Returning a dataset Depends what you mean by data set. Result set is the more common term in SQL circles, but that may be what you mean. Update, delete and insert sprocs don't really return result sets, although they do tell you how many rows were affected. Select sprocs always return result sets, although said set may consist of zero rows. TOP n also depends on which version of SQL Server you are using. In 2005 and 2008, TOP accepts an argument so you don't have to construct the statement, you can just pass in a variable and plug it into the code: CREATE PROCEDURE myProc (@n int) AS SELECT TOP @n [PERCENT] * FROM someTables -- percent is optional ... etc. Arthur From fuller.artful at gmail.com Tue Mar 25 09:01:40 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Tue, 25 Mar 2008 10:01:40 -0400 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: <006101c88e71$f6a2c450$0201a8c0@M90> References: <005b01c88dfc$d280f1c0$0201a8c0@M90> <29f585dd0803250341u3ac0906eo23fb5e3b3c8ef9f8@mail.gmail.com> <006101c88e71$f6a2c450$0201a8c0@M90> Message-ID: <29f585dd0803250701t3dd7f676q254a89540ac0a224@mail.gmail.com> Yup. The SELECT statement returns a result set and you can work with it as you please. You might, for example, enter the name of the sproc as the record source of an Access form (assuming a connection of course). A. On Tue, Mar 25, 2008 at 8:15 AM, jwcolby wrote: > OH now THAT is cool. > > So what is the syntax for returning the dataset? Is the select statement > just implicitly assigned as the output? > > > John W. Colby > From jwcolby at colbyconsulting.com Tue Mar 25 13:05:32 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 14:05:32 -0400 Subject: [dba-SQLServer] Copy a database using a store procedure or function Message-ID: <00a401c88ea2$d18660b0$0201a8c0@M90> I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com From word_diva at hotmail.com Tue Mar 25 13:17:31 2008 From: word_diva at hotmail.com (Nancy Lytle) Date: Tue, 25 Mar 2008 13:17:31 -0500 Subject: [dba-SQLServer] Copy a database using a store procedure or function In-Reply-To: <00a401c88ea2$d18660b0$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> Message-ID: I know it's a pain to learn, but SSIS (integration services) can do just about everything you need to do.Nancy Lytle N_Lytle at terpalum.umd.edu > From: jwcolby at colbyconsulting.com> To: dba-sqlserver at databaseadvisors.com> Date: Tue, 25 Mar 2008 14:05:32 -0400> Subject: [dba-SQLServer] Copy a database using a store procedure or function> > I have built up a template database which has views that pull data out of> many different databases / tables. Additionally I now have user stored> procedures which perform processing steps. In real life I manually copy> this template database to a new name using the copy database wizard, and> then run the stored procedures and stuff to build up a data order for> shipment. > > What I really need to do is have a method of copying this database to a new> name and then "use" that database to launch the various stored procedures> inside of it to fill the tables, build the data and export the data.> > Is there a function or sp which can copy a database to a new name? When I> Google I get about a million "use the copy database wizard" answers.> > John W. Colby> Colby Consulting> www.ColbyConsulting.com > > _______________________________________________> dba-SQLServer mailing list> dba-SQLServer at databaseadvisors.com> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver> http://www.databaseadvisors.com> _________________________________________________________________ Test your Star IQ http://club.live.com/red_carpet_reveal.aspx?icid=redcarpet_HMTAGMAR From James at fcidms.com Tue Mar 25 13:40:23 2008 From: James at fcidms.com (James Barash) Date: Tue, 25 Mar 2008 14:40:23 -0400 Subject: [dba-SQLServer] Copy a database using a store procedure or function In-Reply-To: <00a401c88ea2$d18660b0$0201a8c0@M90> Message-ID: <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 Tue Mar 25 14:08:38 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 15:08:38 -0400 Subject: [dba-SQLServer] Copy a database using a store procedure orfunction In-Reply-To: <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> Message-ID: <00a901c88eab$a25a2e30$0201a8c0@M90> James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 From pauln at sqlserverbible.com Tue Mar 25 14:24:34 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 13:24:34 -0600 Subject: [dba-SQLServer] Copy a database using a store procedure orfunction In-Reply-To: <00a901c88eab$a25a2e30$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> Message-ID: <004401c88ead$dc2de1e0$9489a5a0$@com> To move /copy a file use detach - copy the file - then attach. Real fast real simple. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Tue Mar 25 14:24:58 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 13:24:58 -0600 Subject: [dba-SQLServer] Copy a database using a store procedure orfunction In-Reply-To: <00a901c88eab$a25a2e30$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> Message-ID: <004501c88ead$ea8c2a80$bfa47f80$@com> Never Ever build any objects using SSMS Object Explorer. Develop everything - DDL/Schema, procs, unit test inserts, and proc test batches ALL with scripts stored as .sql files in the file system and checked into source control. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Tue Mar 25 14:32:56 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 13:32:56 -0600 Subject: [dba-SQLServer] Check out my SQLServerDVD.com commercial In-Reply-To: <00a901c88eab$a25a2e30$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> Message-ID: <004901c88eaf$07e8afd0$17ba0f70$@com> It's on YouTube, but easier to find on my website www.sqlserverbible.com -Paul From robert at webedb.com Tue Mar 25 14:40:39 2008 From: robert at webedb.com (Robert L. Stewart) Date: Tue, 25 Mar 2008 14:40:39 -0500 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: References: Message-ID: <200803251945.m2PJjN8Q015316@databaseadvisors.com> Arthur, All of my Insert, Update and Delete SPROCS return result sets. The insert returns the record inserted. The Update returns the record updated. The Delete returns the rows deleted or in 2005, the actual record deleted. Robert At 01:00 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 06:41:03 -0400 >From: "Arthur Fuller" >Subject: Re: [dba-SQLServer] Returning a dataset >To: "Discussion concerning MS SQL Server" > >Message-ID: > <29f585dd0803250341u3ac0906eo23fb5e3b3c8ef9f8 at mail.gmail.com> >Content-Type: text/plain; charset=ISO-8859-1 > >Depends what you mean by data set. Result set is the more common term in SQL >circles, but that may be what you mean. Update, delete and insert sprocs >don't really return result sets, although they do tell you how many rows >were affected. Select sprocs always return result sets, although said set >may consist of zero rows. > >TOP n also depends on which version of SQL Server you are using. In 2005 and >2008, TOP accepts an argument so you don't have to construct the statement, >you can just pass in a variable and plug it into the code: > >CREATE PROCEDURE myProc (@n int) >AS > SELECT TOP @n [PERCENT] * FROM someTables -- percent is optional > ... etc. > >Arthur From jwcolby at colbyconsulting.com Tue Mar 25 14:52:56 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 15:52:56 -0400 Subject: [dba-SQLServer] Copy a database using a storeprocedure orfunction In-Reply-To: <004501c88ead$ea8c2a80$bfa47f80$@com> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com> Message-ID: <00b601c88eb1$d2bf09f0$0201a8c0@M90> I have to tell you Paul that your world is not accessible to the average Joe trying to get work done. I am not a SQL Server admin or a Sql Server anything, I am a guy trying to fill an order. I haven't the slightest interest in spending the next 10 years becoming a command line guru. I want to write a line of code Copy "SomeDatabaseName", "SomeOtherDatabaseName" If it is more complex than that then it is useless to me. In any given week, I support a call center application in Connecticut (via a tunnel and RDT), a pair of databases in a town just north of Phili (via RDT), my servers, pick up information on building virtual machines, download and install firewalls, and fill orders on a largish database shipping email lists to clients etc. I am just me, running a business. We live in 2008, not 1958. I am not feeding punched cards into a card hopper, I am trying to solve a problem. Anything that stands in the way of solving that problem is a curse, not a blessing. SQL Server simply sucks compared to almost anything else out there in 2008. Batches? Give me a break!!! Command lines? I did that in 1982 with CPM, I do not expect to do that in 2008 with SQL Server. TWENTY FIVE YEARS AGO I DID COMMAND LINES. My computer is three orders of magnitude more powerful than 1982. My programming languages are several orders of magnitude more powerful than 1982. My database is several orders of magnitude more powerful than 1982. And yet I am supposed to use batches and command lines to control it????? That is like programming in Fortran by lining up the columns of a line of code in the columns of a punched card! I did that (in 1984). You may very well love that crap, but it is not useful to the ordinary Joe. Using primitive tools is not a sign of intelligence (or manliness). It is merely a sign of the sorry state of the tool. Just my opinion of course. Trying to get WORK done here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 3:25 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storeprocedure orfunction Never Ever build any objects using SSMS Object Explorer. Develop everything - DDL/Schema, procs, unit test inserts, and proc test batches ALL with scripts stored as .sql files in the file system and checked into source control. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? 19 When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pauln at sqlserverbible.com Tue Mar 25 15:07:31 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 14:07:31 -0600 Subject: [dba-SQLServer] Copy a database using a storeprocedure orfunction In-Reply-To: <00b601c88eb1$d2bf09f0$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com> <00b601c88eb1$d2bf09f0$0201a8c0@M90> Message-ID: <006c01c88eb3$dc315590$949400b0$@com> Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:53 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storeprocedure orfunction I have to tell you Paul that your world is not accessible to the average Joe trying to get work done. I am not a SQL Server admin or a Sql Server anything, I am a guy trying to fill an order. I haven't the slightest interest in spending the next 10 years becoming a command line guru. I want to write a line of code Copy "SomeDatabaseName", "SomeOtherDatabaseName" If it is more complex than that then it is useless to me. In any given week, I support a call center application in Connecticut (via a tunnel and RDT), a pair of databases in a town just north of Phili (via RDT), my servers, pick up information on building virtual machines, download and install firewalls, and fill orders on a largish database shipping email lists to clients etc. I am just me, running a business. We live in 2008, not 1958. I am not feeding punched cards into a card hopper, I am trying to solve a problem. Anything that stands in the way of solving that problem is a curse, not a blessing. SQL Server simply sucks compared to almost anything else out there in 2008. Batches? Give me a break!!! Command lines? I did that in 1982 with CPM, I do not expect to do that in 2008 with SQL Server. TWENTY FIVE YEARS AGO I DID COMMAND LINES. My computer is three orders of magnitude more powerful than 1982. My programming languages are several orders of magnitude more powerful than 1982. My database is several orders of magnitude more powerful than 1982. And yet I am supposed to use batches and command lines to control it????? That is like programming in Fortran by lining up the columns of a line of code in the columns of a punched card! I did that (in 1984). You may very well love that crap, but it is not useful to the ordinary Joe. Using primitive tools is not a sign of intelligence (or manliness). It is merely a sign of the sorry state of the tool. Just my opinion of course. Trying to get WORK done here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 3:25 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storeprocedure orfunction Never Ever build any objects using SSMS Object Explorer. Develop everything - DDL/Schema, procs, unit test inserts, and proc test batches ALL with scripts stored as .sql files in the file system and checked into source control. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? 19 When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From Elizabeth.J.Doering at wellsfargo.com Tue Mar 25 15:10:27 2008 From: Elizabeth.J.Doering at wellsfargo.com (Elizabeth.J.Doering at wellsfargo.com) Date: Tue, 25 Mar 2008 15:10:27 -0500 Subject: [dba-SQLServer] Copy a database using a store procedure or function References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90><004501c88ead$ea8c2a80$bfa47f80$@com> <00b601c88eb1$d2bf09f0$0201a8c0@M90> Message-ID: I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:53 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using astoreprocedure orfunction I have to tell you Paul that your world is not accessible to the average Joe trying to get work done. I am not a SQL Server admin or a Sql Server anything, I am a guy trying to fill an order. I haven't the slightest interest in spending the next 10 years becoming a command line guru. I want to write a line of code Copy "SomeDatabaseName", "SomeOtherDatabaseName" If it is more complex than that then it is useless to me. In any given week, I support a call center application in Connecticut (via a tunnel and RDT), a pair of databases in a town just north of Phili (via RDT), my servers, pick up information on building virtual machines, download and install firewalls, and fill orders on a largish database shipping email lists to clients etc. I am just me, running a business. We live in 2008, not 1958. I am not feeding punched cards into a card hopper, I am trying to solve a problem. Anything that stands in the way of solving that problem is a curse, not a blessing. SQL Server simply sucks compared to almost anything else out there in 2008. Batches? Give me a break!!! Command lines? I did that in 1982 with CPM, I do not expect to do that in 2008 with SQL Server. TWENTY FIVE YEARS AGO I DID COMMAND LINES. My computer is three orders of magnitude more powerful than 1982. My programming languages are several orders of magnitude more powerful than 1982. My database is several orders of magnitude more powerful than 1982. And yet I am supposed to use batches and command lines to control it????? That is like programming in Fortran by lining up the columns of a line of code in the columns of a punched card! I did that (in 1984). You may very well love that crap, but it is not useful to the ordinary Joe. Using primitive tools is not a sign of intelligence (or manliness). It is merely a sign of the sorry state of the tool. Just my opinion of course. Trying to get WORK done here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 3:25 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storeprocedure orfunction Never Ever build any objects using SSMS Object Explorer. Develop everything - DDL/Schema, procs, unit test inserts, and proc test batches ALL with scripts stored as .sql files in the file system and checked into source control. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? 19 When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 From robert at webedb.com Tue Mar 25 15:47:38 2008 From: robert at webedb.com (Robert L. Stewart) Date: Tue, 25 Mar 2008 15:47:38 -0500 Subject: [dba-SQLServer] Copy a database using a stored procedure or function In-Reply-To: References: Message-ID: <200803252050.m2PKoSsH016750@databaseadvisors.com> John, Just a suggestion, do not ever work with Oracle. If you think SQL Server is archaic, you have not seen anything yet. Take a look at SQL DMO Objects and the TRANSFER method. That is what the wizard is using to do a database copy. If you want to do it relatively simply: Create the new DB. Backup the current DB. Restore the backup with overwrite option to the new db. And yes, if you are willing to write some code, the three steps can be done through a stored procedure. Robert At 03:10 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 15:52:56 -0400 >From: "jwcolby" >Subject: Re: [dba-SQLServer] Copy a database using a storeprocedure > orfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <00b601c88eb1$d2bf09f0$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >I have to tell you Paul that your world is not accessible to the average Joe >trying to get work done. I am not a SQL Server admin or a Sql Server >anything, I am a guy trying to fill an order. I haven't the slightest >interest in spending the next 10 years becoming a command line guru. I want >to write a line of code > >Copy "SomeDatabaseName", "SomeOtherDatabaseName" > >If it is more complex than that then it is useless to me. In any given >week, I support a call center application in Connecticut (via a tunnel and >RDT), a pair of databases in a town just north of Phili (via RDT), my >servers, pick up information on building virtual machines, download and >install firewalls, and fill orders on a largish database shipping email >lists to clients etc. I am just me, running a business. > >We live in 2008, not 1958. I am not feeding punched cards into a card >hopper, I am trying to solve a problem. Anything that stands in the way of >solving that problem is a curse, not a blessing. SQL Server simply sucks >compared to almost anything else out there in 2008. Batches? Give me a >break!!! Command lines? I did that in 1982 with CPM, I do not expect to do >that in 2008 with SQL Server. TWENTY FIVE YEARS AGO I DID COMMAND LINES. >My computer is three orders of magnitude more powerful than 1982. My >programming languages are several orders of magnitude more powerful than >1982. My database is several orders of magnitude more powerful than 1982. >And yet I am supposed to use batches and command lines to control it????? >That is like programming in Fortran by lining up the columns of a line of >code in the columns of a punched card! I did that (in 1984). > >You may very well love that crap, but it is not useful to the ordinary Joe. >Using primitive tools is not a sign of intelligence (or manliness). It is >merely a sign of the sorry state of the tool. > >Just my opinion of course. Trying to get WORK done here. > >John W. Colby From jwcolby at colbyconsulting.com Tue Mar 25 15:52:29 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 16:52:29 -0400 Subject: [dba-SQLServer] QLRE: Copy a database usinga storeprocedure orfunction In-Reply-To: <006c01c88eb3$dc315590$949400b0$@com> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90> <006c01c88eb3$dc315590$949400b0$@com> Message-ID: <00b701c88eba$241e0eb0$0201a8c0@M90> No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul From jwcolby at colbyconsulting.com Tue Mar 25 16:00:56 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 17:00:56 -0400 Subject: [dba-SQLServer] Copy a database using a store procedure orfunction In-Reply-To: References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90><004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90> Message-ID: <00b801c88ebb$52599410$0201a8c0@M90> I knew if I bitched long enough someone would get tired of it and come up with an answer. Thanks. I am trying it now. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Tuesday, March 25, 2008 4:10 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:53 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using astoreprocedure orfunction I have to tell you Paul that your world is not accessible to the average Joe trying to get work done. I am not a SQL Server admin or a Sql Server anything, I am a guy trying to fill an order. I haven't the slightest interest in spending the next 10 years becoming a command line guru. I want to write a line of code Copy "SomeDatabaseName", "SomeOtherDatabaseName" If it is more complex than that then it is useless to me. In any given week, I support a call center application in Connecticut (via a tunnel and RDT), a pair of databases in a town just north of Phili (via RDT), my servers, pick up information on building virtual machines, download and install firewalls, and fill orders on a largish database shipping email lists to clients etc. I am just me, running a business. We live in 2008, not 1958. I am not feeding punched cards into a card hopper, I am trying to solve a problem. Anything that stands in the way of solving that problem is a curse, not a blessing. SQL Server simply sucks compared to almost anything else out there in 2008. Batches? Give me a break!!! Command lines? I did that in 1982 with CPM, I do not expect to do that in 2008 with SQL Server. TWENTY FIVE YEARS AGO I DID COMMAND LINES. My computer is three orders of magnitude more powerful than 1982. My programming languages are several orders of magnitude more powerful than 1982. My database is several orders of magnitude more powerful than 1982. And yet I am supposed to use batches and command lines to control it????? That is like programming in Fortran by lining up the columns of a line of code in the columns of a punched card! I did that (in 1984). You may very well love that crap, but it is not useful to the ordinary Joe. Using primitive tools is not a sign of intelligence (or manliness). It is merely a sign of the sorry state of the tool. Just my opinion of course. Trying to get WORK done here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 3:25 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storeprocedure orfunction Never Ever build any objects using SSMS Object Explorer. Develop everything - DDL/Schema, procs, unit test inserts, and proc test batches ALL with scripts stored as .sql files in the file system and checked into source control. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? 19 When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From robert at webedb.com Tue Mar 25 16:06:02 2008 From: robert at webedb.com (Robert L. Stewart) Date: Tue, 25 Mar 2008 16:06:02 -0500 Subject: [dba-SQLServer] Create DB and Backup DB In-Reply-To: References: Message-ID: <200803252107.m2PL7G8Z026082@databaseadvisors.com> John, Below is the code to create a DB and Backup a DB. I will let you do the research and get the SQL to do the restore. It is a bit more than your requested single line though. What you want to do is restore the backup you just created to the DB you created. Robert P.S. While you do need to look for line wraps, it is not a problem like VBA. CREATE PROCEDURE dbo. pCreate_Load_DB @DBNameCreate varchar ( 64 ), @DBNameBackup varchar ( 64 ), @data_path nvarchar ( 256 ) = NULL, @BackupLocation varchar ( 500 ) = null, @Drive char ( 1 ), @InstanceName sysname = null, @Drive varchar ( 1 ) = null AS BEGIN SET NOCOUNT ON ; DECLARE @Sql nvarchar ( max ), @ErrorMessage varchar ( 500 ) SET @ErrorMessage = 'No Error' IF @data_path IS NULL BEGIN SET @data_path = ( SELECT SUBSTRING ( physical_name , 1, CHARINDEX ( N 'master.mdf' , LOWER ( physical_name )) - 1) FROM master. sys.master_files WHERE database_id = 1 AND file_id = 1 ) ; END -- execute the CREATE DATABASE statement SET @Sql = 'CREATE DATABASE Sales ON ( NAME = ' + @DBNameCreate + '_dat, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'dat.mdf' + CHAR ( 39 ) + ', SIZE = 10, FILEGROWTH = 5 ) LOG ON ( NAME = ' + @DBNameCreate + '_log, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'log.ldf' + CHAR ( 39 ) + ', SIZE = 5MB )' EXEC sp_executesql @Sql SET @Drive = 'F' SET @InstanceName = CAST ( ISNULL ( SERVERPROPERTY ( 'InstanceName' ), SERVERPROPERTY ( 'ServerName' )) AS sysname ) SET @BackupLocation = @Drive + ':\SQL_Backups\' + @InstanceName + '\' BEGIN TRY SET @SQL = 'BACKUP DATABASE ' + @DBNameBackup + ' TO DISK=' + CHAR ( 39 ) + @BackupLocation + @DBNameBackup + '_BACKUP.BAK' + CHAR ( 39 ) + ' WITH INIT' EXEC sp_ExecuteSql @SQL -- truncate the log files BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY SIMPLE' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + char ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + char ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'TRUE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN CHECKPOINT END BEGIN SET @Sql = 'DBCC SHRINKFILE (' + @DBNameBackup + '_Log,1)' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + char ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + char ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'FALSE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY FULL' EXEC sp_executesql @Sql END END TRY BEGIN CATCH SELECT @ErrorMessage = ERROR_MESSAGE () ; END CATCH END From jwcolby at colbyconsulting.com Tue Mar 25 16:17:19 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 17:17:19 -0400 Subject: [dba-SQLServer] Create DB and Backup DB In-Reply-To: <200803252107.m2PL7G8Z026082@databaseadvisors.com> References: <200803252107.m2PL7G8Z026082@databaseadvisors.com> Message-ID: <00b901c88ebd$9c675540$0201a8c0@M90> Wow! John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Tuesday, March 25, 2008 5:06 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Create DB and Backup DB John, Below is the code to create a DB and Backup a DB. I will let you do the research and get the SQL to do the restore. It is a bit more than your requested single line though. What you want to do is restore the backup you just created to the DB you created. Robert P.S. While you do need to look for line wraps, it is not a problem like VBA. CREATE PROCEDURE dbo. pCreate_Load_DB @DBNameCreate varchar ( 64 ), @DBNameBackup varchar ( 64 ), @data_path nvarchar ( 256 ) = NULL, @BackupLocation varchar ( 500 ) = null, @Drive char ( 1 ), @InstanceName sysname = null, @Drive varchar ( 1 ) = null AS BEGIN SET NOCOUNT ON ; DECLARE @Sql nvarchar ( max ), @ErrorMessage varchar ( 500 ) SET @ErrorMessage = 'No Error' IF @data_path IS NULL BEGIN SET @data_path = ( SELECT SUBSTRING ( physical_name , 1, CHARINDEX ( N 'master.mdf' , LOWER ( physical_name )) - 1) FROM master. sys.master_files WHERE database_id = 1 AND file_id = 1 ) ; END -- execute the CREATE DATABASE statement SET @Sql = 'CREATE DATABASE Sales ON ( NAME = ' + @DBNameCreate + '_dat, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'dat.mdf' + CHAR ( 39 ) + ', SIZE = 10, FILEGROWTH = 5 ) LOG ON ( NAME = ' + @DBNameCreate + '_log, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'log.ldf' + CHAR ( 39 ) + ', SIZE = 5MB )' EXEC sp_executesql @Sql SET @Drive = 'F' SET @InstanceName = CAST ( ISNULL ( SERVERPROPERTY ( 'InstanceName' ), SERVERPROPERTY ( 'ServerName' )) AS sysname ) SET @BackupLocation = @Drive + ':\SQL_Backups\' + @InstanceName + '\' BEGIN TRY SET @SQL = 'BACKUP DATABASE ' + @DBNameBackup + ' TO DISK=' + CHAR ( 39 ) + @BackupLocation + @DBNameBackup + '_BACKUP.BAK' + CHAR ( 39 ) + ' WITH INIT' EXEC sp_ExecuteSql @SQL -- truncate the log files BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY SIMPLE' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + char ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + char ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'TRUE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN CHECKPOINT END BEGIN SET @Sql = 'DBCC SHRINKFILE (' + @DBNameBackup + '_Log,1)' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + char ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + char ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'FALSE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY FULL' EXEC sp_executesql @Sql END END TRY BEGIN CATCH SELECT @ErrorMessage = ERROR_MESSAGE () ; END CATCH END _______________________________________________ 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 Tue Mar 25 16:36:17 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 17:36:17 -0400 Subject: [dba-SQLServer] Copy a database using a store procedure orfunction In-Reply-To: References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90><004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90> Message-ID: <00ba01c88ec0$42a39160$0201a8c0@M90> Elizabeth, Thanks for the code. I am trying it now. I would like to make one comment though. >This is from BOL for SQL Server 2005, which is often amazingly helpful. First of all, what is you job? What do you do? My comment is that, the instruction manual for flying a DC10 is almost assuredly "amazingly useful" to the right people. If I just want to get to London by tomorrow night, it is probably about as useful as the proverbial "tits on a boar". That manual and a two thousand dollars will get you a ticket to London. I have spent hours in BOL (really!). It has rarely been "amazingly useful", in fact I can't say that I have EVER found it such. But then my job is not writing SQL Server TSQL code day in and day out. If that were my job then I am absolutely sure it would be "amazingly useful" to me. I used the "flight manual" example because when I was a teenager, I had a job cleaning apartments after people moved out. I was cleaning an apartment and found the maintenance manual for an army helicopter. While it was fascinating, it was also "totally useless" to me. OTOH it was no doubt "amazingly useful" to the guy who left it behind. My job is not to write TSQL. Very occasionally I am forced to do so because there are no easier to use tools but that doesn't mean that I will EVER know enough to find BOL "amazingly useful". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Tuesday, March 25, 2008 4:10 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 From Gustav at cactus.dk Tue Mar 25 17:55:00 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 25 Mar 2008 23:55:00 +0100 Subject: [dba-SQLServer] QLRE: Copy a database using a store procedure or function Message-ID: Hi John How far have you pushed Visual Studio? I've found with 2005 that you can from inside this with DataTableAdapters etc. perform surprisingly many tasks which behind the scenes generate code directly in the database. And with VS2008 you have LINQ which wraps much SQL in an OO style syntax much more in style with the other code you write. This is some of the beauty of Visual Studio. Many ASP script kiddies still open a connection to the database and fire some SQL code created as a simple string. That way they use VS as classic ASP ten years ago which was horrible. The abstraction introduced by the Data Abstraction Layers "lifts" much of the coding to a level which you would expect today - indeed if you (like most of us here) are grown up with the power of Access and its GUI for building queries. And even if I respect - and think I understand - Paul's and Robert's arguments on writing pure SQL in the manager, I have the same feeling like you when I do so, that it can't be true I in this year have to sit and write GO in a primitive editor. /gustav >>> jwcolby at colbyconsulting.com 25-03-2008 21:52 >>> No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul From fhtapia at gmail.com Tue Mar 25 17:59:37 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 25 Mar 2008 15:59:37 -0700 Subject: [dba-SQLServer] Copy a database using a storeprocedure orfunction In-Reply-To: <00b601c88eb1$d2bf09f0$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com> <00b601c88eb1$d2bf09f0$0201a8c0@M90> Message-ID: John, Since you do not want to be a TSQL wiz, there are ways for you to get things done really quick. One such way is to use a tool from Red-Gate. It's called Sql Compare, you can litterally point it from source to destination db, it will look at all such objects and copy over any new object, or even bring over modified objects, (ie, changes to views) to the target db. http://www.red-gate.com/ -- Francisco On Tue, Mar 25, 2008 at 12:52 PM, jwcolby wrote: > I have to tell you Paul that your world is not accessible to the average > Joe > trying to get work done. I am not a SQL Server admin or a Sql Server > anything, I am a guy trying to fill an order. I haven't the slightest > interest in spending the next 10 years becoming a command line guru. I > want > to write a line of code > > Copy "SomeDatabaseName", "SomeOtherDatabaseName" > > If it is more complex than that then it is useless to me. In any given > week, I support a call center application in Connecticut (via a tunnel and > RDT), a pair of databases in a town just north of Phili (via RDT), my > servers, pick up information on building virtual machines, download and > install firewalls, and fill orders on a largish database shipping email > lists to clients etc. I am just me, running a business. > > We live in 2008, not 1958. I am not feeding punched cards into a card > hopper, I am trying to solve a problem. Anything that stands in the way > of > solving that problem is a curse, not a blessing. SQL Server simply sucks > compared to almost anything else out there in 2008. Batches? Give me a > break!!! Command lines? I did that in 1982 with CPM, I do not expect to > do > that in 2008 with SQL Server. TWENTY FIVE YEARS AGO I DID COMMAND LINES. > My computer is three orders of magnitude more powerful than 1982. My > programming languages are several orders of magnitude more powerful than > 1982. My database is several orders of magnitude more powerful than 1982. > And yet I am supposed to use batches and command lines to control it????? > That is like programming in Fortran by lining up the columns of a line of > code in the columns of a punched card! I did that (in 1984). > > You may very well love that crap, but it is not useful to the ordinary > Joe. > Using primitive tools is not a sign of intelligence (or manliness). It is > merely a sign of the sorry state of the tool. > > Just my opinion of course. Trying to get WORK done here. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul > Nielsen > Sent: Tuesday, March 25, 2008 3:25 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a storeprocedure > orfunction > > Never Ever build any objects using SSMS Object Explorer. Develop > everything > - DDL/Schema, procs, unit test inserts, and proc test batches ALL with > scripts stored as .sql files in the file system and checked into source > control. > > > > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Tuesday, March 25, 2008 1:09 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > James, > > That is an interesting solution. My main objection to that (other than > being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a > new view or stored procedure etc I have to rebuild the script. I just > want > to > > Copy "SomeDatabase", "NewName" > > This is the kind of thing that drives me crazy about SQL Server. It has > the > IQ of a mouse when it comes to programming. I'm telling you the . > Language > of Dbase II was like Einstein compared to what you have to do with SQL > Server. > > "Generate scripts"? The database is a single file (OK it could be more, > but > still...), what is so damned hard about copying that and telling it that > it > has a new name? To make matters worse, there is a wizard that does it. > Why > can't I just call whatever function that wizard calls and pass in the > parameters that the wizard gathers and copy my database? > 19 > When I want pain, I go to my mistress downtown and she uses a cat-o-nine. > When I really want some TORTURE I fire up SQL Server and try and do some > work. > > ;-) > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James > Barash > Sent: Tuesday, March 25, 2008 2:40 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > John: > > If you only need to copy the design of the database but not the data, you > can use the scripting wizard to create a script of all the objects and use > that to make the new database. If you are using SQL Server 2005, > Right-Click > on the database, select Tasks -> Generate Scripts. Then you can choose to > script all the objects, including Tables, Views, Stored Procedures, UDF, > Users, etc; or you can choose individual objects. Once you've created the > script, add the appropriate Create Database statement at the top and save > the script to a file and you will be able to build as many database as you > need from the same template. > Hope this helps. > > James Barash > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Tuesday, March 25, 2008 2:06 PM > To: 'Discussion concerning MS SQL Server' > Subject: [dba-SQLServer] Copy a database using a store procedure or > function > > I have built up a template database which has views that pull data out of > many different databases / tables. Additionally I now have user stored > procedures which perform processing steps. In real life I manually copy > this template database to a new name using the copy database wizard, and > then run the stored procedures and stuff to build up a data order for > shipment. > > What I really need to do is have a method of copying this database to a > new > name and then "use" that database to launch the various stored procedures > inside of it to fill the tables, build the data and export the data. > > Is there a function or sp which can copy a database to a new name? When I > Google I get about a million "use the copy database wizard" answers. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > 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 > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > __________ NOD32 2971 (20080325) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > > _______________________________________________ > 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 > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From pauln at sqlserverbible.com Tue Mar 25 18:17:07 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 17:17:07 -0600 Subject: [dba-SQLServer] Copy a database using a store procedure orfunction In-Reply-To: <004401c88ead$dc2de1e0$9489a5a0$@com> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> <004401c88ead$dc2de1e0$9489a5a0$@com> Message-ID: <00c701c88ece$58b36c60$0a1a4520$@com> For a anti-T-SQL, no T-SQL batches GUI easy way to move a file... As I posted at 1:25... Pick the database in SSMS - Object Explorer Right click to open context menu > Tasks > Detach then OK The file can now be copied to wherever you want. On the new server, in SSMS-Object Explorer Pick Databases Right click to Open Context Menu > Attach Pick the file and click OK. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 1:25 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction To move /copy a file use detach - copy the file - then attach. Real fast real simple. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fhtapia at gmail.com Tue Mar 25 18:21:26 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 25 Mar 2008 16:21:26 -0700 Subject: [dba-SQLServer] Copy a database using a store procedure orfunction In-Reply-To: <00ba01c88ec0$42a39160$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com> <00b601c88eb1$d2bf09f0$0201a8c0@M90> <00ba01c88ec0$42a39160$0201a8c0@M90> Message-ID: John, You "used" to write databases. and that "Used To" mean you wrote "SQL" code. Granted that Access SQL is nowhere in the realm of TSQL, but neither is TSQL and VBA, even though you can practically do it all from TSQL (but you would not want to). BOL is a manual you "Have To" learn to use. I say "Have To" because as long as you plan on using Sql Server, you should plan on making BOL and Google your best friend. There are many things that I am constantly learning about this engine, and I've been working on as an Administrator for over 5 years. You can't know everything, and it's great that resources such as this list and the internet exists. The term "Amazingly useful" is a subjective term. However the kindness you receive despite your spammer database is more "amazing useful" than I ever thought you'd get. I mean more power to you that you are banking in on your knowledge of databases and explotation of people's personal information and putting it to good use to make good $$. In programming (not just VB) there are many roads on how to get there. Not all of them are bad choices, some just make more logical sense. btw, Critizing the car because the driver doesn't know how to drive is also useless. -- Francisco On Tue, Mar 25, 2008 at 2:36 PM, jwcolby wrote: > Elizabeth, > > Thanks for the code. I am trying it now. I would like to make one > comment > though. > > >This is from BOL for SQL Server 2005, which is often amazingly helpful. > > First of all, what is you job? What do you do? > > My comment is that, the instruction manual for flying a DC10 is almost > assuredly "amazingly useful" to the right people. If I just want to get > to > London by tomorrow night, it is probably about as useful as the proverbial > "tits on a boar". That manual and a two thousand dollars will get you a > ticket to London. > > I have spent hours in BOL (really!). It has rarely been "amazingly > useful", > in fact I can't say that I have EVER found it such. But then my job is > not > writing SQL Server TSQL code day in and day out. If that were my job then > I > am absolutely sure it would be "amazingly useful" to me. > > I used the "flight manual" example because when I was a teenager, I had a > job cleaning apartments after people moved out. I was cleaning an > apartment > and found the maintenance manual for an army helicopter. While it was > fascinating, it was also "totally useless" to me. OTOH it was no doubt > "amazingly useful" to the guy who left it behind. > > My job is not to write TSQL. Very occasionally I am forced to do so > because > there are no easier to use tools but that doesn't mean that I will EVER > know > enough to find BOL "amazingly useful". > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of > Elizabeth.J.Doering at wellsfargo.com > Sent: Tuesday, March 25, 2008 4:10 PM > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > I haven't used this (being pretty new to this myself), but I'm sure some > one > else here can speak to it: > > E. Make a copy of a database using BACKUP and RESTORE This example uses > both > the BACKUP and RESTORE statements to make a copy of the AdventureWorks > database. The MOVE statement causes the data and log file to be restored > to > the specified locations. The RESTORE FILELISTONLY statement is used to > determine the number and names of the files in the database being > restored. > The new copy of the database is named TestDB. For more information, see > RESTORE FILELISTONLY (Transact-SQL). > > Copy Code > BACKUP DATABASE AdventureWorks > TO DISK = 'C:\AdventureWorks.bak' > > RESTORE FILELISTONLY > FROM DISK = 'C:\AdventureWorks.bak' > > RESTORE DATABASE TestDB > FROM DISK = 'C:\AdventureWorks.bak' > WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', > MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' > GO > > This is from BOL for SQL Server 2005, which is often amazingly helpful. > > HTH, > > > Liz > > > Liz Doering > elizabeth.j.doering at wellsfargo.com > 612.667.2447 > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From pauln at sqlserverbible.com Tue Mar 25 18:37:44 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 17:37:44 -0600 Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedure or function In-Reply-To: <00b701c88eba$241e0eb0$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90> <006c01c88eb3$dc315590$949400b0$@com> <00b701c88eba$241e0eb0$0201a8c0@M90> Message-ID: <00ea01c88ed1$3a793470$af6b9d50$@com> Hi John, Sounds like you have a lot to do. I build entire SQL Server back-ends in days/weeks much like you've figured out the best way to build entire Access apps in days/weeks. I was trying to show you the fastest and safest way to develop client-server code and then deploy across multiple servers. Moving databases or objects using back-ups or scripting out objects saved only in the database is a real pain and error prone. Coding with SSMS/Query Editor and then saving the script makes it easier and faster. But if that's not style, no problem. If you ever do need a proc written or any T-SQL help, I'd love to help you, Cheers, -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:52 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] QLRE: Copy a database usinga storeprocedure orfunction No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Tue Mar 25 19:30:28 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 20:30:28 -0400 Subject: [dba-SQLServer] Copy a database using astore procedure orfunction In-Reply-To: <00c701c88ece$58b36c60$0a1a4520$@com> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90><004401c88ead$dc2de1e0$9489a5a0$@com> <00c701c88ece$58b36c60$0a1a4520$@com> Message-ID: <00bc01c88ed8$987f7870$0201a8c0@M90> Yes, but it is not automated. I know how to copy a database, I have been doing so for months - with the menus from the gui. I need to automate this whole thing. You don't even have to detach with the wizard. I need to do it from code. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 7:17 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using astore procedure orfunction For a anti-T-SQL, no T-SQL batches GUI easy way to move a file... As I posted at 1:25... Pick the database in SSMS - Object Explorer Right click to open context menu > Tasks > Detach then OK The file can now be copied to wherever you want. On the new server, in SSMS-Object Explorer Pick Databases Right click to Open Context Menu > Attach Pick the file and click OK. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 1:25 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction To move /copy a file use detach - copy the file - then attach. Real fast real simple. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 1:09 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction James, That is an interesting solution. My main objection to that (other than being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a new view or stored procedure etc I have to rebuild the script. I just want to Copy "SomeDatabase", "NewName" This is the kind of thing that drives me crazy about SQL Server. It has the IQ of a mouse when it comes to programming. I'm telling you the . Language of Dbase II was like Einstein compared to what you have to do with SQL Server. "Generate scripts"? The database is a single file (OK it could be more, but still...), what is so damned hard about copying that and telling it that it has a new name? To make matters worse, there is a wizard that does it. Why can't I just call whatever function that wizard calls and pass in the parameters that the wizard gathers and copy my database? When I want pain, I go to my mistress downtown and she uses a cat-o-nine. When I really want some TORTURE I fire up SQL Server and try and do some work. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Tuesday, March 25, 2008 2:40 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedure orfunction John: If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:06 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using a store procedure or function I have built up a template database which has views that pull data out of many different databases / tables. Additionally I now have user stored procedures which perform processing steps. In real life I manually copy this template database to a new name using the copy database wizard, and then run the stored procedures and stuff to build up a data order for shipment. What I really need to do is have a method of copying this database to a new name and then "use" that database to launch the various stored procedures inside of it to fill the tables, build the data and export the data. Is there a function or sp which can copy a database to a new name? When I Google I get about a million "use the copy database wizard" answers. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 Tue Mar 25 20:03:20 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 21:03:20 -0400 Subject: [dba-SQLServer] Copy a database using a store procedureorfunction In-Reply-To: References: <00a401c88ea2$d18660b0$0201a8c0@M90><00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90><004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90><00ba01c88ec0$42a39160$0201a8c0@M90> Message-ID: <00bd01c88edd$2fa8d710$0201a8c0@M90> I am not criticizing anybody, I am simply pointing out that there are many different jobs. Mine is not SQL Server Administrator, nor SQL Server programmer. Mine is SQL Server user. SQL Server is an immensely powerful system where the human interface is just emerging from the stone age. Like anyone familiar with the stone age tools, they are good enough to get the job done, if you happen to be familiar with the stone age tools. If you are familiar with high powered rifles and razor sharp knives,and airplanes to get to the hunt, the stone age hunting tools are ... well.. Stone age. I understand perfectly well that Sql server can do immensely useful things, so can Linux. But Windows is king for a reason, having nothing to do with the ability to get the job done, but rather to do with making the job easier to get done. In fact I still do write databases. I just write them using modern tools. I am in the process of writing a complex system with dozens of tables to track clients, jobs, orders, billing etc, all with the data store in SQL Server. I would not consider writing the application as TSQL in files on the disk. Sorry, ain't happening. I am using VB.Net, with libraries to allow me to automate getting at the email attachments, read order data out of spreadsheets (my client's requirements), automate building disk structures, automate exporting data out to CSVs for the address validation, automate directory watching to sense when the files pop back out of the address validation software, automate reimportation to SQL Server, automate exporting to flat file, encrypting the files when the client asks, log errors, log my machine time for billing, automate billing, and so forth and so on. Could I write it all in TSQL? No clue at all, but I can tell you that IF IT IS POSSIBLE, it would take me years to get good enough to write a reliable system in TSQL. It will take me weeks of coding to do it in VBA but it will look and work like modern software when I am done. Harness the power of SQL Server for what it does best, and the power of .Net for what it does best. You know as well as I that there is no one tool that does everything. RIGHT NOW, for the next few weeks, I need a quick and dirty script. And I can tell you that it is extremely unlikely that BOL will ever be my friend. My job does not require BOL. As for not knowing how to drive... That is plain silly. I am criticizing the car for having no dashboard. Sorry, but the dash board is missing. It has an immensely powerful engine, I will hand you that. And as you and many others have pointed out, I can go BUY a dashboard from other companies. I am just trying to get some quick things done, EASY things... IF you have been doing SQL Server admin for 10 years. The dashboard is missing. In the end I will use VB.Net to build a custom dashboard but in the here and now, quick and dirty the lack of a dashboard simply reminds me how stone age the tool is. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Tuesday, March 25, 2008 7:21 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a store procedureorfunction John, You "used" to write databases. and that "Used To" mean you wrote "SQL" code. Granted that Access SQL is nowhere in the realm of TSQL, but neither is TSQL and VBA, even though you can practically do it all from TSQL (but you would not want to). BOL is a manual you "Have To" learn to use. I say "Have To" because as long as you plan on using Sql Server, you should plan on making BOL and Google your best friend. There are many things that I am constantly learning about this engine, and I've been working on as an Administrator for over 5 years. You can't know everything, and it's great that resources such as this list and the internet exists. The term "Amazingly useful" is a subjective term. However the kindness you receive despite your spammer database is more "amazing useful" than I ever thought you'd get. I mean more power to you that you are banking in on your knowledge of databases and explotation of people's personal information and putting it to good use to make good $$. In programming (not just VB) there are many roads on how to get there. Not all of them are bad choices, some just make more logical sense. btw, Critizing the car because the driver doesn't know how to drive is also useless. -- Francisco From pauln at sqlserverbible.com Tue Mar 25 20:25:44 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 19:25:44 -0600 Subject: [dba-SQLServer] Copy a database using a store procedureorfunction In-Reply-To: <00bd01c88edd$2fa8d710$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90><00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90><004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90><00ba01c88ec0$42a39160$0201a8c0@M90> <00bd01c88edd$2fa8d710$0201a8c0@M90> Message-ID: <004401c88ee0$51061230$f3123690$@com> But you are using version control for all source code including DDL code, right? -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 7:03 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a store procedureorfunction I am not criticizing anybody, I am simply pointing out that there are many different jobs. Mine is not SQL Server Administrator, nor SQL Server programmer. Mine is SQL Server user. SQL Server is an immensely powerful system where the human interface is just emerging from the stone age. Like anyone familiar with the stone age tools, they are good enough to get the job done, if you happen to be familiar with the stone age tools. If you are familiar with high powered rifles and razor sharp knives,and airplanes to get to the hunt, the stone age hunting tools are ... well.. Stone age. I understand perfectly well that Sql server can do immensely useful things, so can Linux. But Windows is king for a reason, having nothing to do with the ability to get the job done, but rather to do with making the job easier to get done. In fact I still do write databases. I just write them using modern tools. I am in the process of writing a complex system with dozens of tables to track clients, jobs, orders, billing etc, all with the data store in SQL Server. I would not consider writing the application as TSQL in files on the disk. Sorry, ain't happening. I am using VB.Net, with libraries to allow me to automate getting at the email attachments, read order data out of spreadsheets (my client's requirements), automate building disk structures, automate exporting data out to CSVs for the address validation, automate directory watching to sense when the files pop back out of the address validation software, automate reimportation to SQL Server, automate exporting to flat file, encrypting the files when the client asks, log errors, log my machine time for billing, automate billing, and so forth and so on. Could I write it all in TSQL? No clue at all, but I can tell you that IF IT IS POSSIBLE, it would take me years to get good enough to write a reliable system in TSQL. It will take me weeks of coding to do it in VBA but it will look and work like modern software when I am done. Harness the power of SQL Server for what it does best, and the power of .Net for what it does best. You know as well as I that there is no one tool that does everything. RIGHT NOW, for the next few weeks, I need a quick and dirty script. And I can tell you that it is extremely unlikely that BOL will ever be my friend. My job does not require BOL. As for not knowing how to drive... That is plain silly. I am criticizing the car for having no dashboard. Sorry, but the dash board is missing. It has an immensely powerful engine, I will hand you that. And as you and many others have pointed out, I can go BUY a dashboard from other companies. I am just trying to get some quick things done, EASY things... IF you have been doing SQL Server admin for 10 years. The dashboard is missing. In the end I will use VB.Net to build a custom dashboard but in the here and now, quick and dirty the lack of a dashboard simply reminds me how stone age the tool is. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Tuesday, March 25, 2008 7:21 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a store procedureorfunction John, You "used" to write databases. and that "Used To" mean you wrote "SQL" code. Granted that Access SQL is nowhere in the realm of TSQL, but neither is TSQL and VBA, even though you can practically do it all from TSQL (but you would not want to). BOL is a manual you "Have To" learn to use. I say "Have To" because as long as you plan on using Sql Server, you should plan on making BOL and Google your best friend. There are many things that I am constantly learning about this engine, and I've been working on as an Administrator for over 5 years. You can't know everything, and it's great that resources such as this list and the internet exists. The term "Amazingly useful" is a subjective term. However the kindness you receive despite your spammer database is more "amazing useful" than I ever thought you'd get. I mean more power to you that you are banking in on your knowledge of databases and explotation of people's personal information and putting it to good use to make good $$. In programming (not just VB) there are many roads on how to get there. Not all of them are bad choices, some just make more logical sense. btw, Critizing the car because the driver doesn't know how to drive is also useless. -- Francisco _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2972 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Tue Mar 25 20:26:28 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 21:26:28 -0400 Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedureor function In-Reply-To: <00ea01c88ed1$3a793470$af6b9d50$@com> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90> <006c01c88eb3$dc315590$949400b0$@com><00b701c88eba$241e0eb0$0201a8c0@M90> <00ea01c88ed1$3a793470$af6b9d50$@com> Message-ID: <00be01c88ee0$6b393970$0201a8c0@M90> Paul, You have been immensely helpful already, and I certainly don't mean to denigrate your abilities. You obviously know your stuff. I understand data store concepts but the BE is just one (small) part of an application. I have designed systems with hundreds of tables, one such system was used by a company that built cell towers, start to finish, from buying / leasing land to constructing the towers, to maintaining the systems once built. It had FIVE completely different Fes for different divisions of the company. Another such system is an entire call center for a company that handles disability insurance claims. The point is that the data store is just part of the whole thing and while it is AN important part, it is only ONE important part. It would appear that you have focused on the data store and getting that down to an art, and I applaud your abilities, but the tools you need are not the tools I need. That is all I am saying. I am here on this forum as a know nothing nubee, who will NEVER know 1/100th what you know ABOUT SQL SERVER. That is just reality and I am not sad about that. I love what I do just like you love what you do. I just need someone's help figuring out the tiny little pieces that I need SQL Server to do. Trying to make me a SQL Server guru is like trying to teach the pig to sing. It isn't going to happen, and it pisses off the pig. And yea, I am more than a little unhappy about how hard it is to do the slightest little thing in SQL Server. I have to tell you, I have spent more time getting less done in SQL Server than I have spent getting a whole load done in .NET, and I have to also say that .Net is a complex system. Just the nature of the beast I guess. Luckily I have a raft of very knowledgeable people on this list to help me figure this stuff out and get back to what I should be doing. Thanks again for all your help as well as the suggestions from everyone else on the list. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 7:38 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedureor function Hi John, Sounds like you have a lot to do. I build entire SQL Server back-ends in days/weeks much like you've figured out the best way to build entire Access apps in days/weeks. I was trying to show you the fastest and safest way to develop client-server code and then deploy across multiple servers. Moving databases or objects using back-ups or scripting out objects saved only in the database is a real pain and error prone. Coding with SSMS/Query Editor and then saving the script makes it easier and faster. But if that's not style, no problem. If you ever do need a proc written or any T-SQL help, I'd love to help you, Cheers, -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:52 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] QLRE: Copy a database usinga storeprocedure orfunction No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, c++bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pauln at sqlserverbible.com Tue Mar 25 21:19:23 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 20:19:23 -0600 Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedureor function In-Reply-To: <00be01c88ee0$6b393970$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90> <006c01c88eb3$dc315590$949400b0$@com><00b701c88eba$241e0eb0$0201a8c0@M90> <00ea01c88ed1$3a793470$af6b9d50$@com> <00be01c88ee0$6b393970$0201a8c0@M90> Message-ID: <007701c88ee7$cf5b35f0$6e11a1d0$@com> Hi John, The irony is that the other discussion I've been involved in is a long thread in the SQL Server MVP newsgroups about how the SQL Server tools have become so sophisticated that there may not be as much of a need for SQL Server gurus in the future. So it's all a matter of perspective. That and we're all just a bit too busy. And so I must crank up the LotR soundtrack, motivate myself, and get back to the book. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 7:26 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedureor function Paul, You have been immensely helpful already, and I certainly don't mean to denigrate your abilities. You obviously know your stuff. I understand data store concepts but the BE is just one (small) part of an application. I have designed systems with hundreds of tables, one such system was used by a company that built cell towers, start to finish, from buying / leasing land to constructing the towers, to maintaining the systems once built. It had FIVE completely different Fes for different divisions of the company. Another such system is an entire call center for a company that handles disability insurance claims. The point is that the data store is just part of the whole thing and while it is AN important part, it is only ONE important part. It would appear that you have focused on the data store and getting that down to an art, and I applaud your abilities, but the tools you need are not the tools I need. That is all I am saying. I am here on this forum as a know nothing nubee, who will NEVER know 1/100th what you know ABOUT SQL SERVER. That is just reality and I am not sad about that. I love what I do just like you love what you do. I just need someone's help figuring out the tiny little pieces that I need SQL Server to do. Trying to make me a SQL Server guru is like trying to teach the pig to sing. It isn't going to happen, and it pisses off the pig. And yea, I am more than a little unhappy about how hard it is to do the slightest little thing in SQL Server. I have to tell you, I have spent more time getting less done in SQL Server than I have spent getting a whole load done in .NET, and I have to also say that .Net is a complex system. Just the nature of the beast I guess. Luckily I have a raft of very knowledgeable people on this list to help me figure this stuff out and get back to what I should be doing. Thanks again for all your help as well as the suggestions from everyone else on the list. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 7:38 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedureor function Hi John, Sounds like you have a lot to do. I build entire SQL Server back-ends in days/weeks much like you've figured out the best way to build entire Access apps in days/weeks. I was trying to show you the fastest and safest way to develop client-server code and then deploy across multiple servers. Moving databases or objects using back-ups or scripting out objects saved only in the database is a real pain and error prone. Coding with SSMS/Query Editor and then saving the script makes it easier and faster. But if that's not style, no problem. If you ever do need a proc written or any T-SQL help, I'd love to help you, Cheers, -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:52 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] QLRE: Copy a database usinga storeprocedure orfunction No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, c++bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2972 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From jwcolby at colbyconsulting.com Tue Mar 25 22:12:34 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 25 Mar 2008 23:12:34 -0400 Subject: [dba-SQLServer] QLRE: Copy a database using astored procedureor function In-Reply-To: <007701c88ee7$cf5b35f0$6e11a1d0$@com> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90> <004501c88ead$ea8c2a80$bfa47f80$@com><00b601c88eb1$d2bf09f0$0201a8c0@M90> <006c01c88eb3$dc315590$949400b0$@com><00b701c88eba$241e0eb0$0201a8c0@M90> <00ea01c88ed1$3a793470$af6b9d50$@com><00be01c88ee0$6b393970$0201a8c0@M90> <007701c88ee7$cf5b35f0$6e11a1d0$@com> Message-ID: <00c501c88eef$3cf73120$0201a8c0@M90> Lol. There is more to administering a complex database than a tool. The tools can bring greater usability lower down the spectrum though. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 10:19 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using astored procedureor function Hi John, The irony is that the other discussion I've been involved in is a long thread in the SQL Server MVP newsgroups about how the SQL Server tools have become so sophisticated that there may not be as much of a need for SQL Server gurus in the future. So it's all a matter of perspective. That and we're all just a bit too busy. And so I must crank up the LotR soundtrack, motivate myself, and get back to the book. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 7:26 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedureor function Paul, You have been immensely helpful already, and I certainly don't mean to denigrate your abilities. You obviously know your stuff. I understand data store concepts but the BE is just one (small) part of an application. I have designed systems with hundreds of tables, one such system was used by a company that built cell towers, start to finish, from buying / leasing land to constructing the towers, to maintaining the systems once built. It had FIVE completely different Fes for different divisions of the company. Another such system is an entire call center for a company that handles disability insurance claims. The point is that the data store is just part of the whole thing and while it is AN important part, it is only ONE important part. It would appear that you have focused on the data store and getting that down to an art, and I applaud your abilities, but the tools you need are not the tools I need. That is all I am saying. I am here on this forum as a know nothing nubee, who will NEVER know 1/100th what you know ABOUT SQL SERVER. That is just reality and I am not sad about that. I love what I do just like you love what you do. I just need someone's help figuring out the tiny little pieces that I need SQL Server to do. Trying to make me a SQL Server guru is like trying to teach the pig to sing. It isn't going to happen, and it pisses off the pig. And yea, I am more than a little unhappy about how hard it is to do the slightest little thing in SQL Server. I have to tell you, I have spent more time getting less done in SQL Server than I have spent getting a whole load done in .NET, and I have to also say that .Net is a complex system. Just the nature of the beast I guess. Luckily I have a raft of very knowledgeable people on this list to help me figure this stuff out and get back to what I should be doing. Thanks again for all your help as well as the suggestions from everyone else on the list. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 7:38 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedureor function Hi John, Sounds like you have a lot to do. I build entire SQL Server back-ends in days/weeks much like you've figured out the best way to build entire Access apps in days/weeks. I was trying to show you the fastest and safest way to develop client-server code and then deploy across multiple servers. Moving databases or objects using back-ups or scripting out objects saved only in the database is a real pain and error prone. Coding with SSMS/Query Editor and then saving the script makes it easier and faster. But if that's not style, no problem. If you ever do need a proc written or any T-SQL help, I'd love to help you, Cheers, -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:52 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] QLRE: Copy a database usinga storeprocedure orfunction No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, c++bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2972 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Wed Mar 26 02:30:58 2008 From: ebarro at verizon.net (Eric Barro) Date: Wed, 26 Mar 2008 00:30:58 -0700 Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedure or function In-Reply-To: <00ea01c88ed1$3a793470$af6b9d50$@com> Message-ID: <0JYB00H5XUD91O52@vms040.mailsrvcs.net> Paul, Are you the author of the SQL Bible book? http://www.amazon.com/Server-2005-Bible-Paul-Nielsen/dp/0764542567/ref=pd_bb s_1?ie=UTF8&s=books&qid=1206516605&sr=8-1 Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:38 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedure or function Hi John, Sounds like you have a lot to do. I build entire SQL Server back-ends in days/weeks much like you've figured out the best way to build entire Access apps in days/weeks. I was trying to show you the fastest and safest way to develop client-server code and then deploy across multiple servers. Moving databases or objects using back-ups or scripting out objects saved only in the database is a real pain and error prone. Coding with SSMS/Query Editor and then saving the script makes it easier and faster. But if that's not style, no problem. If you ever do need a proc written or any T-SQL help, I'd love to help you, Cheers, -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:52 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] QLRE: Copy a database usinga storeprocedure orfunction No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, c++bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pauln at sqlserverbible.com Wed Mar 26 08:22:35 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 26 Mar 2008 07:22:35 -0600 Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedure or function In-Reply-To: <0JYB00H5XUD91O52@vms040.mailsrvcs.net> References: <00ea01c88ed1$3a793470$af6b9d50$@com> <0JYB00H5XUD91O52@vms040.mailsrvcs.net> Message-ID: <014401c88f44$757418b0$605c4a10$@com> guilty -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Wednesday, March 26, 2008 1:31 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedure or function Paul, Are you the author of the SQL Bible book? http://www.amazon.com/Server-2005-Bible-Paul-Nielsen/dp/0764542567/ref=pd_bb s_1?ie=UTF8&s=books&qid=1206516605&sr=8-1 Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:38 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] QLRE: Copy a database using a stored procedure or function Hi John, Sounds like you have a lot to do. I build entire SQL Server back-ends in days/weeks much like you've figured out the best way to build entire Access apps in days/weeks. I was trying to show you the fastest and safest way to develop client-server code and then deploy across multiple servers. Moving databases or objects using back-ups or scripting out objects saved only in the database is a real pain and error prone. Coding with SSMS/Query Editor and then saving the script makes it easier and faster. But if that's not style, no problem. If you ever do need a proc written or any T-SQL help, I'd love to help you, Cheers, -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, March 25, 2008 2:52 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] QLRE: Copy a database usinga storeprocedure orfunction No Paul, you don't get it. I don't want to code Sql server at all. I certainly don't want to edit a file on a directory in TSQL. I also don't want to go open a stall door, lead a horse out, put a harness on it, hitch it up to my wagon, climb up and sit on a board and spend the next hour bruising my butt getting three miles to the center of town. Luckily I have a car. Unfortunately I am still writing TSQL in SQL Server. When you understand how TSQL equates to a horse and wagon you will understand what I mean. You are hitching up a wagon each time you do anything in SQL Server and the sad part is, you shouldn't have to. I can build entire systems in VB or Access in a matter of days or weeks. Reams of forms, reports, queries. Code that allows me to connect to the internet, download files from an FTP site, open the files, import them into the database, export the data back out, attach them to emails and send results off to clients. Writing SQL at all is a total waste of (my) time. 15 years ago designing one single form took days and weeks of programming in c++. Now I can drag and drop objects out onto forms, set properties, c++bind them to data, enter data, see the data, report the data in hours. You are still living in the "weeks to do a form" era, and you obviously like it, and that is fine... for you. It is not fine for me because I make my living doing stuff quickly. Please, do not EVER suggest to me editing TSQL in files on a disk. The probability that I will even read the post is somewhere between 0 and negative infinity, and rapidly approaching negative infinity. I'm trying to get WORK done here. Work BTW is not writing TSQL. Work is receiving a job in an excel spreadsheet attached to an email, creating a directory structure on my hard drive to hold the pieces and parts, saving the order spreadsheet into that directory structure, copying the SQL Server template database, modifying a view in the copied database to pull the right records, exporting the data to a CSV file on an address validation server, processing that CSV file through a third party Address Validation software, reloading the cleaned data (CSV file) into SQL Server, deduping the addresses, selecting a random set N of those address, Exporting them to a flat file, marking them as exported, zipping the flat file and FTPing it or attaching it to an email, then emailing the clients telling them the order went out. All with a minimum of my time spent. It should take me 1/2 hour (of my time, MAXIMUM) to do all of that stuff. Do we see how I truly do NOT want to be writing SQL (in a file on a DISK!!!)? Do we see how spending years learning TSQL AT ALL is not in the cards? I don't want to learn TSQL, I don't want to WRITE TSQL, I want to build an application that builds my orders from a few pieces of information typed into a form, logs the processor time used for the various tasks into tables, executes the order, transmits the order to the client, computes a bill for my processing time, and emails the bill to the client. In fact I REALLY want the client to type his own damned order information into a form on the internet, and receive his order and a bill for my processor time over the internet. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 4:08 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storeprocedure orfunction Source code belongs in source code control. Developing in a gui is just plain dangerous. All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in source control. I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. It's fast, simple, and easy. In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? -Paul _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2971 (20080325) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 __________ NOD32 2974 (20080326) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From robert at webedb.com Wed Mar 26 08:21:27 2008 From: robert at webedb.com (Robert L. Stewart) Date: Wed, 26 Mar 2008 08:21:27 -0500 Subject: [dba-SQLServer] Copy a database using a stored procedure or function In-Reply-To: References: Message-ID: <200803261326.m2QDQDCJ029137@databaseadvisors.com> Paul, Probably not. John, There is no such thing as a SQL Server USER. If you do not want to hire a DBA/SQL Programmer, then you are it, like it or not. 3rd party tools are there for a reason. They were there for Access also. If you don't like the FREE tools, buy one that you do like. Since you have no idea what the previous versions of SQL Server were like, you have no reference point for the current version. I have used and programmed with SQL Server since 3.21. It has come a long, long way since then. I gave you a 2/3's completed solution, written as it should have been, in T-SQL. Stop the bitching and complaining. If you need help, you have received it from this list. But, I have to agree with Francisco, you got the help even if you are enabling spamming and junk mail. Robert At 08:25 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 19:25:44 -0600 >From: "Paul Nielsen" >Subject: Re: [dba-SQLServer] Copy a database using a store > procedureorfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <004401c88ee0$51061230$f3123690$@com> >Content-Type: text/plain; charset="us-ascii" > >But you are using version control for all source code including DDL code, >right? > >-Paul > > > > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby >Sent: Tuesday, March 25, 2008 7:03 PM >To: 'Discussion concerning MS SQL Server' >Subject: Re: [dba-SQLServer] Copy a database using a store >procedureorfunction > >I am not criticizing anybody, I am simply pointing out that there are many >different jobs. Mine is not SQL Server Administrator, nor SQL Server >programmer. Mine is SQL Server user. SQL Server is an immensely powerful >system where the human interface is just emerging from the stone age. Like >anyone familiar with the stone age tools, they are good enough to get the >job done, if you happen to be familiar with the stone age tools. If you are >familiar with high powered rifles and razor sharp knives,and airplanes to >get to the hunt, the stone age hunting tools are ... well.. Stone age. From David at sierranevada.com Wed Mar 26 10:28:58 2008 From: David at sierranevada.com (David Lewis) Date: Wed, 26 Mar 2008 08:28:58 -0700 Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedureor In-Reply-To: References: Message-ID: Hi John: I don't think this will really 'help' you at this point, but it may make it a little easier for you to accept your situation the next time you start getting annoyed... You accepted a job that requires (form the sounds of it) a full-scale rdms -- Access wouldn't fit the bill. All the functionality that Access wrapped up neatly into gui's is in sql server, but not necessarily in a gui, and generally in a much more powerful and flexible form. But, as you are discovering, each of the things you are trying to do requires quite a learning curve. That isn't the fault of sql server -- it was built for needs that presuppose a fairly deep bench. Most places that use all the functions that you are using have a person(s) that specialize in each of the functions. There is a T-sql guy, an SSIS guy, a dba for tuning, backups and restores, etc. You are wearing many hats, and all the hats are pretty sophisticated. To take a very simple example, if you are used to building queries in Access using its gui, you've got a repertoire of approaches to getting the data you want. When you move to sql server, the gui for building queries is pretty crude, and if you take the plunge and go to the screen to write raw t-sql, you begin to discover many many many t-sql commands that either you didn't know existed, or had only heard of but had never tried (I am speaking from my own experience). Many of these turn problems that in access were a pain in the neck to solve, into pretty something trivial. I am speaking of sub-queries, case statements, correllated sub-queries, derived tables, etc. etc. etc. Using these in Access is nearly impossible, or actually impossible, so Access people generally never learn to use them. At least that was my experience (I didn't learn to write t-sql until I moved to sql server, and now I shudder at the thought of having to use access' gui to build a query). This example holds true for all the tools you are trying to use. Not a pleasant or comfortable state of affairs for you, but that is the way it is. When I have found myself in a similar position in the past, for example completely stuck on how to use DTS (now SSIS), I looked for a person who could work side by side with me to get things done; in that way I was able to learn from an expert (or at least someone with a lot more experience than I). That means spending money on a consultant, and I don't know how that fits with the economics of this job, but either way you look at it you need training or help, and that generally doesn't come cheap. Hope this helps (but of course I realize it likely just pissed you off more!) David 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 jwcolby at colbyconsulting.com Wed Mar 26 10:40:56 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 11:40:56 -0400 Subject: [dba-SQLServer] Copy a database using a stored procedure orfunction In-Reply-To: <200803261326.m2QDQDCJ029137@databaseadvisors.com> References: <200803261326.m2QDQDCJ029137@databaseadvisors.com> Message-ID: <001201c88f57$c8ba7a10$0201a8c0@M90> Robert, Making judgments about what I do for a living is unhelpful and in fact downright inappropriate. Peoples careers range from terrorists to Catholic bishops. I don't see you becoming a priest. ONE thing that I do is a database for a company that sells address lists to companies that send bulk mail. I also write databases for non-profit organizations that help parents of children with disabilities. And many other databases. I am not killing people, I am filling a very valid request of a very valid company. Bitching, yea I am guilty. To say that I do not know what the previous versions are like is not true and beside the point. I know what dbaseII was like in 1985 and I expect the tools 23 years later to be superior (in user interface). SQL Server (interface) is BARELY superior to dbase II in a few areas and much worse in others. You can make excuses for the tool all you want, it still SUCKS. Call it bitching if you want, I am simply calling your favorite spade a spade. It SUCKS. Alright? Not complaining, simply stating the obvious. Having spent your entire adult life working in it may make it SEEM (to you) like it doesn't SUCK but, in fact, it SUCKS. Now, if you wish to take offense at my stating that the tool sucks, have at. Notice that Gustav pretty much also stated that the tool (interface) sucks. Rant at him a bit why don't you. The emperor has no clothes, though he remains a pretty powerful emperor. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Wednesday, March 26, 2008 9:21 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction Paul, Probably not. John, There is no such thing as a SQL Server USER. If you do not want to hire a DBA/SQL Programmer, then you are it, like it or not. 3rd party tools are there for a reason. They were there for Access also. If you don't like the FREE tools, buy one that you do like. Since you have no idea what the previous versions of SQL Server were like, you have no reference point for the current version. I have used and programmed with SQL Server since 3.21. It has come a long, long way since then. I gave you a 2/3's completed solution, written as it should have been, in T-SQL. Stop the bitching and complaining. If you need help, you have received it from this list. But, I have to agree with Francisco, you got the help even if you are enabling spamming and junk mail. Robert At 08:25 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 19:25:44 -0600 >From: "Paul Nielsen" >Subject: Re: [dba-SQLServer] Copy a database using a store > procedureorfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <004401c88ee0$51061230$f3123690$@com> >Content-Type: text/plain; charset="us-ascii" > >But you are using version control for all source code including DDL >code, right? > >-Paul > > > > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of >jwcolby >Sent: Tuesday, March 25, 2008 7:03 PM >To: 'Discussion concerning MS SQL Server' >Subject: Re: [dba-SQLServer] Copy a database using a store >procedureorfunction > >I am not criticizing anybody, I am simply pointing out that there are >many different jobs. Mine is not SQL Server Administrator, nor SQL >Server programmer. Mine is SQL Server user. SQL Server is an >immensely powerful system where the human interface is just emerging >from the stone age. Like anyone familiar with the stone age tools, >they are good enough to get the job done, if you happen to be familiar >with the stone age tools. If you are familiar with high powered rifles >and razor sharp knives,and airplanes to get to the hunt, the stone age hunting tools are ... well.. Stone age. _______________________________________________ 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 Mar 26 10:42:36 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Wed, 26 Mar 2008 08:42:36 -0700 Subject: [dba-SQLServer] Copy a database using a store procedure or function Message-ID: You complain about the lack of a dashboard, but since you are a vb.net guy that's like complaining that you've loaded visual studio but that there is no ready built applett to let you run Sql Server code, and I don't mean clicking and dragging the sql objects because that means you stlll have to add all the connection objects, as you said you just want a point and click. You're going to have to build something, many of the suggestions are valid options that you can use in you VB.net app you CAN dynamically call these different code snippetts and alter them on the fly. On 3/25/08, jwcolby wrote: > I am not criticizing anybody, I am simply pointing out that there are many > different jobs. Mine is not SQL Server Administrator, nor SQL Server > programmer. Mine is SQL Server user. SQL Server is an immensely powerful > system where the human interface is just emerging from the stone age. Like > anyone familiar with the stone age tools, they are good enough to get the > job done, if you happen to be familiar with the stone age tools. If you are > familiar with high powered rifles and razor sharp knives,and airplanes to > get to the hunt, the stone age hunting tools are ... well.. Stone age. > > I understand perfectly well that Sql server can do immensely useful things, > so can Linux. But Windows is king for a reason, having nothing to do with > the ability to get the job done, but rather to do with making the job easier > to get done. > > In fact I still do write databases. I just write them using modern tools. > I am in the process of writing a complex system with dozens of tables to > track clients, jobs, orders, billing etc, all with the data store in SQL > Server. I would not consider writing the application as TSQL in files on > the disk. Sorry, ain't happening. I am using VB.Net, with libraries to > allow me to automate getting at the email attachments, read order data out > of spreadsheets (my client's requirements), automate building disk > structures, automate exporting data out to CSVs for the address validation, > automate directory watching to sense when the files pop back out of the > address validation software, automate reimportation to SQL Server, automate > exporting to flat file, encrypting the files when the client asks, log > errors, log my machine time for billing, automate billing, and so forth and > so on. > > Could I write it all in TSQL? No clue at all, but I can tell you that IF IT > IS POSSIBLE, it would take me years to get good enough to write a reliable > system in TSQL. It will take me weeks of coding to do it in VBA but it will > look and work like modern software when I am done. Harness the power of SQL > Server for what it does best, and the power of .Net for what it does best. > You know as well as I that there is no one tool that does everything. > > RIGHT NOW, for the next few weeks, I need a quick and dirty script. And I > can tell you that it is extremely unlikely that BOL will ever be my friend. > My job does not require BOL. > > As for not knowing how to drive... That is plain silly. > > I am criticizing the car for having no dashboard. Sorry, but the dash board > is missing. It has an immensely powerful engine, I will hand you that. And > as you and many others have pointed out, I can go BUY a dashboard from other > companies. I am just trying to get some quick things done, EASY things... > IF you have been doing SQL Server admin for 10 years. > > The dashboard is missing. In the end I will use VB.Net to build a custom > dashboard but in the here and now, quick and dirty the lack of a dashboard > simply reminds me how stone age the tool is. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco > Tapia > Sent: Tuesday, March 25, 2008 7:21 PM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Copy a database using a store > procedureorfunction > > John, > You "used" to write databases. and that "Used To" mean you wrote "SQL" > code. Granted that Access SQL is nowhere in the realm of TSQL, but neither > is TSQL and VBA, even though you can practically do it all from TSQL (but > you would not want to). BOL is a manual you "Have To" learn to use. I say > "Have To" because as long as you plan on using Sql Server, you should plan > on making BOL and Google your best friend. There are many things that I am > constantly learning about this engine, and I've been working on as an > Administrator for over 5 years. You can't know everything, and it's great > that resources such as this list and the internet exists. > > The term "Amazingly useful" is a subjective term. However the kindness you > receive despite your spammer database is more "amazing useful" than I ever > thought you'd get. I mean more power to you that you are banking in on your > knowledge of databases and explotation of people's personal information and > putting it to good use to make good $$. In programming (not just VB) there > are many roads on how to get there. Not all of them are bad choices, some > just make more logical sense. btw, Critizing the car because the driver > doesn't know how to drive is also useless. > > > -- > Francisco > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- Sent from Gmail for mobile | mobile.google.com -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Wed Mar 26 10:43:15 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 11:43:15 -0400 Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedureor In-Reply-To: References: Message-ID: <001301c88f58$1bf145b0$0201a8c0@M90> LOL, no you didn't piss me off more. I know all of what you are saying. And the members of this list, while irritated that I state the obvious, have been an immense help. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Wednesday, March 26, 2008 11:29 AM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedureor Hi John: I don't think this will really 'help' you at this point, but it may make it a little easier for you to accept your situation the next time you start getting annoyed... You accepted a job that requires (form the sounds of it) a full-scale rdms -- Access wouldn't fit the bill. All the functionality that Access wrapped up neatly into gui's is in sql server, but not necessarily in a gui, and generally in a much more powerful and flexible form. But, as you are discovering, each of the things you are trying to do requires quite a learning curve. That isn't the fault of sql server -- it was built for needs that presuppose a fairly deep bench. Most places that use all the functions that you are using have a person(s) that specialize in each of the functions. There is a T-sql guy, an SSIS guy, a dba for tuning, backups and restores, etc. You are wearing many hats, and all the hats are pretty sophisticated. To take a very simple example, if you are used to building queries in Access using its gui, you've got a repertoire of approaches to getting the data you want. When you move to sql server, the gui for building queries is pretty crude, and if you take the plunge and go to the screen to write raw t-sql, you begin to discover many many many t-sql commands that either you didn't know existed, or had only heard of but had never tried (I am speaking from my own experience). Many of these turn problems that in access were a pain in the neck to solve, into pretty something trivial. I am speaking of sub-queries, case statements, correllated sub-queries, derived tables, etc. etc. etc. Using these in Access is nearly impossible, or actually impossible, so Access people generally never learn to use them. At least that was my experience (I didn't learn to write t-sql until I moved to sql server, and now I shudder at the thought of having to use access' gui to build a query). This example holds true for all the tools you are trying to use. Not a pleasant or comfortable state of affairs for you, but that is the way it is. When I have found myself in a similar position in the past, for example completely stuck on how to use DTS (now SSIS), I looked for a person who could work side by side with me to get things done; in that way I was able to learn from an expert (or at least someone with a lot more experience than I). That means spending money on a consultant, and I don't know how that fits with the economics of this job, but either way you look at it you need training or help, and that generally doesn't come cheap. Hope this helps (but of course I realize it likely just pissed you off more!) David 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 ebarro at verizon.net Wed Mar 26 11:10:03 2008 From: ebarro at verizon.net (Eric Barro) Date: Wed, 26 Mar 2008 11:10:03 -0500 (CDT) Subject: [dba-SQLServer] Copy a database using a stored procedure orfunction Message-ID: <19187861.515221206547803130.JavaMail.root@vms124.mailsrvcs.net> So...John, you are making us all contribute to this company's junk mail processing engine that could eventually end up in our doorsteps? ;) >ONE thing that I do is a database for a company that sells address lists to companies that send bulk mail. John W. Colby Colby Consulting www.ColbyConsulting.com From pauln at sqlserverbible.com Tue Mar 25 11:00:55 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Tue, 25 Mar 2008 10:00:55 -0600 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: <005b01c88dfc$d280f1c0$0201a8c0@M90> References: <005b01c88dfc$d280f1c0$0201a8c0@M90> Message-ID: <000001c88e91$69be9940$3d3bcbc0$@com> Hi John, Here's a chapter on sprocs. It's not the greatest chapter, but the section on return data scope is useful. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 24, 2008 4:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Returning a dataset A stored procedure can return a data set correct? Is that data set updateable? I need to run a stored procedure, where I pass in the Value for the TOP N (the N part) and then build up a SQL statement and execute that inside of the sp. That sp needs to return the data set to another SP, and that SP has to update a field in the data set returned by the first sp. Is this possible? ATM I have a view called TopN, which returns a date field. I have a query that updates that date field to today's date. The problem is that the TopN view is hard coded with a number (30000 for today's order) but that value could be any number. So I need to turn the view into a SP where I can pass in the number of records to update and then pass the set up date fields back to an update SP to do the update. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2968 (20080324) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Wed Mar 26 11:15:54 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 26 Mar 2008 10:15:54 -0600 Subject: [dba-SQLServer] Copy a database using a stored procedure orfunction In-Reply-To: <19187861.515221206547803130.JavaMail.root@vms124.mailsrvcs.net> References: <19187861.515221206547803130.JavaMail.root@vms124.mailsrvcs.net> Message-ID: <000c01c88f5c$ad1c10c0$07543240$@com> John, So if we help you can you purge our names from the list? -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Wednesday, March 26, 2008 10:10 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction So...John, you are making us all contribute to this company's junk mail processing engine that could eventually end up in our doorsteps? ;) >ONE thing that I do is a database for a company that sells address lists to companies that send bulk mail. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2975 (20080326) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From Gustav at cactus.dk Wed Mar 26 12:20:11 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 26 Mar 2008 18:20:11 +0100 Subject: [dba-SQLServer] Copy a database using a stored procedure or function Message-ID: Hi John, Robert, Paul et al We use SQL Server as a data store and not as an "application". I'm a firm believer that only low-level logic should be handled by the engine while any high-level business-rule-style logic belongs to a middle-tier or the frontend or - if that is not possible - should be fully maintained by and controlled from either of these. One reason for this is exactly what you are arguing about, that it takes a life's work to become an excellent T-SQL programmer and neither I nor the company I work for can allocate such resources. Also, this discussion reminds me of the days of DOS. I cannot count how many batch files I wrote in the eighties and nineties for just about anything including full screen login systems for NetWare and sophisticated menu systems. PC Magazine in those days had a column of advanced batch programming often beyond belief. I've kept it all somewhere, but since Windows 95 arrived it has never been used and users stopped requesting such services. I will never be used again, but this is where I understand John; when I go to that SQL editor it is close to typing in Edlin - you only miss the piping! Wow, that was great (wiping a small tear). When you move to VS and its great environment you feel the difference. Having worked with the manager of version 6.5 years back, however, the current manager represents a vast improvement, and it is quite nice that you can run it together with Visual Studio which overlaps quite a lot while you have the same look and feel. /gustav >>> jwcolby at colbyconsulting.com 26-03-2008 16:40:56 >>> Robert, Making judgments about what I do for a living is unhelpful and in fact downright inappropriate. Peoples careers range from terrorists to Catholic bishops. I don't see you becoming a priest. ONE thing that I do is a database for a company that sells address lists to companies that send bulk mail. I also write databases for non-profit organizations that help parents of children with disabilities. And many other databases. I am not killing people, I am filling a very valid request of a very valid company. Bitching, yea I am guilty. To say that I do not know what the previous versions are like is not true and beside the point. I know what dbaseII was like in 1985 and I expect the tools 23 years later to be superior (in user interface). SQL Server (interface) is BARELY superior to dbase II in a few areas and much worse in others. You can make excuses for the tool all you want, it still SUCKS. Call it bitching if you want, I am simply calling your favorite spade a spade. It SUCKS. Alright? Not complaining, simply stating the obvious. Having spent your entire adult life working in it may make it SEEM (to you) like it doesn't SUCK but, in fact, it SUCKS. Now, if you wish to take offense at my stating that the tool sucks, have at. Notice that Gustav pretty much also stated that the tool (interface) sucks. Rant at him a bit why don't you. The emperor has no clothes, though he remains a pretty powerful emperor. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Wednesday, March 26, 2008 9:21 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction Paul, Probably not. John, There is no such thing as a SQL Server USER. If you do not want to hire a DBA/SQL Programmer, then you are it, like it or not. 3rd party tools are there for a reason. They were there for Access also. If you don't like the FREE tools, buy one that you do like. Since you have no idea what the previous versions of SQL Server were like, you have no reference point for the current version. I have used and programmed with SQL Server since 3.21. It has come a long, long way since then. I gave you a 2/3's completed solution, written as it should have been, in T-SQL. Stop the bitching and complaining. If you need help, you have received it from this list. But, I have to agree with Francisco, you got the help even if you are enabling spamming and junk mail. Robert At 08:25 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 19:25:44 -0600 >From: "Paul Nielsen" >Subject: Re: [dba-SQLServer] Copy a database using a store > procedureorfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <004401c88ee0$51061230$f3123690$@com> >Content-Type: text/plain; charset="us-ascii" > >But you are using version control for all source code including DDL >code, right? > >-Paul > > > > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of >jwcolby >Sent: Tuesday, March 25, 2008 7:03 PM >To: 'Discussion concerning MS SQL Server' >Subject: Re: [dba-SQLServer] Copy a database using a store >procedureorfunction > >I am not criticizing anybody, I am simply pointing out that there are >many different jobs. Mine is not SQL Server Administrator, nor SQL >Server programmer. Mine is SQL Server user. SQL Server is an >immensely powerful system where the human interface is just emerging >from the stone age. Like anyone familiar with the stone age tools, >they are good enough to get the job done, if you happen to be familiar >with the stone age tools. If you are familiar with high powered rifles >and razor sharp knives,and airplanes to get to the hunt, the stone age hunting tools are ... well.. Stone age. From ebarro at verizon.net Wed Mar 26 13:17:20 2008 From: ebarro at verizon.net (Eric Barro) Date: Wed, 26 Mar 2008 13:17:20 -0500 (CDT) Subject: [dba-SQLServer] Copy a database using a stored procedure or function Message-ID: <8572573.1248051206555440792.JavaMail.root@vms229.mailsrvcs.net> Gustav, It's no different than moving from dBASE to Access and then from Access to SQL server. Access changed the programming paradigm from what we were used to in dBASE to an event-driven paradigm. The simplest things that one could do with dBASE code was such a pain to figure out with Access 1.0 since the paradigm shifted to an event-driven approach. There was a learning curve to overcome. Ditto when moving from Access which spoiled us with the GUI drag and drop functionality for querying data. Enterprise Manager for SQL server was such a pain to grasp simply because SQL server wasn't made to have a GUI. I hated the idea that SQL server didn't have the same GUI that Access had...after all, it was made by the same company -- Micro$oft. But oftentimes the GUI just gets in the way. Same deal with Sharepoint. I'm a nuts and bolts type of guy who likes to "peek under the hood" to see how the "engine" is working its magic. The GUI becomes a better tool if you know exactly how things work "under the hood". Stored procedures, user-defined functions that return either values or result sets, temporary tables and temporary table variables, data partioning, scheduled jobs, role-based security (integrated with windows or native sql server), full-text cataloging for search engine-like functionality, support for VB, scripting objects, replication, etc... -- these are the things that make SQL server the workhorse it is. Sure it takes time to learn these and be good at it. But isn't that true with the other products (dBASE, Access, etc..)? If we really wanted something simple and easy to use, why not buy a MAC? Eric --------------------------------------------------- From: Gustav Brock Date: 2008/03/26 Wed PM 12:20:11 CDT To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure or function Hi John, Robert, Paul et al We use SQL Server as a data store and not as an "application". I'm a firm believer that only low-level logic should be handled by the engine while any high-level business-rule-style logic belongs to a middle-tier or the frontend or - if that is not possible - should be fully maintained by and controlled from either of these. One reason for this is exactly what you are arguing about, that it takes a life's work to become an excellent T-SQL programmer and neither I nor the company I work for can allocate such resources. Also, this discussion reminds me of the days of DOS. I cannot count how many batch files I wrote in the eighties and nineties for just about anything including full screen login systems for NetWare and sophisticated menu systems. PC Magazine in those days had a column of advanced batch programming often beyond belief. I've kept it all somewhere, but since Windows 95 arrived it has never been used and users stopped requesting such services. I will never be used again, but this is where I understand John; when I go to that SQL editor it is close to typing in Edlin - you only miss the piping! Wow, that was great (wiping a small tear). When you move to VS and its great environment you feel the difference. Having worked with the manager of version 6.5 years back, however, the current manager represents a vast improvement, and it is quite nice that you can run it together with Visual Studio which overlaps quite a lot while you have the same look and feel. /gustav >>> jwcolby at colbyconsulting.com 26-03-2008 16:40:56 >>> Robert, Making judgments about what I do for a living is unhelpful and in fact downright inappropriate. Peoples careers range from terrorists to Catholic bishops. I don't see you becoming a priest. ONE thing that I do is a database for a company that sells address lists to companies that send bulk mail. I also write databases for non-profit organizations that help parents of children with disabilities. And many other databases. I am not killing people, I am filling a very valid request of a very valid company. Bitching, yea I am guilty. To say that I do not know what the previous versions are like is not true and beside the point. I know what dbaseII was like in 1985 and I expect the tools 23 years later to be superior (in user interface). SQL Server (interface) is BARELY superior to dbase II in a few areas and much worse in others. You can make excuses for the tool all you want, it still SUCKS. Call it bitching if you want, I am simply calling your favorite spade a spade. It SUCKS. Alright? Not complaining, simply stating the obvious. Having spent your entire adult life working in it may make it SEEM (to you) like it doesn't SUCK but, in fact, it SUCKS. Now, if you wish to take offense at my stating that the tool sucks, have at. Notice that Gustav pretty much also stated that the tool (interface) sucks. Rant at him a bit why don't you. The emperor has no clothes, though he remains a pretty powerful emperor. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Wednesday, March 26, 2008 9:21 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction Paul, Probably not. John, There is no such thing as a SQL Server USER. If you do not want to hire a DBA/SQL Programmer, then you are it, like it or not. 3rd party tools are there for a reason. They were there for Access also. If you don't like the FREE tools, buy one that you do like. Since you have no idea what the previous versions of SQL Server were like, you have no reference point for the current version. I have used and programmed with SQL Server since 3.21. It has come a long, long way since then. I gave you a 2/3's completed solution, written as it should have been, in T-SQL. Stop the bitching and complaining. If you need help, you have received it from this list. But, I have to agree with Francisco, you got the help even if you are enabling spamming and junk mail. Robert At 08:25 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 19:25:44 -0600 >From: "Paul Nielsen" >Subject: Re: [dba-SQLServer] Copy a database using a store > procedureorfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <004401c88ee0$51061230$f3123690$@com> >Content-Type: text/plain; charset="us-ascii" > >But you are using version control for all source code including DDL >code, right? > >-Paul > > > > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of >jwcolby >Sent: Tuesday, March 25, 2008 7:03 PM >To: 'Discussion concerning MS SQL Server' >Subject: Re: [dba-SQLServer] Copy a database using a store >procedureorfunction > >I am not criticizing anybody, I am simply pointing out that there are >many different jobs. Mine is not SQL Server Administrator, nor SQL >Server programmer. Mine is SQL Server user. SQL Server is an >immensely powerful system where the human interface is just emerging >from the stone age. Like anyone familiar with the stone age tools, >they are good enough to get the job done, if you happen to be familiar >with the stone age tools. If you are familiar with high powered rifles >and razor sharp knives,and airplanes to get to the hunt, the stone age hunting tools are ... well.. Stone age. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From robert at webedb.com Wed Mar 26 14:51:09 2008 From: robert at webedb.com (Robert L. Stewart) Date: Wed, 26 Mar 2008 14:51:09 -0500 Subject: [dba-SQLServer] Copy a database using a stored procedure or function In-Reply-To: References: Message-ID: <200803261956.m2QJujvq001878@databaseadvisors.com> John, What I take offense with is the attitude of "Help me, but let me rant about how difficult it is." A priest no. But at one time, I was a licensed minister in one of the mainstream denominations. :-) Spam and junk mail are never valid. Think of the trees and bandwidth wasted. Ask the questions and leave the commentary out. You have your expertise at classes, etc in Access. I have a lot of experience there also. I have a client management system, DB in SQL Server, that I have developed over the last 10+ years. A number of social service agencies use it. When I chose to use SQL Server, I did not whine about how hard it was to use. Now, as a DBA and SQL programmer, I continue to be amazed at what SQL Server can do. And, I still do some of my FE work in Access, but am moving to .Net for that. Comparing SQL Server to dBase II is like comparing a skateboard to a Cadillac. Everything evolves in the programming world. Just not at the speed you want it to. Robert At 10:41 AM 3/26/2008, you wrote: >Date: Wed, 26 Mar 2008 11:40:56 -0400 >From: "jwcolby" >Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <001201c88f57$c8ba7a10$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >Robert, > >Making judgments about what I do for a living is unhelpful and in fact >downright inappropriate. Peoples careers range from terrorists to Catholic >bishops. I don't see you becoming a priest. ONE thing that I do is a >database for a company that sells address lists to companies that send bulk >mail. I also write databases for non-profit organizations that help parents >of children with disabilities. And many other databases. I am not killing >people, I am filling a very valid request of a very valid company. > >Bitching, yea I am guilty. > >To say that I do not know what the previous versions are like is not true >and beside the point. I know what dbaseII was like in 1985 and I expect the >tools 23 years later to be superior (in user interface). SQL Server >(interface) is BARELY superior to dbase II in a few areas and much worse in >others. You can make excuses for the tool all you want, it still SUCKS. >Call it bitching if you want, I am simply calling your favorite spade a >spade. It SUCKS. Alright? Not complaining, simply stating the obvious. >Having spent your entire adult life working in it may make it SEEM (to you) >like it doesn't SUCK but, in fact, it SUCKS. > >Now, if you wish to take offense at my stating that the tool sucks, have at. >Notice that Gustav pretty much also stated that the tool (interface) sucks. >Rant at him a bit why don't you. > >The emperor has no clothes, though he remains a pretty powerful emperor. > >John W. Colby From jwcolby at colbyconsulting.com Wed Mar 26 15:05:27 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 16:05:27 -0400 Subject: [dba-SQLServer] Copy a database using a storedprocedure orfunction In-Reply-To: <19187861.515221206547803130.JavaMail.root@vms124.mailsrvcs.net> References: <19187861.515221206547803130.JavaMail.root@vms124.mailsrvcs.net> Message-ID: <003001c88f7c$bcaf7070$0201a8c0@M90> Uhhhh yep. ;-) He actually makes a good point though. He says that junk mail is only junk mail if you don't want it. My client is trying very hard to match the lists to exactly people who have purchased such stuff in the past. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Wednesday, March 26, 2008 12:10 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a storedprocedure orfunction So...John, you are making us all contribute to this company's junk mail processing engine that could eventually end up in our doorsteps? ;) >ONE thing that I do is a database for a company that sells address >lists to companies that send bulk mail. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 Mar 26 15:07:20 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 16:07:20 -0400 Subject: [dba-SQLServer] Copy a database using astored procedure orfunction In-Reply-To: <000c01c88f5c$ad1c10c0$07543240$@com> References: <19187861.515221206547803130.JavaMail.root@vms124.mailsrvcs.net> <000c01c88f5c$ad1c10c0$07543240$@com> Message-ID: <003101c88f7c$ffbfdda0$0201a8c0@M90> LOL. I could. To be honest I don't even look at the names. There are anywhere from 50 to 150 million in each list. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Wednesday, March 26, 2008 12:16 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using astored procedure orfunction John, So if we help you can you purge our names from the list? -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Wednesday, March 26, 2008 10:10 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction So...John, you are making us all contribute to this company's junk mail processing engine that could eventually end up in our doorsteps? ;) >ONE thing that I do is a database for a company that sells address >lists to companies that send bulk mail. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2975 (20080326) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ 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 Mar 26 15:17:42 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 16:17:42 -0400 Subject: [dba-SQLServer] Copy a database using a storedprocedure or function In-Reply-To: <8572573.1248051206555440792.JavaMail.root@vms229.mailsrvcs.net> References: <8572573.1248051206555440792.JavaMail.root@vms229.mailsrvcs.net> Message-ID: <003201c88f7e$73161f20$0201a8c0@M90> Eric, Part of the problem though is that SQL Server can do many different things. I don't need any of the stuff you mentioned. My lists are not relational, they are one long wide list. I split off the name and address and maintain that as a separate list but still not parent / child, rather 1-1. I don't need all that stuff but I DO need sql server. It is the only thing powerful enough to process a list of 100 million names with 150 fields and indexes etc. So my point is that I really and truly DO NOT NEED all of that stuff. I need a small handful of concepts, most of which I have already learned. I am here now trying to copy a database (for example). Never got that far. I do not want, nor do I need a gigabyte disk full of directories full of sql statements all neatly cataloged. I just need a small template database with about 30 views and 20 stored procedures. Someday soon I will not even need that as I move my logic to .NET but right now I do. So telling me to go memorize BOL is simply a dreadful and unrealistic response to my questions. Even if I could, I would never use it again in the next two years and what would be the point of all that effort? You really and truly need to get that there are an entire spectrum of uses for SQL Server from an IBM to a tiny 5 man virtual company processing address lists. I have to know 10 times as much stuff ENTIRELY UNRELATED TO SQL SERVER as I do stuff related to sql server, just to handle the little address list company. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Wednesday, March 26, 2008 2:17 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a storedprocedure or function Gustav, It's no different than moving from dBASE to Access and then from Access to SQL server. Access changed the programming paradigm from what we were used to in dBASE to an event-driven paradigm. The simplest things that one could do with dBASE code was such a pain to figure out with Access 1.0 since the paradigm shifted to an event-driven approach. There was a learning curve to overcome. Ditto when moving from Access which spoiled us with the GUI drag and drop functionality for querying data. Enterprise Manager for SQL server was such a pain to grasp simply because SQL server wasn't made to have a GUI. I hated the idea that SQL server didn't have the same GUI that Access had...after all, it was made by the same company -- Micro$oft. But oftentimes the GUI just gets in the way. Same deal with Sharepoint. I'm a nuts and bolts type of guy who likes to "peek under the hood" to see how the "engine" is working its magic. The GUI becomes a better tool if you know exactly how things work "under the hood". Stored procedures, user-defined functions that return either values or result sets, temporary tables and temporary table variables, data partioning, scheduled jobs, role-based security (integrated with windows or native sql server), full-text cataloging for search engine-like functionality, support for VB, scripting objects, replication, etc... -- these are the things that make SQL server the workhorse it is. Sure it takes time to learn these and be good at it. But isn't that true with the other products (dBASE, Access, etc..)? If we really wanted something simple and easy to use, why not buy a MAC? Eric --------------------------------------------------- From: Gustav Brock Date: 2008/03/26 Wed PM 12:20:11 CDT To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure or function Hi John, Robert, Paul et al We use SQL Server as a data store and not as an "application". I'm a firm believer that only low-level logic should be handled by the engine while any high-level business-rule-style logic belongs to a middle-tier or the frontend or - if that is not possible - should be fully maintained by and controlled from either of these. One reason for this is exactly what you are arguing about, that it takes a life's work to become an excellent T-SQL programmer and neither I nor the company I work for can allocate such resources. Also, this discussion reminds me of the days of DOS. I cannot count how many batch files I wrote in the eighties and nineties for just about anything including full screen login systems for NetWare and sophisticated menu systems. PC Magazine in those days had a column of advanced batch programming often beyond belief. I've kept it all somewhere, but since Windows 95 arrived it has never been used and users stopped requesting such services. I will never be used again, but this is where I understand John; when I go to that SQL editor it is close to typing in Edlin - you only miss the piping! Wow, that was great (wiping a small tear). When you move to VS and its great environment you feel the difference. Having worked with the manager of version 6.5 years back, however, the current manager represents a vast improvement, and it is quite nice that you can run it together with Visual Studio which overlaps quite a lot while you have the same look and feel. /gustav >>> jwcolby at colbyconsulting.com 26-03-2008 16:40:56 >>> Robert, Making judgments about what I do for a living is unhelpful and in fact downright inappropriate. Peoples careers range from terrorists to Catholic bishops. I don't see you becoming a priest. ONE thing that I do is a database for a company that sells address lists to companies that send bulk mail. I also write databases for non-profit organizations that help parents of children with disabilities. And many other databases. I am not killing people, I am filling a very valid request of a very valid company. Bitching, yea I am guilty. To say that I do not know what the previous versions are like is not true and beside the point. I know what dbaseII was like in 1985 and I expect the tools 23 years later to be superior (in user interface). SQL Server (interface) is BARELY superior to dbase II in a few areas and much worse in others. You can make excuses for the tool all you want, it still SUCKS. Call it bitching if you want, I am simply calling your favorite spade a spade. It SUCKS. Alright? Not complaining, simply stating the obvious. Having spent your entire adult life working in it may make it SEEM (to you) like it doesn't SUCK but, in fact, it SUCKS. Now, if you wish to take offense at my stating that the tool sucks, have at. Notice that Gustav pretty much also stated that the tool (interface) sucks. Rant at him a bit why don't you. The emperor has no clothes, though he remains a pretty powerful emperor. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Wednesday, March 26, 2008 9:21 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction Paul, Probably not. John, There is no such thing as a SQL Server USER. If you do not want to hire a DBA/SQL Programmer, then you are it, like it or not. 3rd party tools are there for a reason. They were there for Access also. If you don't like the FREE tools, buy one that you do like. Since you have no idea what the previous versions of SQL Server were like, you have no reference point for the current version. I have used and programmed with SQL Server since 3.21. It has come a long, long way since then. I gave you a 2/3's completed solution, written as it should have been, in T-SQL. Stop the bitching and complaining. If you need help, you have received it from this list. But, I have to agree with Francisco, you got the help even if you are enabling spamming and junk mail. Robert At 08:25 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 19:25:44 -0600 >From: "Paul Nielsen" >Subject: Re: [dba-SQLServer] Copy a database using a store > procedureorfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <004401c88ee0$51061230$f3123690$@com> >Content-Type: text/plain; charset="us-ascii" > >But you are using version control for all source code including DDL >code, right? > >-Paul > > > > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of >jwcolby >Sent: Tuesday, March 25, 2008 7:03 PM >To: 'Discussion concerning MS SQL Server' >Subject: Re: [dba-SQLServer] Copy a database using a store >procedureorfunction > >I am not criticizing anybody, I am simply pointing out that there are >many different jobs. Mine is not SQL Server Administrator, nor SQL >Server programmer. Mine is SQL Server user. SQL Server is an >immensely powerful system where the human interface is just emerging >from the stone age. Like anyone familiar with the stone age tools, >they are good enough to get the job done, if you happen to be familiar >with the stone age tools. If you are familiar with high powered rifles >and razor sharp knives,and airplanes to get to the hunt, the stone age hunting tools are ... well.. Stone age. _______________________________________________ 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 From jwcolby at colbyconsulting.com Wed Mar 26 15:22:03 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 16:22:03 -0400 Subject: [dba-SQLServer] Copy a database using a stored procedure orfunction In-Reply-To: <200803261956.m2QJujvq001878@databaseadvisors.com> References: <200803261956.m2QJujvq001878@databaseadvisors.com> Message-ID: <003301c88f7f$0e7caf10$0201a8c0@M90> >Spam and junk mail are never valid. Think of the trees and bandwidth wasted. Yes, please leave the commentary out. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Wednesday, March 26, 2008 3:51 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, What I take offense with is the attitude of "Help me, but let me rant about how difficult it is." A priest no. But at one time, I was a licensed minister in one of the mainstream denominations. :-) Spam and junk mail are never valid. Think of the trees and bandwidth wasted. Ask the questions and leave the commentary out. You have your expertise at classes, etc in Access. I have a lot of experience there also. I have a client management system, DB in SQL Server, that I have developed over the last 10+ years. A number of social service agencies use it. When I chose to use SQL Server, I did not whine about how hard it was to use. Now, as a DBA and SQL programmer, I continue to be amazed at what SQL Server can do. And, I still do some of my FE work in Access, but am moving to .Net for that. Comparing SQL Server to dBase II is like comparing a skateboard to a Cadillac. Everything evolves in the programming world. Just not at the speed you want it to. Robert From jwcolby at colbyconsulting.com Wed Mar 26 15:29:33 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 16:29:33 -0400 Subject: [dba-SQLServer] Copy a database using a stored procedure orfunction In-Reply-To: <200803261956.m2QJujvq001878@databaseadvisors.com> References: <200803261956.m2QJujvq001878@databaseadvisors.com> Message-ID: <003401c88f80$1a4eb210$0201a8c0@M90> Robert, you are being an ass. Bulk mail is nothing more than advertising. You get advertised on tv, on radio, on every web page and on your doorstep. The advertising on tv and radio and on the web is wasting electricity but I don't see you getting all green about that. If you want to rant about advertising, go to a list about that subject. For bulk mail there are opt out lists, go get on one. I get NO junk mail. Spammers are a whole different breed and are by and large criminals. To call me one is an unwarranted insult and I would appreciate it if you would cease. KNOCK IT OFF WITH THE CRAP AT DIRECTED AT ME. It matters not a whit to me whether you like it, what matters to me is that you use the SQL Server list to rant about your personal opinions about such stuff. This is also not a list to rant about abortion, or Christianity, or ... We have an off topic list, take that nonsense there. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Wednesday, March 26, 2008 3:51 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, What I take offense with is the attitude of "Help me, but let me rant about how difficult it is." A priest no. But at one time, I was a licensed minister in one of the mainstream denominations. :-) Spam and junk mail are never valid. Think of the trees and bandwidth wasted. Ask the questions and leave the commentary out. You have your expertise at classes, etc in Access. I have a lot of experience there also. I have a client management system, DB in SQL Server, that I have developed over the last 10+ years. A number of social service agencies use it. When I chose to use SQL Server, I did not whine about how hard it was to use. Now, as a DBA and SQL programmer, I continue to be amazed at what SQL Server can do. And, I still do some of my FE work in Access, but am moving to .Net for that. Comparing SQL Server to dBase II is like comparing a skateboard to a Cadillac. Everything evolves in the programming world. Just not at the speed you want it to. Robert At 10:41 AM 3/26/2008, you wrote: >Date: Wed, 26 Mar 2008 11:40:56 -0400 >From: "jwcolby" >Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <001201c88f57$c8ba7a10$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >Robert, > >Making judgments about what I do for a living is unhelpful and in fact >downright inappropriate. Peoples careers range from terrorists to >Catholic bishops. I don't see you becoming a priest. ONE thing that I >do is a database for a company that sells address lists to companies >that send bulk mail. I also write databases for non-profit >organizations that help parents of children with disabilities. And >many other databases. I am not killing people, I am filling a very valid request of a very valid company. > >Bitching, yea I am guilty. > >To say that I do not know what the previous versions are like is not >true and beside the point. I know what dbaseII was like in 1985 and I >expect the tools 23 years later to be superior (in user interface). >SQL Server >(interface) is BARELY superior to dbase II in a few areas and much >worse in others. You can make excuses for the tool all you want, it still SUCKS. >Call it bitching if you want, I am simply calling your favorite spade a >spade. It SUCKS. Alright? Not complaining, simply stating the obvious. >Having spent your entire adult life working in it may make it SEEM (to >you) like it doesn't SUCK but, in fact, it SUCKS. > >Now, if you wish to take offense at my stating that the tool sucks, have at. >Notice that Gustav pretty much also stated that the tool (interface) sucks. >Rant at him a bit why don't you. > >The emperor has no clothes, though he remains a pretty powerful emperor. > >John W. Colby _______________________________________________ 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 Mar 26 15:35:56 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 16:35:56 -0400 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: <000001c88e91$69be9940$3d3bcbc0$@com> References: <005b01c88dfc$d280f1c0$0201a8c0@M90> <000001c88e91$69be9940$3d3bcbc0$@com> Message-ID: <003501c88f80$fecea300$0201a8c0@M90> Thanks. I was reading it already. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 12:01 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Returning a dataset Hi John, Here's a chapter on sprocs. It's not the greatest chapter, but the section on return data scope is useful. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 24, 2008 4:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Returning a dataset A stored procedure can return a data set correct? Is that data set updateable? I need to run a stored procedure, where I pass in the Value for the TOP N (the N part) and then build up a SQL statement and execute that inside of the sp. That sp needs to return the data set to another SP, and that SP has to update a field in the data set returned by the first sp. Is this possible? ATM I have a view called TopN, which returns a date field. I have a query that updates that date field to today's date. The problem is that the TopN view is hard coded with a number (30000 for today's order) but that value could be any number. So I need to turn the view into a SP where I can pass in the number of records to update and then pass the set up date fields back to an update SP to do the update. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2968 (20080324) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Wed Mar 26 15:45:13 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 26 Mar 2008 14:45:13 -0600 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: <003501c88f80$fecea300$0201a8c0@M90> References: <005b01c88dfc$d280f1c0$0201a8c0@M90> <000001c88e91$69be9940$3d3bcbc0$@com> <003501c88f80$fecea300$0201a8c0@M90> Message-ID: <002701c88f82$4acd7b40$e06871c0$@com> This was the first email I sent when you first asked about returning data. It was help up waiting for approval to post through the newsgroup. When I learned that it was delayed, I sent it to you directly. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 26, 2008 2:36 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Returning a dataset Thanks. I was reading it already. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 12:01 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Returning a dataset Hi John, Here's a chapter on sprocs. It's not the greatest chapter, but the section on return data scope is useful. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, March 24, 2008 4:17 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Returning a dataset A stored procedure can return a data set correct? Is that data set updateable? I need to run a stored procedure, where I pass in the Value for the TOP N (the N part) and then build up a SQL statement and execute that inside of the sp. That sp needs to return the data set to another SP, and that SP has to update a field in the data set returned by the first sp. Is this possible? ATM I have a view called TopN, which returns a date field. I have a query that updates that date field to today's date. The problem is that the TopN view is hard coded with a number (30000 for today's order) but that value could be any number. So I need to turn the view into a SP where I can pass in the number of records to update and then pass the set up date fields back to an update SP to do the update. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2968 (20080324) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2975 (20080326) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From pauln at sqlserverbible.com Wed Mar 26 16:16:36 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 26 Mar 2008 15:16:36 -0600 Subject: [dba-SQLServer] Copy a database using a storedprocedure or function In-Reply-To: <003201c88f7e$73161f20$0201a8c0@M90> References: <8572573.1248051206555440792.JavaMail.root@vms229.mailsrvcs.net> <003201c88f7e$73161f20$0201a8c0@M90> Message-ID: <004301c88f86$ad5bbfc0$08133f40$@com> >> SQL Server (interface) is BARELY superior to dbase II in a few areas and much worse in others. I don't believe you've ever used the SSMS in the way I've been promoting. If you did, you'd be in love with how easy and quickly you get the work done. So you have no right complaining about what you refuse to try. >> nor do I need a gigabyte disk full of directories full of sql statements all neatly cataloged If you understood client/server, you'd realize how ridiculous that sounds. Most SQL Server databases I've written are in a single script 20K - 100K. >> I just need a small template database with about 30 views and 20 stored procedures. I know what you're trying to do. I can bill it in my sleep. Every database I build is a template style database. I know exactly how to do that specific task the easiest way possible. As I've been trying to tell you, the ***EASY*** way to build a template database is by a single script that creates the database, creates the tables, views and procs. Open script, point to server. Edit db name. press F5. Done. I've done this hundreds of times. Ever hear of Agile development? Doing it your way is the old way. The Agile way is faster and better. For agile development use 1 script for DDL code, one script for sample test data, and a third script for unit testing. I can go through iterations much faster than you can develop and test even in Access. SSMS screams developer performance when you know how to develop in a way that works with client server rather than fighting against it. >> I am here on this forum as a know nothing nubee, who will NEVER know 1/100th what you know ABOUT SQL SERVER. Then why not listen when I say, "you're doing it the hard way, this way is much easier?" Why insist that my advice is stone-aged? --- You literally have no idea what you're asking for. And when I and others try to tell you how to do what you want the *easy* way, you kick, scream, and insult - complaining that it's too hard, but you really have no idea what we're even suggesting. Rather than saying, "Hmmm, ok how would I do that?", you insult those offering best practices and advice. How many times has a client told you that their specific application is different and unique, when you knew all along that they just needed xyz? And when you tried to help, they just refused to even hear what you told them. I've built many large SQL Server apps that brought in Gbs of mainframe data, cleaned and ETL'd it into a DW. One that sounds almost exactly like the one you're working on. I can help you avoid the pitfalls you don't even know about. Yet. So you don't need FKs? You still need a PK. So you need to select random rows? You think you need to add a column and index it? Did you look up the tablesample suggestion? Tablesample with order by newID() is what you need. I'll say it again. No one who is efficient with SQL Server develops using the click interface of SSMS. Smart SQL Server db developers write and execute scripts because they know that DDL is valuable source code and the database is the execution of the source code, not where you deposit source code. And because it's easier and faster. In Access, you just built up a database by clicking, maybe opening up an event and adding some code, and then you copied the database around. That's fine for Access, but it's a pain in SQL Server. You complain it's a pain, I show you how to avoid the pain, you insult and rant more. The reasons you hate SQL Server are ALL due to your old style of development - not SQL Server, not BOL, not the tool. You want to fly a 777 but you complain because it's different than driving your old truck. Now, I have a chapter to finish. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 26, 2008 2:18 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storedprocedure or function Eric, Part of the problem though is that SQL Server can do many different things. I don't need any of the stuff you mentioned. My lists are not relational, they are one long wide list. I split off the name and address and maintain that as a separate list but still not parent / child, rather 1-1. I don't need all that stuff but I DO need sql server. It is the only thing powerful enough to process a list of 100 million names with 150 fields and indexes etc. So my point is that I really and truly DO NOT NEED all of that stuff. I need a small handful of concepts, most of which I have already learned. I am here now trying to copy a database (for example). Never got that far. I do not want, nor do I need a gigabyte disk full of directories full of sql statements all neatly cataloged. I just need a small template database with about 30 views and 20 stored procedures. Someday soon I will not even need that as I move my logic to .NET but right now I do. So telling me to go memorize BOL is simply a dreadful and unrealistic response to my questions. Even if I could, I would never use it again in the next two years and what would be the point of all that effort? You really and truly need to get that there are an entire spectrum of uses for SQL Server from an IBM to a tiny 5 man virtual company processing address lists. I have to know 10 times as much stuff ENTIRELY UNRELATED TO SQL SERVER as I do stuff related to sql server, just to handle the little address list company. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Wednesday, March 26, 2008 2:17 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a storedprocedure or function Gustav, It's no different than moving from dBASE to Access and then from Access to SQL server. Access changed the programming paradigm from what we were used to in dBASE to an event-driven paradigm. The simplest things that one could do with dBASE code was such a pain to figure out with Access 1.0 since the paradigm shifted to an event-driven approach. There was a learning curve to overcome. Ditto when moving from Access which spoiled us with the GUI drag and drop functionality for querying data. Enterprise Manager for SQL server was such a pain to grasp simply because SQL server wasn't made to have a GUI. I hated the idea that SQL server didn't have the same GUI that Access had...after all, it was made by the same company -- Micro$oft. But oftentimes the GUI just gets in the way. Same deal with Sharepoint. I'm a nuts and bolts type of guy who likes to "peek under the hood" to see how the "engine" is working its magic. The GUI becomes a better tool if you know exactly how things work "under the hood". Stored procedures, user-defined functions that return either values or result sets, temporary tables and temporary table variables, data partioning, scheduled jobs, role-based security (integrated with windows or native sql server), full-text cataloging for search engine-like functionality, support for VB, scripting objects, replication, etc... -- these are the things that make SQL server the workhorse it is. Sure it takes time to learn these and be good at it. But isn't that true with the other products (dBASE, Access, etc..)? If we really wanted something simple and easy to use, why not buy a MAC? Eric --------------------------------------------------- From: Gustav Brock Date: 2008/03/26 Wed PM 12:20:11 CDT To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure or function Hi John, Robert, Paul et al We use SQL Server as a data store and not as an "application". I'm a firm believer that only low-level logic should be handled by the engine while any high-level business-rule-style logic belongs to a middle-tier or the frontend or - if that is not possible - should be fully maintained by and controlled from either of these. One reason for this is exactly what you are arguing about, that it takes a life's work to become an excellent T-SQL programmer and neither I nor the company I work for can allocate such resources. Also, this discussion reminds me of the days of DOS. I cannot count how many batch files I wrote in the eighties and nineties for just about anything including full screen login systems for NetWare and sophisticated menu systems. PC Magazine in those days had a column of advanced batch programming often beyond belief. I've kept it all somewhere, but since Windows 95 arrived it has never been used and users stopped requesting such services. I will never be used again, but this is where I understand John; when I go to that SQL editor it is close to typing in Edlin - you only miss the piping! Wow, that was great (wiping a small tear). When you move to VS and its great environment you feel the difference. Having worked with the manager of version 6.5 years back, however, the current manager represents a vast improvement, and it is quite nice that you can run it together with Visual Studio which overlaps quite a lot while you have the same look and feel. /gustav >>> jwcolby at colbyconsulting.com 26-03-2008 16:40:56 >>> Robert, Making judgments about what I do for a living is unhelpful and in fact downright inappropriate. Peoples careers range from terrorists to Catholic bishops. I don't see you becoming a priest. ONE thing that I do is a database for a company that sells address lists to companies that send bulk mail. I also write databases for non-profit organizations that help parents of children with disabilities. And many other databases. I am not killing people, I am filling a very valid request of a very valid company. Bitching, yea I am guilty. To say that I do not know what the previous versions are like is not true and beside the point. I know what dbaseII was like in 1985 and I expect the tools 23 years later to be superior (in user interface). SQL Server (interface) is BARELY superior to dbase II in a few areas and much worse in others. You can make excuses for the tool all you want, it still SUCKS. Call it bitching if you want, I am simply calling your favorite spade a spade. It SUCKS. Alright? Not complaining, simply stating the obvious. Having spent your entire adult life working in it may make it SEEM (to you) like it doesn't SUCK but, in fact, it SUCKS. Now, if you wish to take offense at my stating that the tool sucks, have at. Notice that Gustav pretty much also stated that the tool (interface) sucks. Rant at him a bit why don't you. The emperor has no clothes, though he remains a pretty powerful emperor. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Wednesday, March 26, 2008 9:21 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction Paul, Probably not. John, There is no such thing as a SQL Server USER. If you do not want to hire a DBA/SQL Programmer, then you are it, like it or not. 3rd party tools are there for a reason. They were there for Access also. If you don't like the FREE tools, buy one that you do like. Since you have no idea what the previous versions of SQL Server were like, you have no reference point for the current version. I have used and programmed with SQL Server since 3.21. It has come a long, long way since then. I gave you a 2/3's completed solution, written as it should have been, in T-SQL. Stop the bitching and complaining. If you need help, you have received it from this list. But, I have to agree with Francisco, you got the help even if you are enabling spamming and junk mail. Robert At 08:25 PM 3/25/2008, you wrote: >Date: Tue, 25 Mar 2008 19:25:44 -0600 >From: "Paul Nielsen" >Subject: Re: [dba-SQLServer] Copy a database using a store > procedureorfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <004401c88ee0$51061230$f3123690$@com> >Content-Type: text/plain; charset="us-ascii" > >But you are using version control for all source code including DDL >code, right? > >-Paul > > > > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of >jwcolby >Sent: Tuesday, March 25, 2008 7:03 PM >To: 'Discussion concerning MS SQL Server' >Subject: Re: [dba-SQLServer] Copy a database using a store >procedureorfunction > >I am not criticizing anybody, I am simply pointing out that there are >many different jobs. Mine is not SQL Server Administrator, nor SQL >Server programmer. Mine is SQL Server user. SQL Server is an >immensely powerful system where the human interface is just emerging >from the stone age. Like anyone familiar with the stone age tools, >they are good enough to get the job done, if you happen to be familiar >with the stone age tools. If you are familiar with high powered rifles >and razor sharp knives,and airplanes to get to the hunt, the stone age hunting tools are ... well.. Stone age. _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2975 (20080326) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fuller.artful at gmail.com Tue Mar 25 20:33:39 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Tue, 25 Mar 2008 21:33:39 -0400 Subject: [dba-SQLServer] Copy a database using astore procedure orfunction In-Reply-To: <00bc01c88ed8$987f7870$0201a8c0@M90> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> <004401c88ead$dc2de1e0$9489a5a0$@com> <00c701c88ece$58b36c60$0a1a4520$@com> <00bc01c88ed8$987f7870$0201a8c0@M90> Message-ID: <29f585dd0803251833l64640a1ep8f0fce3d0605c757@mail.gmail.com> This is going to be a difficult message to phrase correctly. I want to be extremely careful here because I am extremely uncomfortable with Paul Nielsen's perspective and attitude. With anyone whose address is sqlbible one must be careful, but I need to say that Paul's attitude is not in the realm of sharing information with newbies, but rather in the realm of "I came from the command line and therefore you should learn it first". Perhaps that is not what Paul intends, but that is how I'm perceiving his line here. I myself take a different path. I think "use the wizards while you're learning, as much as possible", and trace what happened as a result of your instructions -- if and when you're ready for that. To say, "Don't use the wizards" is to negate all the work the development team put into this part of the product, not to mention that the wizards get things done. This is not to say that I am ready to marry the wizard-builders, but it is to appreciate their efforts. As it happens, I use tools from ApexSQL and Red Gate that solve problems the built-ins do not. Paul has an excellent point when it comes to writing cert-exams. These typically do not want to know which things to click to do a given job; they want the underlying SQL, and this is a good thing. But you can get things done using the wizards, and learn how they do it at the same time. Paul seems to be ignoring the growth path, and instead (as my father did to me) that the best way to learn to swim is to throw you off the end of the pier. As a victim of that teaching strategy, I do protest, and suggest another way. JC's point is valid, and Paul's command-line objections are valid too -- once you get to a certain point, but definitely not at the outset. Paul is perpetuating the "priesthood" mentality, and I for one take serious objection to that attitude, but I am attempting to do so gracefully and merely suggest that it overlooks the tutorial and getting-things-done-right-now phase. I hope that these objections were phrased gently enough so as not to start a war. Arthur On 3/25/08, jwcolby wrote: > > Yes, but it is not automated. I know how to copy a database, I have been > doing so for months - with the menus from the gui. I need to automate > this > whole thing. You don't even have to detach with the wizard. > > I need to do it from code. > > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul > Nielsen > > Sent: Tuesday, March 25, 2008 7:17 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using astore procedure > orfunction > > > For a anti-T-SQL, no T-SQL batches GUI easy way to move a file... > > As I posted at 1:25... > > Pick the database in SSMS - Object Explorer > > Right click to open context menu > Tasks > Detach then OK > > The file can now be copied to wherever you want. > > On the new server, in SSMS-Object Explorer > > Pick Databases > > Right click to Open Context Menu > Attach > > Pick the file and click OK. > > -Paul > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul > Nielsen > Sent: Tuesday, March 25, 2008 1:25 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > To move /copy a file use detach - copy the file - then attach. Real fast > real simple. > > -Paul > > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Tuesday, March 25, 2008 1:09 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > James, > > That is an interesting solution. My main objection to that (other than > being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a > new view or stored procedure etc I have to rebuild the script. I just > want > to > > Copy "SomeDatabase", "NewName" > > This is the kind of thing that drives me crazy about SQL Server. It has > the > IQ of a mouse when it comes to programming. I'm telling you the . > Language > of Dbase II was like Einstein compared to what you have to do with SQL > Server. > > "Generate scripts"? The database is a single file (OK it could be more, > but > still...), what is so damned hard about copying that and telling it that > it > has a new name? To make matters worse, there is a wizard that does > it. Why > can't I just call whatever function that wizard calls and pass in the > parameters that the wizard gathers and copy my database? > > When I want pain, I go to my mistress downtown and she uses a cat-o-nine. > When I really want some TORTURE I fire up SQL Server and try and do some > work. > > ;-) > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James > Barash > Sent: Tuesday, March 25, 2008 2:40 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > John: > > If you only need to copy the design of the database but not the data, you > can use the scripting wizard to create a script of all the objects and use > that to make the new database. If you are using SQL Server 2005, > Right-Click > on the database, select Tasks -> Generate Scripts. Then you can choose to > script all the objects, including Tables, Views, Stored Procedures, UDF, > Users, etc; or you can choose individual objects. Once you've created the > script, add the appropriate Create Database statement at the top and save > the script to a file and you will be able to build as many database as you > need from the same template. > Hope this helps. > > James Barash > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Tuesday, March 25, 2008 2:06 PM > To: 'Discussion concerning MS SQL Server' > Subject: [dba-SQLServer] Copy a database using a store procedure or > function > > I have built up a template database which has views that pull data out of > many different databases / tables. Additionally I now have user stored > procedures which perform processing steps. In real life I manually copy > this template database to a new name using the copy database wizard, and > then run the stored procedures and stuff to build up a data order for > shipment. > > What I really need to do is have a method of copying this database to a > new > name and then "use" that database to launch the various stored procedures > inside of it to fill the tables, build the data and export the data. > > Is there a function or sp which can copy a database to a new name? When I > Google I get about a million "use the copy database wizard" answers. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > 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 > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > __________ NOD32 2971 (20080325) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > __________ NOD32 2971 (20080325) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > > _______________________________________________ > 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 > > From pauln at sqlserverbible.com Wed Mar 26 17:16:09 2008 From: pauln at sqlserverbible.com (Paul Nielsen) Date: Wed, 26 Mar 2008 16:16:09 -0600 Subject: [dba-SQLServer] Copy a database using astore procedure orfunction In-Reply-To: <29f585dd0803251833l64640a1ep8f0fce3d0605c757@mail.gmail.com> References: <00a401c88ea2$d18660b0$0201a8c0@M90> <00c401c88ea7$afc9cde0$6a00a8c0@fci.local> <00a901c88eab$a25a2e30$0201a8c0@M90> <004401c88ead$dc2de1e0$9489a5a0$@com> <00c701c88ece$58b36c60$0a1a4520$@com> <00bc01c88ed8$987f7870$0201a8c0@M90> <29f585dd0803251833l64640a1ep8f0fce3d0605c757@mail.gmail.com> Message-ID: <002401c88f8e$fef869c0$fce93d40$@com> I am trying to show John how to develop a template database the easy way. For several messages I presented a gentle "this way is easier" approach, happy to help, and was insulted at every message. Enough is enough. SQL Server is not a horse and buggy, not 1985, and my methods are not stone-age. He has no right to insult what he won't try. It's not sink or swim method. Insisting on SQL Server development using only clicks is the sink or swim. Learning to save a script is the easy way. John's big problem is that he wants a template database but his click method is the opposite of the easy to re-deploy template approach. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Tuesday, March 25, 2008 7:34 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using astore procedure orfunction This is going to be a difficult message to phrase correctly. I want to be extremely careful here because I am extremely uncomfortable with Paul Nielsen's perspective and attitude. With anyone whose address is sqlbible one must be careful, but I need to say that Paul's attitude is not in the realm of sharing information with newbies, but rather in the realm of "I came from the command line and therefore you should learn it first". Perhaps that is not what Paul intends, but that is how I'm perceiving his line here. I myself take a different path. I think "use the wizards while you're learning, as much as possible", and trace what happened as a result of your instructions -- if and when you're ready for that. To say, "Don't use the wizards" is to negate all the work the development team put into this part of the product, not to mention that the wizards get things done. This is not to say that I am ready to marry the wizard-builders, but it is to appreciate their efforts. As it happens, I use tools from ApexSQL and Red Gate that solve problems the built-ins do not. Paul has an excellent point when it comes to writing cert-exams. These typically do not want to know which things to click to do a given job; they want the underlying SQL, and this is a good thing. But you can get things done using the wizards, and learn how they do it at the same time. Paul seems to be ignoring the growth path, and instead (as my father did to me) that the best way to learn to swim is to throw you off the end of the pier. As a victim of that teaching strategy, I do protest, and suggest another way. JC's point is valid, and Paul's command-line objections are valid too -- once you get to a certain point, but definitely not at the outset. Paul is perpetuating the "priesthood" mentality, and I for one take serious objection to that attitude, but I am attempting to do so gracefully and merely suggest that it overlooks the tutorial and getting-things-done-right-now phase. I hope that these objections were phrased gently enough so as not to start a war. Arthur On 3/25/08, jwcolby wrote: > > Yes, but it is not automated. I know how to copy a database, I have been > doing so for months - with the menus from the gui. I need to automate > this > whole thing. You don't even have to detach with the wizard. > > I need to do it from code. > > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul > Nielsen > > Sent: Tuesday, March 25, 2008 7:17 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using astore procedure > orfunction > > > For a anti-T-SQL, no T-SQL batches GUI easy way to move a file... > > As I posted at 1:25... > > Pick the database in SSMS - Object Explorer > > Right click to open context menu > Tasks > Detach then OK > > The file can now be copied to wherever you want. > > On the new server, in SSMS-Object Explorer > > Pick Databases > > Right click to Open Context Menu > Attach > > Pick the file and click OK. > > -Paul > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul > Nielsen > Sent: Tuesday, March 25, 2008 1:25 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > To move /copy a file use detach - copy the file - then attach. Real fast > real simple. > > -Paul > > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Tuesday, March 25, 2008 1:09 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > James, > > That is an interesting solution. My main objection to that (other than > being so 1950s-ish) is it doesn't adapt to changes, i.e. any time I add a > new view or stored procedure etc I have to rebuild the script. I just > want > to > > Copy "SomeDatabase", "NewName" > > This is the kind of thing that drives me crazy about SQL Server. It has > the > IQ of a mouse when it comes to programming. I'm telling you the . > Language > of Dbase II was like Einstein compared to what you have to do with SQL > Server. > > "Generate scripts"? The database is a single file (OK it could be more, > but > still...), what is so damned hard about copying that and telling it that > it > has a new name? To make matters worse, there is a wizard that does > it. Why > can't I just call whatever function that wizard calls and pass in the > parameters that the wizard gathers and copy my database? > > When I want pain, I go to my mistress downtown and she uses a cat-o-nine. > When I really want some TORTURE I fire up SQL Server and try and do some > work. > > ;-) > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James > Barash > Sent: Tuesday, March 25, 2008 2:40 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Copy a database using a store procedure > orfunction > > John: > > If you only need to copy the design of the database but not the data, you > can use the scripting wizard to create a script of all the objects and use > that to make the new database. If you are using SQL Server 2005, > Right-Click > on the database, select Tasks -> Generate Scripts. Then you can choose to > script all the objects, including Tables, Views, Stored Procedures, UDF, > Users, etc; or you can choose individual objects. Once you've created the > script, add the appropriate Create Database statement at the top and save > the script to a file and you will be able to build as many database as you > need from the same template. > Hope this helps. > > James Barash > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Tuesday, March 25, 2008 2:06 PM > To: 'Discussion concerning MS SQL Server' > Subject: [dba-SQLServer] Copy a database using a store procedure or > function > > I have built up a template database which has views that pull data out of > many different databases / tables. Additionally I now have user stored > procedures which perform processing steps. In real life I manually copy > this template database to a new name using the copy database wizard, and > then run the stored procedures and stuff to build up a data order for > shipment. > > What I really need to do is have a method of copying this database to a > new > name and then "use" that database to launch the various stored procedures > inside of it to fill the tables, build the data and export the data. > > Is there a function or sp which can copy a database to a new name? When I > Google I get about a million "use the copy database wizard" answers. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > 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 > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > __________ NOD32 2971 (20080325) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > __________ NOD32 2971 (20080325) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > > _______________________________________________ > 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 > > _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com __________ NOD32 2976 (20080326) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com From fhtapia at gmail.com Wed Mar 26 17:29:28 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Wed, 26 Mar 2008 15:29:28 -0700 Subject: [dba-SQLServer] Copy a database using a storedprocedure or function In-Reply-To: <004301c88f86$ad5bbfc0$08133f40$@com> References: <8572573.1248051206555440792.JavaMail.root@vms229.mailsrvcs.net> <003201c88f7e$73161f20$0201a8c0@M90> <004301c88f86$ad5bbfc0$08133f40$@com> Message-ID: Group, Let's try to get back on topic. A bump in the road has distracted us all from the purpose of the list and spawned off a series of OT email that evolved into name-calling and ranting. I appreciate all of you who have taken the time to be courteous and polite during this discourse. Let's try to keep it on track. -- -Francisco dba-SqlServer Moderator From jwcolby at colbyconsulting.com Wed Mar 26 19:34:48 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 20:34:48 -0400 Subject: [dba-SQLServer] Returning a dataset In-Reply-To: <002701c88f82$4acd7b40$e06871c0$@com> References: <005b01c88dfc$d280f1c0$0201a8c0@M90> <000001c88e91$69be9940$3d3bcbc0$@com><003501c88f80$fecea300$0201a8c0@M90> <002701c88f82$4acd7b40$e06871c0$@com> Message-ID: <003901c88fa2$5d6b5bd0$0201a8c0@M90> Yep, I got it directly and started reading it immediately. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Wednesday, March 26, 2008 4:45 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Returning a dataset This was the first email I sent when you first asked about returning data. It was help up waiting for approval to post through the newsgroup. When I learned that it was delayed, I sent it to you directly. -Paul -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, March 26, 2008 2:36 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Returning a dataset Thanks. I was reading it already. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Tuesday, March 25, 2008 12:01 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Returning a dataset Hi John, Here's a chapter on sprocs. It's not the greatest chapter, but the section on return data scope is useful. -Paul From jwcolby at colbyconsulting.com Wed Mar 26 21:33:27 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 22:33:27 -0400 Subject: [dba-SQLServer] Copy a database usinga storedprocedure or function In-Reply-To: <004301c88f86$ad5bbfc0$08133f40$@com> References: <8572573.1248051206555440792.JavaMail.root@vms229.mailsrvcs.net><003201c88f7e$73161f20$0201a8c0@M90> <004301c88f86$ad5bbfc0$08133f40$@com> Message-ID: <000001c88fb2$f0bae530$0201a8c0@M90> Paul, I do the best that I can. I take the examples and paste them into a query window and try and run them and they don't work. They throw arcane error messages (excuse me, exceedingly useful error messages that I just don't happen to have the years of expertise to understand). Things like Line 10 "error close to ," Paul, I don't care what you say, Error near , is NOT a useful error message. I sit on the Access list and provide code all day. People come asking for stuff, I don't tell them to go read books online, I give them a piece of working code, WITH EXPLANATION of how it works and why, as do the other listers. If the person needs assistance learning how to use the debug window I give them that, as do the other listers. If they need to know how to OPEN the debug window, I give them that, as do the other listers. Search the archives Paul, I have been here for about 10 years and provided thousands of answers to questions, to provide whatever level of assistance the person needs from nubee (me here) to advanced expert. Look on the downloads page Paul. http://www.databaseadvisors.com/downloads.asp You will see my name on more fully working code examples than all the rest of the members of these lists COMBINED. I put my money in the pot to help start Database Advisors and make these lists available to you. I have been on the BOD of Database Advisors since it was started. I have served as president of Database Advisors. I continue to contribute cash to the company to make these lists available to you. http://www.databaseadvisors.com/donations/corporate.asp I am not someone who just comes here, contributes nothing and asks everyone to do all my work for me. I need help too, and I did not come here to be lectured about how if I would just spend the time to become an admin... (or to be lectured about spam or bulk mail). To be honest I thought this was going to be a quick "it's easy... Here's a few lines that do what you need". NOW#################### The original subject was "copying a database using a stored procedure". I got one "click this and then click this and the database is copied". Yea, but I didn't ask that (and I already know that as well). I got another from Elizabeth (Thanks very much Elizabeth) that looks like it might actually work, and I am trying to make it work with parameters... STILL trying to make it work with parameters. But at least it is just a few lines that I can actually read and understand. >I know it's a pain to learn, but SSIS (integration services) can do just about everything you need to do Thanks. Do I take this to mean that a SP cannot do this? What exactly do I do with that response? >If you only need to copy the design of the database but not the data, you can use the scripting wizard to create a script of all the objects and use that to make the new database. If you are using SQL Server 2005, Right-Click on the database, select Tasks -> Generate Scripts. Then you can choose to script all the objects, including Tables, Views, Stored Procedures, UDF, Users, etc; or you can choose individual objects. Once you've created the script, add the appropriate Create Database statement at the top and save the script to a file and you will be able to build as many database as you need from the same template. Actually an answer, but not really useful in my circumstances as I politely explained. But thanks James, it was an actual attempt to help. >To move /copy a file use detach - copy the file - then attach. Real fast real simple. Hmmm... Did you read the question? >Never Ever build any objects using SSMS Object Explorer. Develop everything - DDL/Schema, procs, unit test inserts, and proc test batches ALL with scripts stored as .sql files in the file system and checked into source control. OK, didn't understand a single word of that, but definitely not code that I can drop into a SP and get a database copied. Sounds vaguely like a "lecture". >Source code belongs in source code control. Developing in a gui is just plain dangerous. >All I'm saying is that when you code the sproc, do it in query editor and then save the file. Don't use Object Explorer to create new proc, save it in the database and then >edit it by opening it from the database. It's the same code, the difference is that the database is the destination of the code, not where you keep it. You keep the code in >source control. >I do all my development from files in directories that I open, edit, and then run. It's the fastest way to develop with SQL Server. >If you develop with multiple databases and multiple severs then you really need to work this way. You open you file, connect to whichever server you want, and then press F5. >It's fast, simple, and easy. >In SQL Server lingo, any submission to the database is a batch. If you highlight a query and press F5 - that's a batch. If the batch is saved in the database, that's a stored proc. If you've been working with SQL Server you've been doing batches. The question is only where do you want to save your source code? Hmm... Nope, no sp running yet. DEFINITELY sounds like a lecture. >BACKUP DATABASE AdventureWorks > TO DISK = 'C:\AdventureWorks.bak' >RESTORE FILELISTONLY > FROM DISK = 'C:\AdventureWorks.bak' >RESTORE DATABASE TestDB > FROM DISK = 'C:\AdventureWorks.bak' > WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', > MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' >GO BINGO, something useful. Thanks Elizabeth!!! >Take a look at SQL DMO Objects and the TRANSFER method. >That is what the wizard is using to do a database copy. >If you want to do it relatively simply: >Create the new DB. >Backup the current DB. >Restore the backup with overwrite option to the new db. >And yes, if you are willing to write some code, the three steps can be done through a stored procedure. OK... I am willing to write code. Just don't know what code to write. And even if I did, I can't interpret the damned error messages. ;-) And it goes down hill from there... So yea, for some reason I do find this list less than useful. A full day of lectures, and ONE response that actually looks like it might be helpful. Thanks Elizabeth! You guys ROCK! But by and large a huge waste of everybody's time don't you agree? Having done this day, I can tell you that there is not much point in doing another such day. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Paul Nielsen Sent: Wednesday, March 26, 2008 5:17 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storedprocedure or function >> SQL Server (interface) is BARELY superior to dbase II in a few areas >> and much worse in others. I don't believe you've ever used the SSMS in the way I've been promoting. If you did, you'd be in love with how easy and quickly you get the work done. So you have no right complaining about what you refuse to try. ... Now, I have a chapter to finish. -Paul From jwcolby at colbyconsulting.com Wed Mar 26 21:57:43 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 26 Mar 2008 22:57:43 -0400 Subject: [dba-SQLServer] Copy a database using astore procedureorfunction In-Reply-To: <29f585dd0803251833l64640a1ep8f0fce3d0605c757@mail.gmail.com> References: <00a401c88ea2$d18660b0$0201a8c0@M90><00c401c88ea7$afc9cde0$6a00a8c0@fci.local><00a901c88eab$a25a2e30$0201a8c0@M90><004401c88ead$dc2de1e0$9489a5a0$@com><00c701c88ece$58b36c60$0a1a4520$@com><00bc01c88ed8$987f7870$0201a8c0@M90> <29f585dd0803251833l64640a1ep8f0fce3d0605c757@mail.gmail.com> Message-ID: <000601c88fb6$549ec410$0201a8c0@M90> Thanks Arthur for the old "college try". I don't know if you have ever looked at the priesthood, but they REALLY don't like any implications that they are a priesthood, nor that the system is unfriendly. I guess you have seen that already though. I have to honest and say that I too find the wizards extremely useful. If the wizards would write their actions into SQL and paste them into a module like Excel will do, now THAT would be awesome. At some point (when you need automation) the wizards cease to be useful. And then it becomes "sink or swim". Not really much in between. I have been programming since the late 70s and I have to say, the scripts in SQL Server just look like command files from DOS to me (as Gustav so observantly put it). With just about the same level of feedback if something goes wrong. The priesthood likes it because having spent years learning it, it is what makes them priests. I for one find the priests here about as useless as the ones out in the churches. Good luck in the war you just stepped into. Mine is done. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Tuesday, March 25, 2008 9:34 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using astore procedureorfunction This is going to be a difficult message to phrase correctly. I want to be extremely careful here because I am extremely uncomfortable with Paul Nielsen's perspective and attitude. With anyone whose address is sqlbible one must be careful, but I need to say that Paul's attitude is not in the realm of sharing information with newbies, but rather in the realm of "I came from the command line and therefore you should learn it first". Perhaps that is not what Paul intends, but that is how I'm perceiving his line here. I myself take a different path. I think "use the wizards while you're learning, as much as possible", and trace what happened as a result of your instructions -- if and when you're ready for that. To say, "Don't use the wizards" is to negate all the work the development team put into this part of the product, not to mention that the wizards get things done. This is not to say that I am ready to marry the wizard-builders, but it is to appreciate their efforts. As it happens, I use tools from ApexSQL and Red Gate that solve problems the built-ins do not. Paul has an excellent point when it comes to writing cert-exams. These typically do not want to know which things to click to do a given job; they want the underlying SQL, and this is a good thing. But you can get things done using the wizards, and learn how they do it at the same time. Paul seems to be ignoring the growth path, and instead (as my father did to me) that the best way to learn to swim is to throw you off the end of the pier. As a victim of that teaching strategy, I do protest, and suggest another way. JC's point is valid, and Paul's command-line objections are valid too -- once you get to a certain point, but definitely not at the outset. Paul is perpetuating the "priesthood" mentality, and I for one take serious objection to that attitude, but I am attempting to do so gracefully and merely suggest that it overlooks the tutorial and getting-things-done-right-now phase. I hope that these objections were phrased gently enough so as not to start a war. Arthur On 3/25/08, jwcolby wrote: > > Yes, but it is not automated. I know how to copy a database, I have > been doing so for months - with the menus from the gui. I need to > automate this whole thing. You don't even have to detach with the > wizard. > > I need to do it from code. > > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com From jwcolby at colbyconsulting.com Wed Mar 26 23:48:34 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 00:48:34 -0400 Subject: [dba-SQLServer] It seemed like it would be so easy: was Copy a database using a stored procedure In-Reply-To: References: Message-ID: <000701c88fc5$d0b96780$0201a8c0@M90> David, A refreshing bit of reality, thanks for that. My problems are really pretty simple. I think most here can't believe that but they really are. I am building a small relational database, which allows me to track the business side of my business. I am doing that mostly as an exercise in using VB.Net to manipulate SQL Server, and that database is not my problem. SQL Server can be viewed as simply a data store. The "Priests" don't want you to believe that but that is at heart what it is. All the rest is stuff to help manage the data store. If your job is managing a transactional database for Bank of America or something similar, then yea, you need every one of those specialists, in spades. OTOH, there are many cases where the requirements are much less stringent. Mine is one of those. My requirement is for a system that can handle single tables with millions to hundreds of millions of rows, with dozens to hundreds of fields. But in the end they are just SINGLE tables, unrelated to anything else. And furthermore there is not a transaction in site! I just import massive fixed width files, do some minor manipulations to get the field sizes fixed (and that isn't even strictly necessary), then build a bunch of cover index on sets of fields. Each list has name / address info which I do pull out into a separate table, related back to the original by a PK, but again, a one to one. Once the ORIGINAL table is built, it is never modified. EVER. I do build indexes but that is all. The lists just sit there. I take the name / address info and ship it out for address validation, then import it back in. Since it relates one to one with the original table, I now have valid addresses in one table and the rest of the data in the original table. No transactions. As such, I don't need probably 99% of the fancy stuff that SQL Server provides, at least not for this project. It is just a data store. What I am (was, I have given up) trying to do is get some very simple help on some very simple things, or they should be simple. I have already built a template database for "filling orders" from this database. My client asks me for a count (about 16 counts actually) of all the people who... Grouped by. SIMPLE stuff, and I have all of that working (in sql server) and have for a long time (years). I modify a couple of existing views to do the Where... Part, then manually run the count views. Copy the result "table" into a dedicated sheet of an excel workbook. 16 pages, one page for each "count", by state, by income bracket, by age bands and so forth. All working quite well. BTW I keep these as a dedicated database for that order (named after the order in fact) because I may need it later. Not sophisticated but simple and it works. That is the "template database". In fact there are two different kinds of orders. The second kind is "OK, now give me N thousand names / addresses from that count you gave me before". Again, I have been doing this stuff for quite some time, using a strange mixture of SQL Server, a third party Address Validation program running on a server here in my office, and Access (for the final phase). I have been doing all of that for months as well (years actually, I am just getting much more efficient at it lately). I decided that I could automate this second type of order such that many of the bits and pieces were just done by stored procedures. I have done that as well. All on my own, no Priests involved. I came here to this list because there was one specific piece that I hadn't a clue about, but I thought would be dead simple to the Priests. I need to copy that template to a database with a new name. I can (and do) copy the database using the wizard, I just figured that it would be a few lines of something, embedded in a SP and I could then add that to my list of existing SPs that automate what I do. Alas, all I got were lectures. The Priests do not like that I do not find their priesthood something that I wish to join, nor that I do not desire to spend the rest of my life memorizing arcane TSQL syntax. In fact it pisses them off royally that I even find it arcane, though of course it is to the laity. In my mind, I should not have to be a Priest. That is not what I do. I get by with most of it, I just needed one (seemingly) simple piece. So, in the end you are right, Access wouldn't fit the bill. I need SQL Server to be a fast, large data store for an EXTREMELY simple structure of entirely static data. As you can plainly see from the above description, I do not need to be a Priest, I just need a quick answer. I need (still need) to be able to do one thing that I had not figured out, and I got a lot of (dare I say) CRAP that simply reminds me why I do not come here often. I have come here a few times and always go away shaking my head at the lectures about stuff that is no use to me. And BOL. And now even lectures about spam and bulk mail. What makes it REALLY sad is that the Priests think they are doing me a favor with the lectures! Priests are like that though. ;-) My fervent hope is that some of those on this list will take this to heart and just decide that helping someone do something is enough. I helped start this list in the hope that I could get help and it is virtually useless to me. Hasta Luego and may you find yourself useful to a nubee some day. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Wednesday, March 26, 2008 11:29 AM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] QLRE: Copy a database using a stored procedureor Hi John: I don't think this will really 'help' you at this point, but it may make it a little easier for you to accept your situation the next time you start getting annoyed... You accepted a job that requires (form the sounds of it) a full-scale rdms -- Access wouldn't fit the bill. All the functionality that Access wrapped up neatly into gui's is in sql server, but not necessarily in a gui, and generally in a much more powerful and flexible form. But, as you are discovering, each of the things you are trying to do requires quite a learning curve. That isn't the fault of sql server -- it was built for needs that presuppose a fairly deep bench. Most places that use all the functions that you are using have a person(s) that specialize in each of the functions. There is a T-sql guy, an SSIS guy, a dba for tuning, backups and restores, etc. You are wearing many hats, and all the hats are pretty sophisticated. To take a very simple example, if you are used to building queries in Access using its gui, you've got a repertoire of approaches to getting the data you want. When you move to sql server, the gui for building queries is pretty crude, and if you take the plunge and go to the screen to write raw t-sql, you begin to discover many many many t-sql commands that either you didn't know existed, or had only heard of but had never tried (I am speaking from my own experience). Many of these turn problems that in access were a pain in the neck to solve, into pretty something trivial. I am speaking of sub-queries, case statements, correllated sub-queries, derived tables, etc. etc. etc. Using these in Access is nearly impossible, or actually impossible, so Access people generally never learn to use them. At least that was my experience (I didn't learn to write t-sql until I moved to sql server, and now I shudder at the thought of having to use access' gui to build a query). This example holds true for all the tools you are trying to use. Not a pleasant or comfortable state of affairs for you, but that is the way it is. When I have found myself in a similar position in the past, for example completely stuck on how to use DTS (now SSIS), I looked for a person who could work side by side with me to get things done; in that way I was able to learn from an expert (or at least someone with a lot more experience than I). That means spending money on a consultant, and I don't know how that fits with the economics of this job, but either way you look at it you need training or help, and that generally doesn't come cheap. Hope this helps (but of course I realize it likely just pissed you off more!) David 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 Gustav at cactus.dk Thu Mar 27 03:57:06 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 27 Mar 2008 09:57:06 +0100 Subject: [dba-SQLServer] Copy a database using a store procedure or function Message-ID: Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 From Gustav at cactus.dk Thu Mar 27 04:37:45 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 27 Mar 2008 10:37:45 +0100 Subject: [dba-SQLServer] Copy a database using a store procedure or function Message-ID: Hi all Just a note - the pass-through query property "Returns records" must be set to No. Also, there seems to be several ways to name the data and log files. Some use a suffix of _data and _log, some only _log, and some nothing. As the file extension, .mdf or .ldf, tells it all I see no reason to use a suffix at all. However, my example base used _log. Perhaps one of our gurus can clarify this. /gustav >>> Gustav at cactus.dk 27-03-2008 09:57 >>> Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 From Gustav at cactus.dk Thu Mar 27 05:58:44 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 27 Mar 2008 11:58:44 +0100 Subject: [dba-SQLServer] Copy a database using a store procedure or function Message-ID: Hi all One parameter is the database locations which must be specified for MOVE .. TO .. In the example this is hardcoded as c:\ which probably is not what you want. If you wish to find the default locations, these has to be read from the Registry. But to do so you must know the instance name of the engine as well and it starts to be a little complicated. Another method is to create a temp database. Its files will be located in the default folder. Read the filenames and you have the default folder for later use. Then delete the temp database: use master create database defaultdb select GroupId as DataTypeId, case GroupId when 1 then 'Data' when 0 then 'Log' end as DataTypeName, left(filename, len(filename) - charindex('\', ltrim(reverse(filename)))) + '\' as DefaultPath from defaultdb.dbo.sysfiles drop database defaultdb It is not fancy but effective. A faster method is to use the name of an existing database located in the folder you wish to use, and then just run the select part of the code above. /gustav >>> Gustav at cactus.dk 27-03-2008 09:57 >>> Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 From robert at webedb.com Thu Mar 27 07:45:35 2008 From: robert at webedb.com (Robert L. Stewart) Date: Thu, 27 Mar 2008 07:45:35 -0500 Subject: [dba-SQLServer] Copy a database using a stored procedure or function In-Reply-To: References: Message-ID: <200803271246.m2RCkJ2H015681@databaseadvisors.com> John, You can dish it out but not take it. I am not "green." I was simply baiting you. You swallowed hook line and sinker. I really could care less how you make your living. The point is, just ask for help and stop ranting about the poor quality of the tools. If you don't like them, then try doing the same thing with Oracle or MySql. Then you will understand archaic. Treat us as the professionals we are and I will do the same for you. Paul said it very well. Robert At 04:16 PM 3/26/2008, you wrote: >Date: Wed, 26 Mar 2008 16:29:33 -0400 >From: "jwcolby" >Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <003401c88f80$1a4eb210$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >Robert, you are being an ass. Bulk mail is nothing more than advertising. >You get advertised on tv, on radio, on every web page and on your doorstep. >The advertising on tv and radio and on the web is wasting electricity but I >don't see you getting all green about that. If you want to rant about >advertising, go to a list about that subject. > >For bulk mail there are opt out lists, go get on one. I get NO junk mail. >Spammers are a whole different breed and are by and large criminals. To >call me one is an unwarranted insult and I would appreciate it if you would >cease. > >KNOCK IT OFF WITH THE CRAP AT DIRECTED AT ME. It matters not a whit to me >whether you like it, what matters to me is that you use the SQL Server list >to rant about your personal opinions about such stuff. This is also not a >list to rant about abortion, or Christianity, or ... > >We have an off topic list, take that nonsense there. > >John W. Colby From robert at webedb.com Thu Mar 27 07:54:35 2008 From: robert at webedb.com (Robert L. Stewart) Date: Thu, 27 Mar 2008 07:54:35 -0500 Subject: [dba-SQLServer] Copy a database using a stored procedure or function In-Reply-To: References: Message-ID: <200803271256.m2RCuJAU021373@databaseadvisors.com> John, So the code I sent you for a parameterized stored procedure to do everything except the restore was "less than useful." I apologize for the "huge waste of everybody's time" (including mine) to give you a good, solid, viable way of solving your problem. Robert At 09:33 PM 3/26/2008, you wrote: >So yea, for some reason I do find this list less than useful. A full day of >lectures, and ONE response that actually looks like it might be helpful. >Thanks Elizabeth! From jwcolby at colbyconsulting.com Thu Mar 27 08:14:59 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 09:14:59 -0400 Subject: [dba-SQLServer] Copy a database using a stored procedure orfunction In-Reply-To: <200803271256.m2RCuJAU021373@databaseadvisors.com> References: <200803271256.m2RCuJAU021373@databaseadvisors.com> Message-ID: <001801c8900c$9016cdc0$0201a8c0@M90> Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. It just shows how little you read from my posts. I have clearly stated that I know nothing. Your response is two pages of stuff that I have no clue what it is and am entirely incapable of understanding, then you state that is only half the solution and it is now time for me to go write the other half. OTOH look at Elizabeth's solution. It apparently works and is compact and readable. And no snotty "now go learn enough to be worthy to be in my presence" comments. Yes, Robert, it was a huge waste of MY time, and probably yours. I have no doubt that you know this stuff, you are just useless to me. It is not my fault that you are useless to me BTW. Take off your Priest robes, roll up your sleeves, get the "tone" out of your voice and write simple code with explanations of what it does and you could be helpful. Until such time, do not bother to respond to my requests for help because you are useless to me, and you are just irritating (apparently your intent). If you want to be treated as the professional that you seem to be, act like it. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 8:55 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, So the code I sent you for a parameterized stored procedure to do everything except the restore was "less than useful." I apologize for the "huge waste of everybody's time" (including mine) to give you a good, solid, viable way of solving your problem. Robert At 09:33 PM 3/26/2008, you wrote: >So yea, for some reason I do find this list less than useful. A full >day of lectures, and ONE response that actually looks like it might be helpful. >Thanks Elizabeth! _______________________________________________ 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 Mar 27 08:22:13 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 09:22:13 -0400 Subject: [dba-SQLServer] Create DB and Backup DB In-Reply-To: <200803252107.m2PL7G8Z026082@databaseadvisors.com> References: <200803252107.m2PL7G8Z026082@databaseadvisors.com> Message-ID: <001901c8900d$928f0440$0201a8c0@M90> Robert, LOOK at what you write. Now imagine sending this to your mother. She knows just slightly less TSQL that I do (and I have PLAINLY STATED THAT!!!). Do you see a SINGLE comment? Anywhere? But I will definitely get right on "doing the research to get the SQL to do the restore." Totally useless to me. But I genuflect in your general direction oh high and mighty one. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Tuesday, March 25, 2008 5:06 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Create DB and Backup DB John, Below is the code to create a DB and Backup a DB. I will let you do the research and get the SQL to do the restore. It is a bit more than your requested single line though. What you want to do is restore the backup you just created to the DB you created. Robert P.S. While you do need to look for line wraps, it is not a problem like VBA. CREATE PROCEDURE dbo. pCreate_Load_DB @DBNameCreate varchar ( 64 ), @DBNameBackup varchar ( 64 ), @data_path nvarchar ( 256 ) = NULL, @BackupLocation varchar ( 500 ) = null, @Drive char ( 1 ), @InstanceName sysname = null, @Drive varchar ( 1 ) = null AS BEGIN SET NOCOUNT ON ; DECLARE @Sql nvarchar ( max ), @ErrorMessage varchar ( 500 ) SET @ErrorMessage = 'No Error' IF @data_path IS NULL BEGIN SET @data_path = ( SELECT SUBSTRING ( physical_name , 1, CHARINDEX ( N 'master.mdf' , LOWER ( physical_name )) - 1) FROM master. sys.master_files WHERE database_id = 1 AND file_id = 1 ) ; END -- execute the CREATE DATABASE statement SET @Sql = 'CREATE DATABASE Sales ON ( NAME = ' + @DBNameCreate + '_dat, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'dat.mdf' + CHAR ( 39 ) + ', SIZE = 10, FILEGROWTH = 5 ) LOG ON ( NAME = ' + @DBNameCreate + '_log, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'log.ldf' + CHAR ( 39 ) + ', SIZE = 5MB )' EXEC sp_executesql @Sql SET @Drive = 'F' SET @InstanceName = CAST ( ISNULL ( SERVERPROPERTY ( 'InstanceName' ), SERVERPROPERTY ( 'ServerName' )) AS sysname ) SET @BackupLocation = @Drive + ':\SQL_Backups\' + @InstanceName + '\' BEGIN TRY SET @SQL = 'BACKUP DATABASE ' + @DBNameBackup + ' TO DISK=' + CHAR ( 39 ) + @BackupLocation + @DBNameBackup + '_BACKUP.BAK' + CHAR ( 39 ) + ' WITH INIT' EXEC sp_ExecuteSql @SQL -- truncate the log files BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY SIMPLE' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + char ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + char ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'TRUE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN CHECKPOINT END BEGIN SET @Sql = 'DBCC SHRINKFILE (' + @DBNameBackup + '_Log,1)' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + char ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + char ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'FALSE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY FULL' EXEC sp_executesql @Sql END END TRY BEGIN CATCH SELECT @ErrorMessage = ERROR_MESSAGE () ; END CATCH END _______________________________________________ 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 Mar 27 08:34:23 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 09:34:23 -0400 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters In-Reply-To: References: Message-ID: <001a01c8900f$456beff0$0201a8c0@M90> Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 Mar 27 08:36:37 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 06:36:37 -0700 Subject: [dba-SQLServer] Copy a database using a stored procedure or function Message-ID: I have asked for the members on this list to be courteous to each other. All we have is bashing right then left. Nothing is being accomplished when everyone is acting like school children!! John, I don't really care if someone's response was useless to you, you don't have to respond in such a raw and rude manner. Its responses like those that begin these sort of threads, it is nobody elses fault on this list that you are frustrated. Everyone on this thread needs to take a breath and return to the topic, which I belive John earlier stated is now fixed thanks to Elizabeths code. And unless anyone else has improvements on such a suggestion this thread is now closed. __ Francisco Dba-SqlServer List Moderator On 3/27/08, jwcolby wrote: > Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. It just > shows how little you read from my posts. I have clearly stated that I know > nothing. Your response is two pages of stuff that I have no clue what it is > and am entirely incapable of understanding, then you state that is only half > the solution and it is now time for me to go write the other half. > > OTOH look at Elizabeth's solution. It apparently works and is compact and > readable. And no snotty "now go learn enough to be worthy to be in my > presence" comments. > > Yes, Robert, it was a huge waste of MY time, and probably yours. > > I have no doubt that you know this stuff, you are just useless to me. It is > not my fault that you are useless to me BTW. > > Take off your Priest robes, roll up your sleeves, get the "tone" out of your > voice and write simple code with explanations of what it does and you could > be helpful. Until such time, do not bother to respond to my requests for > help because you are useless to me, and you are just irritating (apparently > your intent). > > If you want to be treated as the professional that you seem to be, act like > it. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. > Stewart > Sent: Thursday, March 27, 2008 8:55 AM > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction > > John, > > So the code I sent you for a parameterized stored procedure to do everything > except the restore was "less than useful." > > I apologize for the "huge waste of everybody's time" (including > mine) to give you a good, solid, viable way of solving your problem. > > Robert > > At 09:33 PM 3/26/2008, you wrote: > >So yea, for some reason I do find this list less than useful. A full > >day of lectures, and ONE response that actually looks like it might be > helpful. > >Thanks Elizabeth! > > > _______________________________________________ > 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 Gmail for mobile | mobile.google.com -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Thu Mar 27 08:43:02 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 09:43:02 -0400 Subject: [dba-SQLServer] Copy a database using a stored procedure orfunction In-Reply-To: <200803271246.m2RCkJ2H015681@databaseadvisors.com> References: <200803271246.m2RCkJ2H015681@databaseadvisors.com> Message-ID: <001b01c89010$7ac29c70$0201a8c0@M90> Can you say backpedal? Baiting is acting like a professional? If you want to be treated as a professional, act like one. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 8:46 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, You can dish it out but not take it. I am not "green." I was simply baiting you. You swallowed hook line and sinker. I really could care less how you make your living. The point is, just ask for help and stop ranting about the poor quality of the tools. If you don't like them, then try doing the same thing with Oracle or MySql. Then you will understand archaic. Treat us as the professionals we are and I will do the same for you. Paul said it very well. Robert At 04:16 PM 3/26/2008, you wrote: >Date: Wed, 26 Mar 2008 16:29:33 -0400 >From: "jwcolby" >Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction >To: "'Discussion concerning MS SQL Server'" > >Message-ID: <003401c88f80$1a4eb210$0201a8c0 at M90> >Content-Type: text/plain; charset="us-ascii" > >Robert, you are being an ass. Bulk mail is nothing more than advertising. >You get advertised on tv, on radio, on every web page and on your doorstep. >The advertising on tv and radio and on the web is wasting electricity >but I don't see you getting all green about that. If you want to rant >about advertising, go to a list about that subject. > >For bulk mail there are opt out lists, go get on one. I get NO junk mail. >Spammers are a whole different breed and are by and large criminals. >To call me one is an unwarranted insult and I would appreciate it if >you would cease. > >KNOCK IT OFF WITH THE CRAP AT DIRECTED AT ME. It matters not a whit to >me whether you like it, what matters to me is that you use the SQL >Server list to rant about your personal opinions about such stuff. >This is also not a list to rant about abortion, or Christianity, or ... > >We have an off topic list, take that nonsense there. > >John W. Colby _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Gustav at cactus.dk Thu Mar 27 08:48:55 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 27 Mar 2008 14:48:55 +0100 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters Message-ID: Hi John I think you are trapped by the single/double quote syntax for embedded strings just like when you build string expressions form strings in VBA. Look in Robert's code how he used Chr(34) to wrap string. But your trouble is why I suggested to lift this whole thing out of T-SQL into VB.Net (from where you control the complete process anyway, right?). /gustav >>> jwcolby at colbyconsulting.com 27-03-2008 14:34 >>> Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 From Gustav at cactus.dk Thu Mar 27 08:51:28 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 27 Mar 2008 14:51:28 +0100 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters Message-ID: Hi John Oops, should be: CHAR ( 39 ) > Look in Robert's code how he used Chr(34) to wrap string. /gustav From fhtapia at gmail.com Thu Mar 27 08:55:42 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 06:55:42 -0700 Subject: [dba-SQLServer] CLOSED -- Copy a database using a stored procedure or function Message-ID: If those are the only comments you can have on this thread then this thread is DEAD Please refrain posting anything other than the intended thread topics. This thread appears to be unrsolveable by the intrested parties, therefor this thread is dead. On 3/27/08, jwcolby wrote: > Can you say backpedal? > > Baiting is acting like a professional? If you want to be treated as a > professional, act like one. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. > Stewart > Sent: Thursday, March 27, 2008 8:46 AM > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction > > John, > > You can dish it out but not take it. > > I am not "green." I was simply baiting you. > You swallowed hook line and sinker. I really could care less how you make > your living. > > The point is, just ask for help and stop ranting about the poor quality of > the tools. If you don't like them, then try doing the same thing with Oracle > or MySql. > Then you will understand archaic. > > Treat us as the professionals we are and I will do the same for you. > > Paul said it very well. > > Robert > > At 04:16 PM 3/26/2008, you wrote: > >Date: Wed, 26 Mar 2008 16:29:33 -0400 > >From: "jwcolby" > >Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > > orfunction > >To: "'Discussion concerning MS SQL Server'" > > > >Message-ID: <003401c88f80$1a4eb210$0201a8c0 at M90> > >Content-Type: text/plain; charset="us-ascii" > > > >Robert, you are being an ass. Bulk mail is nothing more than advertising. > >You get advertised on tv, on radio, on every web page and on your doorstep. > >The advertising on tv and radio and on the web is wasting electricity > >but I don't see you getting all green about that. If you want to rant > >about advertising, go to a list about that subject. > > > >For bulk mail there are opt out lists, go get on one. I get NO junk mail. > >Spammers are a whole different breed and are by and large criminals. > >To call me one is an unwarranted insult and I would appreciate it if > >you would cease. > > > >KNOCK IT OFF WITH THE CRAP AT DIRECTED AT ME. It matters not a whit to > >me whether you like it, what matters to me is that you use the SQL > >Server list to rant about your personal opinions about such stuff. > >This is also not a list to rant about abortion, or Christianity, or ... > > > >We have an off topic list, take that nonsense there. > > > >John W. Colby > > > _______________________________________________ > 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 Gmail for mobile | mobile.google.com -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Thu Mar 27 09:01:30 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 10:01:30 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: References: Message-ID: <001f01c89013$0f306f70$0201a8c0@M90> Francisco, Everyone on this list needs to: 1) READ THE QUESTION. 2) RESPOND TO THE QUESTION, in a manner that is at all likely to be useful to the person asking the question. 3) Leave the lectures to a new thread of your own making. Francisco, You keep coming back to ME. I asked a simple question and got useless junk and lectures about the right way to do things. I got exactly TWO responses that were useful and indicated that the respondent even LOOKED at my question, one from Elizabeth and another from James, both of whom I thanked. Robert writes a Doctoral thesis and then inserts crap like "now you can go learn enough to even be worthy of being here" and you don't say a word. If you want to be a moderator why don't you step in at the very beginning and ask the people to respond to the questions in a useful and civil manner, at a level likely to be useful to the person. I don't need their lectures, and I don't need yours (and I don't need a Doctoral thesis). Please everybody, do not respond to the thread unless you have actually READ it and are willing to write answers on my level. And start your own threads if you want to discuss "the right way to" or "how you should NEVER" or write a Doctoral thesis, or anything else not directly related to my question. The question is not answered, though I am certainly on my way, and have started another thread to discuss it further. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 9:37 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction I have asked for the members on this list to be courteous to each other. All we have is bashing right then left. Nothing is being accomplished when everyone is acting like school children!! John, I don't really care if someone's response was useless to you, you don't have to respond in such a raw and rude manner. Its responses like those that begin these sort of threads, it is nobody elses fault on this list that you are frustrated. Everyone on this thread needs to take a breath and return to the topic, which I belive John earlier stated is now fixed thanks to Elizabeths code. And unless anyone else has improvements on such a suggestion this thread is now closed. __ Francisco Dba-SqlServer List Moderator On 3/27/08, jwcolby wrote: > Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. > It just shows how little you read from my posts. I have clearly > stated that I know nothing. Your response is two pages of stuff that > I have no clue what it is and am entirely incapable of understanding, > then you state that is only half the solution and it is now time for me to go write the other half. > > OTOH look at Elizabeth's solution. It apparently works and is compact > and readable. And no snotty "now go learn enough to be worthy to be > in my presence" comments. > > Yes, Robert, it was a huge waste of MY time, and probably yours. > > I have no doubt that you know this stuff, you are just useless to me. > It is not my fault that you are useless to me BTW. > > Take off your Priest robes, roll up your sleeves, get the "tone" out > of your voice and write simple code with explanations of what it does > and you could be helpful. Until such time, do not bother to respond > to my requests for help because you are useless to me, and you are > just irritating (apparently your intent). > > If you want to be treated as the professional that you seem to be, act > like it. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. > Stewart > Sent: Thursday, March 27, 2008 8:55 AM > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction > > John, > > So the code I sent you for a parameterized stored procedure to do > everything except the restore was "less than useful." > > I apologize for the "huge waste of everybody's time" (including > mine) to give you a good, solid, viable way of solving your problem. > > Robert > > At 09:33 PM 3/26/2008, you wrote: > >So yea, for some reason I do find this list less than useful. A full > >day of lectures, and ONE response that actually looks like it might > >be > helpful. > >Thanks Elizabeth! > > > _______________________________________________ > 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 Gmail for mobile | mobile.google.com -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Elizabeth.J.Doering at wellsfargo.com Thu Mar 27 09:11:35 2008 From: Elizabeth.J.Doering at wellsfargo.com (Elizabeth.J.Doering at wellsfargo.com) Date: Thu, 27 Mar 2008 09:11:35 -0500 Subject: [dba-SQLServer] Copy a database using a stored procedureorfunction References: <200803271256.m2RCuJAU021373@databaseadvisors.com> <001801c8900c$9016cdc0$0201a8c0@M90> Message-ID: I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 8:15 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a stored procedureorfunction Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. It just shows how little you read from my posts. I have clearly stated that I know nothing. Your response is two pages of stuff that I have no clue what it is and am entirely incapable of understanding, then you state that is only half the solution and it is now time for me to go write the other half. OTOH look at Elizabeth's solution. It apparently works and is compact and readable. And no snotty "now go learn enough to be worthy to be in my presence" comments. Yes, Robert, it was a huge waste of MY time, and probably yours. I have no doubt that you know this stuff, you are just useless to me. It is not my fault that you are useless to me BTW. Take off your Priest robes, roll up your sleeves, get the "tone" out of your voice and write simple code with explanations of what it does and you could be helpful. Until such time, do not bother to respond to my requests for help because you are useless to me, and you are just irritating (apparently your intent). If you want to be treated as the professional that you seem to be, act like it. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 8:55 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, So the code I sent you for a parameterized stored procedure to do everything except the restore was "less than useful." I apologize for the "huge waste of everybody's time" (including mine) to give you a good, solid, viable way of solving your problem. Robert At 09:33 PM 3/26/2008, you wrote: >So yea, for some reason I do find this list less than useful. A full >day of lectures, and ONE response that actually looks like it might be helpful. >Thanks Elizabeth! _______________________________________________ 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 Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. From James at fcidms.com Thu Mar 27 09:14:05 2008 From: James at fcidms.com (James Barash) Date: Thu, 27 Mar 2008 10:14:05 -0400 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters In-Reply-To: <001a01c8900f$456beff0$0201a8c0@M90> Message-ID: <008b01c89014$d11c5620$6a00a8c0@fci.local> John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 From robert at webedb.com Thu Mar 27 09:14:46 2008 From: robert at webedb.com (Robert L. Stewart) Date: Thu, 27 Mar 2008 09:14:46 -0500 Subject: [dba-SQLServer] Automated Backup and restore In-Reply-To: References: Message-ID: <200803271416.m2REGEFS009236@databaseadvisors.com> For everyone except John (would not want to waste his time) CREATE PROCEDURE [dbo].[usp_CopyDatabase] @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN SET NOCOUNT ON; DECLARE @Sql varchar(max) SET @Sql = 'BACKUP DATABASE ' + @strDBNameFrom + ' TO DISK = ' + @strDBDir + @strDBNameFrom + '.bak WITH INIT' EXEC sp_executesql @Sql SET @Sql = 'RESTORE FILELISTONLY FROM DISK = ' + @strDBDir + @strDBNameFrom + '.bak' EXEC sp_executesql @Sql SET @Sql = RESTORE DATABASE ' + @strDBNameTo + ' FROM DISK = ' + @strDBDir + @strDBNameFrom + '.bak WITH MOVE ' + @strDBNameFrom + '_Data' TO ' + @strDBDir + @strDBNameTo + '.mdf, MOVE ' + @strDBNameFrom + '_Log TO ' + @strDBDir + @strDBNameTo + '.ldf' EXEC sp_executesql @Sql END I did not lookup the exact syntax. You might meed to enclose the dbname and other parts of the variables in CHAR(39), the single quote. Robert From jwcolby at colbyconsulting.com Thu Mar 27 09:28:13 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 10:28:13 -0400 Subject: [dba-SQLServer] Copy a database using a storedprocedureorfunction In-Reply-To: References: <200803271256.m2RCuJAU021373@databaseadvisors.com><001801c8900c$9016cdc0$0201a8c0@M90> Message-ID: <002101c89016$ca63fd90$0201a8c0@M90> ROTFL. Liz, you are a nice lady. I will be honest with you, being in the laity I find BOL useless. The explanations are endless loops of code that does not run as typed, and references to other entries of code that does not run as typed, and pages of arcane syntax that are no doubt useful to those more directly involved in SQL Server. There is a good reason that there are aftermarket books (which I own AND READ) to explain this stuff. I have read chapters Chapters 11, 12 and 13 of Robert Vieira's excellent Beginning SQL Server 2005 Programming and I am slowly learning, but no surprise, the question I asked is a bit beyond what a book like that can even consider. As I have clearly stated, I am not an SQL Server admin, programmer, manager or anything else. I just use it, quite successfully all things considered. Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 10:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz From jwcolby at colbyconsulting.com Thu Mar 27 09:38:08 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 10:38:08 -0400 Subject: [dba-SQLServer] Automated Backup and restore In-Reply-To: <200803271416.m2REGEFS009236@databaseadvisors.com> References: <200803271416.m2REGEFS009236@databaseadvisors.com> Message-ID: <002201c89018$2d34a9a0$0201a8c0@M90> Thanks Robert, that is a very useful piece of code. Simple enough that even I can understand it, but complete enough to make it usable as it is. Still a little tone but you are making progress. ;-) I really and truly do appreciate examples like this. I can read it, I can understand it, and I can now go to it and see how to do other things that this code also demonstrates. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 10:15 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Automated Backup and restore For everyone except John (would not want to waste his time) CREATE PROCEDURE [dbo].[usp_CopyDatabase] @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN SET NOCOUNT ON; DECLARE @Sql varchar(max) SET @Sql = 'BACKUP DATABASE ' + @strDBNameFrom + ' TO DISK = ' + @strDBDir + @strDBNameFrom + '.bak WITH INIT' EXEC sp_executesql @Sql SET @Sql = 'RESTORE FILELISTONLY FROM DISK = ' + @strDBDir + @strDBNameFrom + '.bak' EXEC sp_executesql @Sql SET @Sql = RESTORE DATABASE ' + @strDBNameTo + ' FROM DISK = ' + @strDBDir + @strDBNameFrom + '.bak WITH MOVE ' + @strDBNameFrom + '_Data' TO ' + @strDBDir + @strDBNameTo + '.mdf, MOVE ' + @strDBNameFrom + '_Log TO ' + @strDBDir + @strDBNameTo + '.ldf' EXEC sp_executesql @Sql END I did not lookup the exact syntax. You might meed to enclose the dbname and other parts of the variables in CHAR(39), the single quote. Robert _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Thu Mar 27 09:38:31 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 07:38:31 -0700 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters In-Reply-To: <001a01c8900f$456beff0$0201a8c0@M90> Message-ID: <0JYE00ITI8O8KUN0@vms046.mailsrvcs.net> John/Gustav, You can't marry parameters and SQL commands in the same sentence as per your code example . Therefore... BACKUP DATABASE @strDBNameFrom TO DISK = @strDBDir + @strDBNameFrom + '.bak' Will not work because SQL thinks of parameters in terms of, well criteria for select, insert and update type queries. You need to assign the SQL commands to a SQL variable that you have to declare as such... DECLARE @sql varchar(1000) -- I believe 4000 is the max. SET @sql = 'BACKUP DATABASE ' + CHR(39) + @strDBNameFrom ' + CHR(39) + ' TO DISK = ' + CHR(39) + @strDBDir + @strDBNameFrom + '.bak' + CHR(39) And then you need to execute the SQL command using another SQL command... EXEC (@sql) -- this will run the dynamic parametized SQL query to accomplish the task of backing up the database. --Now to the restore portion... --note the use of CHR(39) ; single apostrophe as delimeters SET @sql = 'RESTORE DATABASE MLV FROM DISK = ' + CHR(39) + 'C:\temp\MLVBak.BAK' + CHR(39) SET @sql = @sql + ' WITH MOVE ' + CHR(39) + 'MLV_Data' + CHR(39) + ' TO ' + CHR(39) + 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_Data.mdf' + ', ' SET @sql = @sql + 'MOVE ' + CHR(39) + 'MLV_log' + CHR(39) + ' TO ' + CHR(39) + 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_log.LDF' + CHR(39) --To debug uncomment the line below (i.e remove the --; -- and /* */ are treated as comment delimiters in SQL syntax) --PRINT @sql --this should give you exactly the following command commented below /* RESTORE DATABASE MLV FROM DISK = 'C:\inetpub\wwwroot\pvp\MLVBak.BAK' WITH MOVE 'MLV_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_Data.mdf', MOVE 'MLV_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_log.LDF' */ --To run it use EXEC command EXEC (@sql) That's it in a nutshell... NOTES: for John 1. Robert's sproc is spot on. What he didn't provide were comments such as why it needs to be like this and not like that, etc... 2. Robert DID provide comments. Simple, yes but you are wrong in saying he didn't provide comments. Take a look at his code again and wherever you see the double dash (--), those are comments. 3. (including Gustav)...it doesn't matter what you name your physical MDF or LDF files, whether you append _Data or _Log to them. What matters is when you search for them in the file system you can easily spot them and associate them with each other because SQL server data files ALWAYS come with SQL server log files (unless of course you specify the no logs option). 4. For your non-relational application John, you can simply do away with TRANSCATION LOG files unless you need to rollback changes. It makes the processing (CRUD operations) go faster since SQL doesn't have to log everything that takes place. 5. Additional tips...if you simply want to "refresh" a table (meaning wipe the data out), use TRUNCATE TABLE (< > are not needed of course when you type the command) ...it skips the transaction logs and sets the identity (autonumber for you Access nubees) field back to 1. It is way faster than DELETE FROM
. Finally...let's just all lighten up and quit being childish. This is not a my thingy is bigger than your thingy deal. It's just SQL server...and by the way for this interested in SQL server 2008, go to a Microsoft event and get a FREE copy of SQL server 2008, Visual Studio 2008 and Windows Server 2008. That's what I'm gonna do later on today. NYAH, NYAH, NYAH, NA...NA...NA LOL! Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 6:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 From ebarro at verizon.net Thu Mar 27 09:41:45 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 07:41:45 -0700 Subject: [dba-SQLServer] Copy a database using a stored procedureorfunction In-Reply-To: Message-ID: <0JYE00HQB8OVJFS0@vms173003.mailsrvcs.net> So John...Elizabeth searched BOL for 'copy database' and she found it in less time than it took for you to formulate your original question? What's up with that? :) Me thinks you need "Google Search"...reminds me of what the users wanted for searching a component parts list in our company. When asked what types of searches they conduct they simply said "we want to search on everything". Ya right! They wanted "Google Search" all right. I don't go to BOL either John so don't feel guilty. :) I go to "Google Search". -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 7:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 8:15 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a stored procedureorfunction Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. It just shows how little you read from my posts. I have clearly stated that I know nothing. Your response is two pages of stuff that I have no clue what it is and am entirely incapable of understanding, then you state that is only half the solution and it is now time for me to go write the other half. OTOH look at Elizabeth's solution. It apparently works and is compact and readable. And no snotty "now go learn enough to be worthy to be in my presence" comments. Yes, Robert, it was a huge waste of MY time, and probably yours. I have no doubt that you know this stuff, you are just useless to me. It is not my fault that you are useless to me BTW. Take off your Priest robes, roll up your sleeves, get the "tone" out of your voice and write simple code with explanations of what it does and you could be helpful. Until such time, do not bother to respond to my requests for help because you are useless to me, and you are just irritating (apparently your intent). If you want to be treated as the professional that you seem to be, act like it. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 8:55 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, So the code I sent you for a parameterized stored procedure to do everything except the restore was "less than useful." I apologize for the "huge waste of everybody's time" (including mine) to give you a good, solid, viable way of solving your problem. Robert At 09:33 PM 3/26/2008, you wrote: >So yea, for some reason I do find this list less than useful. A full >day of lectures, and ONE response that actually looks like it might be helpful. >Thanks Elizabeth! _______________________________________________ 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 Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Thu Mar 27 09:43:45 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 07:43:45 -0700 Subject: [dba-SQLServer] Copy a database using a storedprocedureorfunction In-Reply-To: <002101c89016$ca63fd90$0201a8c0@M90> Message-ID: <0JYE00IR88WYKNN0@vms046.mailsrvcs.net> Hehehehe...John, maybe you should go buy Paul Nielsen's SQL Server 2005 BIBLE! Now *THAT* might get you into the priesthood yet. There's still hope for you John! And that's the good news!!! LOL... Ah yes...a little humor does help. BUY IT NOW!!! DO IT! Hahahahhahahaha.... -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 7:28 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction ROTFL. Liz, you are a nice lady. I will be honest with you, being in the laity I find BOL useless. The explanations are endless loops of code that does not run as typed, and references to other entries of code that does not run as typed, and pages of arcane syntax that are no doubt useful to those more directly involved in SQL Server. There is a good reason that there are aftermarket books (which I own AND READ) to explain this stuff. I have read chapters Chapters 11, 12 and 13 of Robert Vieira's excellent Beginning SQL Server 2005 Programming and I am slowly learning, but no surprise, the question I asked is a bit beyond what a book like that can even consider. As I have clearly stated, I am not an SQL Server admin, programmer, manager or anything else. I just use it, quite successfully all things considered. Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 10:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Thu Mar 27 09:53:40 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 07:53:40 -0700 Subject: [dba-SQLServer] Copy a database using a storedprocedureorfunction In-Reply-To: <002101c89016$ca63fd90$0201a8c0@M90> Message-ID: <0JYE00IBE9DIJLO0@vms046.mailsrvcs.net> Geez John... This is no way to treat a lady! "Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there." It's like telling her..."I like you but I don't like you that much...besides I got what I want from you" ;) -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 7:28 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction ROTFL. Liz, you are a nice lady. I will be honest with you, being in the laity I find BOL useless. The explanations are endless loops of code that does not run as typed, and references to other entries of code that does not run as typed, and pages of arcane syntax that are no doubt useful to those more directly involved in SQL Server. There is a good reason that there are aftermarket books (which I own AND READ) to explain this stuff. I have read chapters Chapters 11, 12 and 13 of Robert Vieira's excellent Beginning SQL Server 2005 Programming and I am slowly learning, but no surprise, the question I asked is a bit beyond what a book like that can even consider. As I have clearly stated, I am not an SQL Server admin, programmer, manager or anything else. I just use it, quite successfully all things considered. Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 10:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz _______________________________________________ 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 Mar 27 10:00:01 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:00:01 -0400 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters In-Reply-To: <008b01c89014$d11c5620$6a00a8c0@fci.local> References: <001a01c8900f$456beff0$0201a8c0@M90> <008b01c89014$d11c5620$6a00a8c0@fci.local> Message-ID: <002301c8901b$3c325f30$0201a8c0@M90> Thanks James, much appreciated. I copied it in and it Executes as entered. I am quite capable of reading that example and understanding what you are doing, and I very much appreciate the simplicity but functionality. First question: RESTORE FILELISTONLY FROM DISK = @FileName BOL actually helps me now... And says that you are getting back a list of the file names involved. But where does the list of names go? IOW it isn't obvious that you are setting some variable to be equal to that list of filenames. Are we actually getting it back and using the list somewhere? Or is this just some code to demonstrate a principal that could be useful sometime? Or does executing the Restore Filelist cause SQL Server to get "primed" internally to do the next step? Next question, where do I place this USP? I read somewhere that if it is placed in the master database then it is accessible everywhere, yet Arthur indicates that he does not like doing that. Can I place it right in the DB that I am copying? That is my template and contains all of the UDPs that I have designed so far to perform all of this stuff for me. Can I execute code from a database that I am about to make a copy of? John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Elizabeth.J.Doering at wellsfargo.com Thu Mar 27 10:03:10 2008 From: Elizabeth.J.Doering at wellsfargo.com (Elizabeth.J.Doering at wellsfargo.com) Date: Thu, 27 Mar 2008 10:03:10 -0500 Subject: [dba-SQLServer] Copy a database usinga storedprocedureorfunction References: <0JYE00IBE9DIJLO0@vms046.mailsrvcs.net> Message-ID: Eric, you have to adjust your expections. :) -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 9:54 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storedprocedureorfunction Geez John... This is no way to treat a lady! "Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there." It's like telling her..."I like you but I don't like you that much...besides I got what I want from you" ;) -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 7:28 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction ROTFL. Liz, you are a nice lady. I will be honest with you, being in the laity I find BOL useless. The explanations are endless loops of code that does not run as typed, and references to other entries of code that does not run as typed, and pages of arcane syntax that are no doubt useful to those more directly involved in SQL Server. There is a good reason that there are aftermarket books (which I own AND READ) to explain this stuff. I have read chapters Chapters 11, 12 and 13 of Robert Vieira's excellent Beginning SQL Server 2005 Programming and I am slowly learning, but no surprise, the question I asked is a bit beyond what a book like that can even consider. As I have clearly stated, I am not an SQL Server admin, programmer, manager or anything else. I just use it, quite successfully all things considered. Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 10:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz _______________________________________________ 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 From ebarro at verizon.net Thu Mar 27 10:06:38 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 08:06:38 -0700 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters In-Reply-To: Message-ID: <0JYE00LDU9Z3G7Q0@vms042.mailsrvcs.net> Gustav, .NET is not the tool to use for backing up and restoring SQL databases. Granted, you may find solutions out there that do that it won't be optimal. Besides, the tool is already there for you to use. Just use it. I would use .NET as a UI to call the sprocs but not everything can be done using .NET. It's just as bad as when the *priests* insist that SQL is the end all and be all and that you'll go to HELL if you don't do it the TSQL way. Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 6:49 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters Hi John I think you are trapped by the single/double quote syntax for embedded strings just like when you build string expressions form strings in VBA. Look in Robert's code how he used Chr(34) to wrap string. But your trouble is why I suggested to lift this whole thing out of T-SQL into VB.Net (from where you control the complete process anyway, right?). /gustav >>> jwcolby at colbyconsulting.com 27-03-2008 14:34 >>> Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 Mar 27 10:12:18 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 08:12:18 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <001f01c89013$0f306f70$0201a8c0@M90> References: <001f01c89013$0f306f70$0201a8c0@M90> Message-ID: John, I've come back to you on the basis that this new thread even has to get started. All posts are welcomed so long as they are ontopic. Read the database asvisors netiquette rules. Best of practices are completly within scope, I see that type of posts on the access list all the time. Because on this list we deal with really big dbs in general, best of practices are completly appropriate. On 3/27/08, jwcolby wrote: > Francisco, > > Everyone on this list needs to: > > 1) READ THE QUESTION. > 2) RESPOND TO THE QUESTION, in a manner that is at all likely to be useful > to the person asking the question. > 3) Leave the lectures to a new thread of your own making. > > Francisco, > > You keep coming back to ME. I asked a simple question and got useless junk > and lectures about the right way to do things. I got exactly TWO responses > that were useful and indicated that the respondent even LOOKED at my > question, one from Elizabeth and another from James, both of whom I thanked. > > Robert writes a Doctoral thesis and then inserts crap like "now you can go > learn enough to even be worthy of being here" and you don't say a word. If > you want to be a moderator why don't you step in at the very beginning and > ask the people to respond to the questions in a useful and civil manner, at > a level likely to be useful to the person. I don't need their lectures, and > I don't need yours (and I don't need a Doctoral thesis). > > Please everybody, do not respond to the thread unless you have actually READ > it and are willing to write answers on my level. And start your own threads > if you want to discuss "the right way to" or "how you should NEVER" or write > a Doctoral thesis, or anything else not directly related to my question. > > The question is not answered, though I am certainly on my way, and have > started another thread to discuss it further. > > Thanks, > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco > Tapia > Sent: Thursday, March 27, 2008 9:37 AM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > orfunction > > I have asked for the members on this list to be courteous to each other. > > All we have is bashing right then left. Nothing is being accomplished when > everyone is acting like school children!! > > John, > I don't really care if someone's response was useless to you, you don't > have to respond in such a raw and rude manner. Its responses like those that > begin these sort of threads, it is nobody elses fault on this list that you > are frustrated. Everyone on this thread needs to take a breath and return > to the topic, which I belive John earlier stated is now fixed thanks to > Elizabeths code. And unless anyone else has improvements on such a > suggestion this thread is now closed. > > > __ > Francisco > Dba-SqlServer List Moderator > > > > On 3/27/08, jwcolby wrote: > > Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. > > It just shows how little you read from my posts. I have clearly > > stated that I know nothing. Your response is two pages of stuff that > > I have no clue what it is and am entirely incapable of understanding, > > then you state that is only half the solution and it is now time for me to > go write the other half. > > > > OTOH look at Elizabeth's solution. It apparently works and is compact > > and readable. And no snotty "now go learn enough to be worthy to be > > in my presence" comments. > > > > Yes, Robert, it was a huge waste of MY time, and probably yours. > > > > I have no doubt that you know this stuff, you are just useless to me. > > It is not my fault that you are useless to me BTW. > > > > Take off your Priest robes, roll up your sleeves, get the "tone" out > > of your voice and write simple code with explanations of what it does > > and you could be helpful. Until such time, do not bother to respond > > to my requests for help because you are useless to me, and you are > > just irritating (apparently your intent). > > > > If you want to be treated as the professional that you seem to be, act > > like it. > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > -----Original Message----- > > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. > > Stewart > > Sent: Thursday, March 27, 2008 8:55 AM > > To: dba-sqlserver at databaseadvisors.com > > Subject: Re: [dba-SQLServer] Copy a database using a stored procedure > > orfunction > > > > John, > > > > So the code I sent you for a parameterized stored procedure to do > > everything except the restore was "less than useful." > > > > I apologize for the "huge waste of everybody's time" (including > > mine) to give you a good, solid, viable way of solving your problem. > > > > Robert > > > > At 09:33 PM 3/26/2008, you wrote: > > >So yea, for some reason I do find this list less than useful. A full > > >day of lectures, and ONE response that actually looks like it might > > >be > > helpful. > > >Thanks Elizabeth! > > > > > > _______________________________________________ > > 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 Gmail for mobile | mobile.google.com > > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > 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 Gmail for mobile | mobile.google.com -Francisco http://sqlthis.blogspot.com | Tsql and More... From David at sierranevada.com Thu Mar 27 10:02:26 2008 From: David at sierranevada.com (David Lewis) Date: Thu, 27 Mar 2008 08:02:26 -0700 Subject: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 In-Reply-To: References: Message-ID: Hi John: A few thoughts unrelated to the copy database issue: I'm not sure I follow everything you do, but it sounds like you receive raw data, scrub it, then use it as a basis of reports (run queries, send the results to the client...). It also sounds like you physically save the recordset results of those queries, and that the underlying base table does not change. If that is the case, why not save only the queries you run, rather than the rows they return? Create the queries as either views, or better yet build views and call them from stored procedures that can accept where clauses, topN parameters, etc.? That approach would mean you don't have to manage tables, or entire databases, and instead only manage views and stored procedures. That, by the way, is a use of sql server that is more in line with how it was designed. One approach might be to have some base views, and a table that might look like: tblOrders Customer RequestDate BaseView WhereClause TopClause Etc. Some sample rows might be: Abc Company 3/1/08 Column1, Column2 FROM dbo.vwSomeBaseView WHERE BLAH = 'Blah' AND BLAHBLAH= ' BlahB%' Top 3000 Abc Company 3/12/08 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Top 10000 Using this approach, you only need to build a smaller number of views, you keep a record of who asked for what, when, and you can recreate the actual query very simply. A stored procedure to do that might look like: CREATE PROCEDURE usp_GetResultSet @Customer VARCHAR(50) , at Date DATETIME AS DECLARE @strSQL VARCHAR(500) DECLARE @Top VARCHAR(50) SELECT @strSQL= 'SELECT ' + ISNULL(TopClause,'') + BaseView + WhereClause FROM tblOrders WHERE Customer=@Customer AND RequestDate=@Date PRINT @strSQL --just for debugging... EXEC(@strSQL) Calling this procedure as usp_GetResultSet 'Abc Company','3/12/08' would give you: SELECT Top 10000 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Voila, no messy storing of new tables, etc. I dunno, maybe that helps keep things tidier? What I am (was, I have given up) trying to do is get some very simple help on some very simple things, or they should be simple. I have already built a template database for "filling orders" from this database. My client asks me for a count (about 16 counts actually) of all the people who... Grouped by. SIMPLE stuff, and I have all of that working (in sql server) and have for a long time (years). I modify a couple of existing views to do the Where... Part, then manually run the count views. Copy the result "table" into a dedicated sheet of an excel workbook. 16 pages, one page for each "count", by state, by income bracket, by age bands and so forth. All working quite well. BTW I keep these as a dedicated database for that order (named after the order in fact) because I may need it later. Not sophisticated but simple and it works. That is the "template database". In fact there are two different kinds of orders. The second kind is "OK, now give me N thousand names / addresses from that count you gave me before". Again, I have been doing this stuff for quite some time, using a strange mixture of SQL Server, a third party Address Validation program running on a server here in my office, and Access (for the final phase). I have been doing all of that for months as well (years actually, I am just getting much more efficient at it lately). I decided that I could automate this second type of order such that many of the bits and pieces were just done by stored procedures. I have done that as well. All on my own, no Priests involved. 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 ebarro at verizon.net Thu Mar 27 10:25:13 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 08:25:13 -0700 Subject: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 In-Reply-To: Message-ID: <0JYE000XDAU2QVZ0@vms173001.mailsrvcs.net> Oh oh...here we go again...you might do well to read the archives David, otherwise you'll get a rap on your knuckles from JC. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Thursday, March 27, 2008 8:02 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 Hi John: A few thoughts unrelated to the copy database issue: I'm not sure I follow everything you do, but it sounds like you receive raw data, scrub it, then use it as a basis of reports (run queries, send the results to the client...). It also sounds like you physically save the recordset results of those queries, and that the underlying base table does not change. If that is the case, why not save only the queries you run, rather than the rows they return? Create the queries as either views, or better yet build views and call them from stored procedures that can accept where clauses, topN parameters, etc.? That approach would mean you don't have to manage tables, or entire databases, and instead only manage views and stored procedures. That, by the way, is a use of sql server that is more in line with how it was designed. One approach might be to have some base views, and a table that might look like: tblOrders Customer RequestDate BaseView WhereClause TopClause Etc. Some sample rows might be: Abc Company 3/1/08 Column1, Column2 FROM dbo.vwSomeBaseView WHERE BLAH = 'Blah' AND BLAHBLAH= ' BlahB%' Top 3000 Abc Company 3/12/08 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Top 10000 Using this approach, you only need to build a smaller number of views, you keep a record of who asked for what, when, and you can recreate the actual query very simply. A stored procedure to do that might look like: CREATE PROCEDURE usp_GetResultSet @Customer VARCHAR(50) , at Date DATETIME AS DECLARE @strSQL VARCHAR(500) DECLARE @Top VARCHAR(50) SELECT @strSQL= 'SELECT ' + ISNULL(TopClause,'') + BaseView + WhereClause FROM tblOrders WHERE Customer=@Customer AND RequestDate=@Date PRINT @strSQL --just for debugging... EXEC(@strSQL) Calling this procedure as usp_GetResultSet 'Abc Company','3/12/08' would give you: SELECT Top 10000 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Voila, no messy storing of new tables, etc. I dunno, maybe that helps keep things tidier? What I am (was, I have given up) trying to do is get some very simple help on some very simple things, or they should be simple. I have already built a template database for "filling orders" from this database. My client asks me for a count (about 16 counts actually) of all the people who... Grouped by. SIMPLE stuff, and I have all of that working (in sql server) and have for a long time (years). I modify a couple of existing views to do the Where... Part, then manually run the count views. Copy the result "table" into a dedicated sheet of an excel workbook. 16 pages, one page for each "count", by state, by income bracket, by age bands and so forth. All working quite well. BTW I keep these as a dedicated database for that order (named after the order in fact) because I may need it later. Not sophisticated but simple and it works. That is the "template database". In fact there are two different kinds of orders. The second kind is "OK, now give me N thousand names / addresses from that count you gave me before". Again, I have been doing this stuff for quite some time, using a strange mixture of SQL Server, a third party Address Validation program running on a server here in my office, and Access (for the final phase). I have been doing all of that for months as well (years actually, I am just getting much more efficient at it lately). I decided that I could automate this second type of order such that many of the bits and pieces were just done by stored procedures. I have done that as well. All on my own, no Priests involved. 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 Gustav at cactus.dk Thu Mar 27 10:45:38 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 27 Mar 2008 16:45:38 +0100 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters Message-ID: Hi Eric I know, but here we just wish to create a copy of an existing template database. No "backup to a safe place", no volume data, no speed issue, but - and that's the big difference from a normal backup/restore job - a new command every time it is called. So instead of all these parameters just build the command string that is needed while you have VB.Net or Access or whatever running - as a master controller copying files, sending e-mails, and creating Excel files - and push that command to the server engine. I know most of it can be done within SQL Server, but this is where I understand John: why not use the environment and languages you are familiar with? You will, anyway, need some simple GUI to type in start parameters and to read or print result codes or the like and pop a messagebox in case of an error. /gustav >>> ebarro at verizon.net 27-03-2008 16:06:38 >>> Gustav, .NET is not the tool to use for backing up and restoring SQL databases. Granted, you may find solutions out there that do that it won't be optimal. Besides, the tool is already there for you to use. Just use it. I would use .NET as a UI to call the sprocs but not everything can be done using .NET. It's just as bad as when the *priests* insist that SQL is the end all and be all and that you'll go to HELL if you don't do it the TSQL way. Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 6:49 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters Hi John I think you are trapped by the single/double quote syntax for embedded strings just like when you build string expressions form strings in VBA. Look in Robert's code how he used Chr(34) to wrap string. But your trouble is why I suggested to lift this whole thing out of T-SQL into VB.Net (from where you control the complete process anyway, right?). /gustav >>> jwcolby at colbyconsulting.com 27-03-2008 14:34 >>> Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 From jwcolby at colbyconsulting.com Thu Mar 27 10:51:41 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:51:41 -0400 Subject: [dba-SQLServer] Copy a database using astored procedureorfunction In-Reply-To: <0JYE00HQB8OVJFS0@vms173003.mailsrvcs.net> References: <0JYE00HQB8OVJFS0@vms173003.mailsrvcs.net> Message-ID: <000001c89022$73f59020$0201a8c0@M90> I did Google search and got a bunch of "how to use the wizards" stuff. Google has a lot of good stuff, but you really have to know how to phrase the question or you just get "how to use the wizard" type answers. Believe me Eric, I read my books, and I Google before I ever come here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 10:42 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using astored procedureorfunction So John...Elizabeth searched BOL for 'copy database' and she found it in less time than it took for you to formulate your original question? What's up with that? :) Me thinks you need "Google Search"...reminds me of what the users wanted for searching a component parts list in our company. When asked what types of searches they conduct they simply said "we want to search on everything". Ya right! They wanted "Google Search" all right. I don't go to BOL either John so don't feel guilty. :) I go to "Google Search". -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 7:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 8:15 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a stored procedureorfunction Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. It just shows how little you read from my posts. I have clearly stated that I know nothing. Your response is two pages of stuff that I have no clue what it is and am entirely incapable of understanding, then you state that is only half the solution and it is now time for me to go write the other half. OTOH look at Elizabeth's solution. It apparently works and is compact and readable. And no snotty "now go learn enough to be worthy to be in my presence" comments. Yes, Robert, it was a huge waste of MY time, and probably yours. I have no doubt that you know this stuff, you are just useless to me. It is not my fault that you are useless to me BTW. Take off your Priest robes, roll up your sleeves, get the "tone" out of your voice and write simple code with explanations of what it does and you could be helpful. Until such time, do not bother to respond to my requests for help because you are useless to me, and you are just irritating (apparently your intent). If you want to be treated as the professional that you seem to be, act like it. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 8:55 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, So the code I sent you for a parameterized stored procedure to do everything except the restore was "less than useful." I apologize for the "huge waste of everybody's time" (including mine) to give you a good, solid, viable way of solving your problem. Robert At 09:33 PM 3/26/2008, you wrote: >So yea, for some reason I do find this list less than useful. A full >day of lectures, and ONE response that actually looks like it might be helpful. >Thanks Elizabeth! _______________________________________________ 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 Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. _______________________________________________ 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 From jwcolby at colbyconsulting.com Thu Mar 27 10:53:09 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:53:09 -0400 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters In-Reply-To: <0JYE00ITI8O8KUN0@vms046.mailsrvcs.net> References: <001a01c8900f$456beff0$0201a8c0@M90> <0JYE00ITI8O8KUN0@vms046.mailsrvcs.net> Message-ID: <000101c89022$a877a400$0201a8c0@M90> Great stuff Eric, thanks. I copied Gustav's example (with parameters) and it APPEARED to work (executed), though I have not yet called it from another query passing in parameters. I will do that next. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 10:39 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters John/Gustav, You can't marry parameters and SQL commands in the same sentence as per your code example . Therefore... BACKUP DATABASE @strDBNameFrom TO DISK = @strDBDir + @strDBNameFrom + '.bak' Will not work because SQL thinks of parameters in terms of, well criteria for select, insert and update type queries. You need to assign the SQL commands to a SQL variable that you have to declare as such... DECLARE @sql varchar(1000) -- I believe 4000 is the max. SET @sql = 'BACKUP DATABASE ' + CHR(39) + @strDBNameFrom ' + CHR(39) + ' TO DISK = ' + CHR(39) + @strDBDir + @strDBNameFrom + '.bak' + CHR(39) And then you need to execute the SQL command using another SQL command... EXEC (@sql) -- this will run the dynamic parametized SQL query to accomplish the task of backing up the database. --Now to the restore portion... --note the use of CHR(39) ; single apostrophe as delimeters SET @sql = 'RESTORE DATABASE MLV FROM DISK = ' + CHR(39) + 'C:\temp\MLVBak.BAK' + CHR(39) SET @sql = @sql + ' WITH MOVE ' + CHR(39) + 'MLV_Data' + CHR(39) + ' TO ' + CHR(39) + 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_Data.mdf' + ', ' SET @sql = @sql + 'MOVE ' + CHR(39) + 'MLV_log' + CHR(39) + ' TO ' + CHR(39) + 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_log.LDF' + CHR(39) --To debug uncomment the line below (i.e remove the --; -- and /* */ are treated as comment delimiters in SQL syntax) --PRINT @sql --this should give you exactly the following command commented below /* RESTORE DATABASE MLV FROM DISK = 'C:\inetpub\wwwroot\pvp\MLVBak.BAK' WITH MOVE 'MLV_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_Data.mdf', MOVE 'MLV_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\MLV_log.LDF' */ --To run it use EXEC command EXEC (@sql) That's it in a nutshell... NOTES: for John 1. Robert's sproc is spot on. What he didn't provide were comments such as why it needs to be like this and not like that, etc... 2. Robert DID provide comments. Simple, yes but you are wrong in saying he didn't provide comments. Take a look at his code again and wherever you see the double dash (--), those are comments. 3. (including Gustav)...it doesn't matter what you name your physical MDF or LDF files, whether you append _Data or _Log to them. What matters is when you search for them in the file system you can easily spot them and associate them with each other because SQL server data files ALWAYS come with SQL server log files (unless of course you specify the no logs option). 4. For your non-relational application John, you can simply do away with TRANSCATION LOG files unless you need to rollback changes. It makes the processing (CRUD operations) go faster since SQL doesn't have to log everything that takes place. 5. Additional tips...if you simply want to "refresh" a table (meaning wipe the data out), use TRUNCATE TABLE
(< > are not needed of course when you type the command) ...it skips the transaction logs and sets the identity (autonumber for you Access nubees) field back to 1. It is way faster than DELETE FROM
. Finally...let's just all lighten up and quit being childish. This is not a my thingy is bigger than your thingy deal. It's just SQL server...and by the way for this interested in SQL server 2008, go to a Microsoft event and get a FREE copy of SQL server 2008, Visual Studio 2008 and Windows Server 2008. That's what I'm gonna do later on today. NYAH, NYAH, NYAH, NA...NA...NA LOL! Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 6:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ 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 Mar 27 10:53:36 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:53:36 -0400 Subject: [dba-SQLServer] Copy a database usinga storedprocedureorfunction In-Reply-To: <0JYE00IR88WYKNN0@vms046.mailsrvcs.net> References: <002101c89016$ca63fd90$0201a8c0@M90> <0JYE00IR88WYKNN0@vms046.mailsrvcs.net> Message-ID: <000201c89022$b7fe18f0$0201a8c0@M90> ROTFL. I would RECOMMEND his book to you guys. I can't say for sure because I don't own it, but I suspect that it starts at a level already over my head. You gotta crawl before you can walk, and I am still crawling. The other thing to remember is that I do use TSQL, and I have come a long way, and gotten a whole ton of stuff working without using any advanced features of TSQL. My database is REALLY simple. No transactions, no locks, no rollbacks, no usernames, no groups, no passwords. It is just me and my server, on a private network, looking at HUGE single tables. Would advanced TSQL help me? I am sure it would. Would it be worth the months or years learning it? Not in my opinion. There is still hope for me. And I have come a long way already, especially considering I sit in a room by myself all day slogging through this stuff. I read, and I Google, and I play and I get frustrated, and I come here when all else fails. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 10:44 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storedprocedureorfunction Hehehehe...John, maybe you should go buy Paul Nielsen's SQL Server 2005 BIBLE! Now *THAT* might get you into the priesthood yet. There's still hope for you John! And that's the good news!!! LOL... Ah yes...a little humor does help. BUY IT NOW!!! DO IT! Hahahahhahahaha.... -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 7:28 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction ROTFL. Liz, you are a nice lady. I will be honest with you, being in the laity I find BOL useless. The explanations are endless loops of code that does not run as typed, and references to other entries of code that does not run as typed, and pages of arcane syntax that are no doubt useful to those more directly involved in SQL Server. There is a good reason that there are aftermarket books (which I own AND READ) to explain this stuff. I have read chapters Chapters 11, 12 and 13 of Robert Vieira's excellent Beginning SQL Server 2005 Programming and I am slowly learning, but no surprise, the question I asked is a bit beyond what a book like that can even consider. As I have clearly stated, I am not an SQL Server admin, programmer, manager or anything else. I just use it, quite successfully all things considered. Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 10:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz From jwcolby at colbyconsulting.com Thu Mar 27 10:53:46 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:53:46 -0400 Subject: [dba-SQLServer] Copy a database usinga storedprocedureorfunction In-Reply-To: <0JYE00IBE9DIJLO0@vms046.mailsrvcs.net> References: <002101c89016$ca63fd90$0201a8c0@M90> <0JYE00IBE9DIJLO0@vms046.mailsrvcs.net> Message-ID: <000301c89022$bdf188f0$0201a8c0@M90> And I didn't mean that, I was simply trying to show just how low in the evolutionary scale I currently sit. Sorry Liz. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 10:54 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database usinga storedprocedureorfunction Geez John... This is no way to treat a lady! "Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there." It's like telling her..."I like you but I don't like you that much...besides I got what I want from you" ;) -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 7:28 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a storedprocedureorfunction ROTFL. Liz, you are a nice lady. I will be honest with you, being in the laity I find BOL useless. The explanations are endless loops of code that does not run as typed, and references to other entries of code that does not run as typed, and pages of arcane syntax that are no doubt useful to those more directly involved in SQL Server. There is a good reason that there are aftermarket books (which I own AND READ) to explain this stuff. I have read chapters Chapters 11, 12 and 13 of Robert Vieira's excellent Beginning SQL Server 2005 Programming and I am slowly learning, but no surprise, the question I asked is a bit beyond what a book like that can even consider. As I have clearly stated, I am not an SQL Server admin, programmer, manager or anything else. I just use it, quite successfully all things considered. Even your example doesn't directly help me much, though it certainly provides me with syntax that might eventually get me there. John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Thu Mar 27 10:53:53 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:53:53 -0400 Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters In-Reply-To: <0JYE00LDU9Z3G7Q0@vms042.mailsrvcs.net> References: <0JYE00LDU9Z3G7Q0@vms042.mailsrvcs.net> Message-ID: <000401c89022$c281bf70$0201a8c0@M90> Eric, You are precisely correct, use each tool for what it does best. I am trying to build stored procedures or UDFs to do the heavy lifting and will eventually tie them in to a .Net FE. Of course I just execute them directly for the moment. It would seem that I now have a tool for copying my template database to an ordername. My appreciation to all for your assistance. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 11:07 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters Gustav, .NET is not the tool to use for backing up and restoring SQL databases. Granted, you may find solutions out there that do that it won't be optimal. Besides, the tool is already there for you to use. Just use it. I would use .NET as a UI to call the sprocs but not everything can be done using .NET. It's just as bad as when the *priests* insist that SQL is the end all and be all and that you'll go to HELL if you don't do it the TSQL way. Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 6:49 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestion plus parameters Hi John I think you are trapped by the single/double quote syntax for embedded strings just like when you build string expressions form strings in VBA. Look in Robert's code how he used Chr(34) to wrap string. But your trouble is why I suggested to lift this whole thing out of T-SQL into VB.Net (from where you control the complete process anyway, right?). /gustav From jwcolby at colbyconsulting.com Thu Mar 27 10:54:09 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:54:09 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: References: <001f01c89013$0f306f70$0201a8c0@M90> Message-ID: <000501c89022$cc33be10$0201a8c0@M90> Francisco, that is all true. However TONE inserted in the best practices is inflammatory and needs to be addressed. I also think that best practices can and should be carved out into separate threads of their own, as they tend to degrade into debates about the best practices. Another issue is that "best practices" is often just not useful to someone at my level. It is absolutely useful to you, but this is my thread, trying to get an answer to my question. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 11:12 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful John, I've come back to you on the basis that this new thread even has to get started. All posts are welcomed so long as they are ontopic. Read the database asvisors netiquette rules. Best of practices are completly within scope, I see that type of posts on the access list all the time. Because on this list we deal with really big dbs in general, best of practices are completly appropriate. On 3/27/08, jwcolby wrote: > Francisco, > > Everyone on this list needs to: > > 1) READ THE QUESTION. > 2) RESPOND TO THE QUESTION, in a manner that is at all likely to be > useful to the person asking the question. > 3) Leave the lectures to a new thread of your own making. > > Francisco, > > You keep coming back to ME. I asked a simple question and got useless > junk and lectures about the right way to do things. I got exactly TWO > responses that were useful and indicated that the respondent even > LOOKED at my question, one from Elizabeth and another from James, both of whom I thanked. > > Robert writes a Doctoral thesis and then inserts crap like "now you > can go learn enough to even be worthy of being here" and you don't say > a word. If you want to be a moderator why don't you step in at the > very beginning and ask the people to respond to the questions in a > useful and civil manner, at a level likely to be useful to the person. > I don't need their lectures, and I don't need yours (and I don't need a Doctoral thesis). > > Please everybody, do not respond to the thread unless you have > actually READ it and are willing to write answers on my level. And > start your own threads if you want to discuss "the right way to" or > "how you should NEVER" or write a Doctoral thesis, or anything else not directly related to my question. > > The question is not answered, though I am certainly on my way, and > have started another thread to discuss it further. > > Thanks, > > John W. Colby > Colby Consulting > www.ColbyConsulting.com From jwcolby at colbyconsulting.com Thu Mar 27 10:54:19 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:54:19 -0400 Subject: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 In-Reply-To: References: Message-ID: <000601c89022$d1f2d7a0$0201a8c0@M90> David, There are several reasons for saving the results. First, I take the addresses and run them through Address validation to find anyone who has moved. Once I do that, there are now people in the original list that are no longer in the zips specified. So I have to get rid of anyone not in the zips specified. Second, the lists potentially contain "duplicate" records. Often times the same person answered questions in several different questionnaires and thus got their name in the db multiple times but with completely different data fields filled in. Also, there may be several members of the same household. The client wants ONE piece of mail per address, so I have to DEDUPE the result set. And finally the client asks for lets say 100K records out of 2.4 million. He wants me to MARK those records as shipped so that he can come back next month and ask for another 100K records. His clients do "test runs" to see what the response is. If the response is good, they come back for more, but each time they come back they want new records. In fact, if the time between orders is long enough, I have to go do the Address Validation, remove moved people thing all over again. I could in fact store just the PKs of the records shipped to handle that part, but I have found a date field to be a good flag of shipped and also tells me WHEN those records were shipped. It is for these reasons that I copy a template each time I fill a NEW order. I store the WHERE views that do the data selection, I do the deduping, and I store flags of records shipped, all inside of the new copy of the template. I name the database with the order name and I can always get back to it. I take the order databases offline after a few weeks (to keep the database list less busy), but can always find them again if the client comes back asking for more addresses. I am in fact trying to build a "business" database that stores all of MY business stuff having to so with this. The clients the order goes to, the order specifications, the directories and databases that the stuff is stored in, how long it took to do stuff (for billing) and all that. However that is the "little database" that I mentioned as an aside, not the one that I get the data from to fill the orders. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Thursday, March 27, 2008 11:02 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 Hi John: A few thoughts unrelated to the copy database issue: I'm not sure I follow everything you do, but it sounds like you receive raw data, scrub it, then use it as a basis of reports (run queries, send the results to the client...). It also sounds like you physically save the recordset results of those queries, and that the underlying base table does not change. If that is the case, why not save only the queries you run, rather than the rows they return? Create the queries as either views, or better yet build views and call them from stored procedures that can accept where clauses, topN parameters, etc.? That approach would mean you don't have to manage tables, or entire databases, and instead only manage views and stored procedures. That, by the way, is a use of sql server that is more in line with how it was designed. One approach might be to have some base views, and a table that might look like: tblOrders Customer RequestDate BaseView WhereClause TopClause Etc. Some sample rows might be: Abc Company 3/1/08 Column1, Column2 FROM dbo.vwSomeBaseView WHERE BLAH = 'Blah' AND BLAHBLAH= ' BlahB%' Top 3000 Abc Company 3/12/08 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Top 10000 Using this approach, you only need to build a smaller number of views, you keep a record of who asked for what, when, and you can recreate the actual query very simply. A stored procedure to do that might look like: CREATE PROCEDURE usp_GetResultSet @Customer VARCHAR(50) , at Date DATETIME AS DECLARE @strSQL VARCHAR(500) DECLARE @Top VARCHAR(50) SELECT @strSQL= 'SELECT ' + ISNULL(TopClause,'') + BaseView + WhereClause FROM tblOrders WHERE Customer=@Customer AND RequestDate=@Date PRINT @strSQL --just for debugging... EXEC(@strSQL) Calling this procedure as usp_GetResultSet 'Abc Company','3/12/08' would give you: SELECT Top 10000 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Voila, no messy storing of new tables, etc. I dunno, maybe that helps keep things tidier? From jwcolby at colbyconsulting.com Thu Mar 27 10:54:28 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 11:54:28 -0400 Subject: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 In-Reply-To: <0JYE000XDAU2QVZ0@vms173001.mailsrvcs.net> References: <0JYE000XDAU2QVZ0@vms173001.mailsrvcs.net> Message-ID: <000701c89022$d77647c0$0201a8c0@M90> LOL, not at all. David is a nice guy responding with friendly suggestions. No knuckle rapping required. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 11:25 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 Oh oh...here we go again...you might do well to read the archives David, otherwise you'll get a rap on your knuckles from JC. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Thursday, March 27, 2008 8:02 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 Hi John: A few thoughts unrelated to the copy database issue: I'm not sure I follow everything you do, but it sounds like you receive raw data, scrub it, then use it as a basis of reports (run queries, send the results to the client...). It also sounds like you physically save the recordset results of those queries, and that the underlying base table does not change. If that is the case, why not save only the queries you run, rather than the rows they return? Create the queries as either views, or better yet build views and call them from stored procedures that can accept where clauses, topN parameters, etc.? That approach would mean you don't have to manage tables, or entire databases, and instead only manage views and stored procedures. That, by the way, is a use of sql server that is more in line with how it was designed. One approach might be to have some base views, and a table that might look like: tblOrders Customer RequestDate BaseView WhereClause TopClause Etc. Some sample rows might be: Abc Company 3/1/08 Column1, Column2 FROM dbo.vwSomeBaseView WHERE BLAH = 'Blah' AND BLAHBLAH= ' BlahB%' Top 3000 Abc Company 3/12/08 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Top 10000 Using this approach, you only need to build a smaller number of views, you keep a record of who asked for what, when, and you can recreate the actual query very simply. A stored procedure to do that might look like: CREATE PROCEDURE usp_GetResultSet @Customer VARCHAR(50) , at Date DATETIME AS DECLARE @strSQL VARCHAR(500) DECLARE @Top VARCHAR(50) SELECT @strSQL= 'SELECT ' + ISNULL(TopClause,'') + BaseView + WhereClause FROM tblOrders WHERE Customer=@Customer AND RequestDate=@Date PRINT @strSQL --just for debugging... EXEC(@strSQL) Calling this procedure as usp_GetResultSet 'Abc Company','3/12/08' would give you: SELECT Top 10000 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Voila, no messy storing of new tables, etc. I dunno, maybe that helps keep things tidier? What I am (was, I have given up) trying to do is get some very simple help on some very simple things, or they should be simple. I have already built a template database for "filling orders" from this database. My client asks me for a count (about 16 counts actually) of all the people who... Grouped by. SIMPLE stuff, and I have all of that working (in sql server) and have for a long time (years). I modify a couple of existing views to do the Where... Part, then manually run the count views. Copy the result "table" into a dedicated sheet of an excel workbook. 16 pages, one page for each "count", by state, by income bracket, by age bands and so forth. All working quite well. BTW I keep these as a dedicated database for that order (named after the order in fact) because I may need it later. Not sophisticated but simple and it works. That is the "template database". In fact there are two different kinds of orders. The second kind is "OK, now give me N thousand names / addresses from that count you gave me before". Again, I have been doing this stuff for quite some time, using a strange mixture of SQL Server, a third party Address Validation program running on a server here in my office, and Access (for the final phase). I have been doing all of that for months as well (years actually, I am just getting much more efficient at it lately). I decided that I could automate this second type of order such that many of the bits and pieces were just done by stored procedures. I have done that as well. All on my own, no Priests involved. 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From David at sierranevada.com Thu Mar 27 11:15:27 2008 From: David at sierranevada.com (David Lewis) Date: Thu, 27 Mar 2008 09:15:27 -0700 Subject: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 44 In-Reply-To: References: Message-ID: OK, I think I understand this a little better, but I get the feeling that copying the result set to a new DATABASE is overkill -- why not just to a new table within the current db? Creating databases is a fairly drastic solution, in my opinion. There is a lot of overhead to them, all sorts of views, procedures, roles, etc associated, even when they are not explicitly used. I think it will unnecessarily bog down your server. Tables are much easier to manage. Just my opinion. D. Lewis ------------------------------ Message: 5 Date: Thu, 27 Mar 2008 11:54:19 -0400 From: "jwcolby" Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 To: "'Discussion concerning MS SQL Server'" Message-ID: <000601c89022$d1f2d7a0$0201a8c0 at M90> Content-Type: text/plain; charset="us-ascii" David, There are several reasons for saving the results. First, I take the addresses and run them through Address validation to find anyone who has moved. Once I do that, there are now people in the original list that are no longer in the zips specified. So I have to get rid of anyone not in the zips specified. Second, the lists potentially contain "duplicate" records. Often times the same person answered questions in several different questionnaires and thus got their name in the db multiple times but with completely different data fields filled in. Also, there may be several members of the same household. The client wants ONE piece of mail per address, so I have to DEDUPE the result set. And finally the client asks for lets say 100K records out of 2.4 million. He wants me to MARK those records as shipped so that he can come back next month and ask for another 100K records. His clients do "test runs" to see what the response is. If the response is good, they come back for more, but each time they come back they want new records. In fact, if the time between orders is long enough, I have to go do the Address Validation, remove moved people thing all over again. I could in fact store just the PKs of the records shipped to handle that part, but I have found a date field to be a good flag of shipped and also tells me WHEN those records were shipped. It is for these reasons that I copy a template each time I fill a NEW order. I store the WHERE views that do the data selection, I do the deduping, and I store flags of records shipped, all inside of the new copy of the template. I name the database with the order name and I can always get back to it. I take the order databases offline after a few weeks (to keep the database list less busy), but can always find them again if the client comes back asking for more addresses. I am in fact trying to build a "business" database that stores all of MY business stuff having to so with this. The clients the order goes to, the order specifications, the directories and databases that the stuff is stored in, how long it took to do stuff (for billing) and all that. However that is the "little database" that I mentioned as an aside, not the one that I get the data from to fill the orders. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Thursday, March 27, 2008 11:02 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 Hi John: A few thoughts unrelated to the copy database issue: I'm not sure I follow everything you do, but it sounds like you receive raw data, scrub it, then use it as a basis of reports (run queries, send the results to the client...). It also sounds like you physically save the recordset results of those queries, and that the underlying base table does not change. If that is the case, why not save only the queries you run, rather than the rows they return? Create the queries as either views, or better yet build views and call them from stored procedures that can accept where clauses, topN parameters, etc.? That approach would mean you don't have to manage tables, or entire databases, and instead only manage views and stored procedures. That, by the way, is a use of sql server that is more in line with how it was designed. One approach might be to have some base views, and a table that might look like: tblOrders Customer RequestDate BaseView WhereClause TopClause Etc. Some sample rows might be: Abc Company 3/1/08 Column1, Column2 FROM dbo.vwSomeBaseView WHERE BLAH = 'Blah' AND BLAHBLAH= ' BlahB%' Top 3000 Abc Company 3/12/08 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Top 10000 Using this approach, you only need to build a smaller number of views, you keep a record of who asked for what, when, and you can recreate the actual query very simply. A stored procedure to do that might look like: CREATE PROCEDURE usp_GetResultSet @Customer VARCHAR(50) , at Date DATETIME AS DECLARE @strSQL VARCHAR(500) DECLARE @Top VARCHAR(50) SELECT @strSQL= 'SELECT ' + ISNULL(TopClause,'') + BaseView + WhereClause FROM tblOrders WHERE Customer=@Customer AND RequestDate=@Date PRINT @strSQL --just for debugging... EXEC(@strSQL) Calling this procedure as usp_GetResultSet 'Abc Company','3/12/08' would give you: SELECT Top 10000 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Voila, no messy storing of new tables, etc. I dunno, maybe that helps keep things tidier? 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 ebarro at verizon.net Thu Mar 27 11:35:10 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 09:35:10 -0700 Subject: [dba-SQLServer] Copy a database using astored procedureorfunction In-Reply-To: <000001c89022$73f59020$0201a8c0@M90> Message-ID: <0JYE00J9DE2Q3NT0@vms048.mailsrvcs.net> I know you do John...I was just injecting some humor into all this. :) I'm pretty sure most if not all have googled their issues BEFORE actually requesting help from this community. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 8:52 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using astored procedureorfunction I did Google search and got a bunch of "how to use the wizards" stuff. Google has a lot of good stuff, but you really have to know how to phrase the question or you just get "how to use the wizard" type answers. Believe me Eric, I read my books, and I Google before I ever come here. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 10:42 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using astored procedureorfunction So John...Elizabeth searched BOL for 'copy database' and she found it in less time than it took for you to formulate your original question? What's up with that? :) Me thinks you need "Google Search"...reminds me of what the users wanted for searching a component parts list in our company. When asked what types of searches they conduct they simply said "we want to search on everything". Ya right! They wanted "Google Search" all right. I don't go to BOL either John so don't feel guilty. :) I go to "Google Search". -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Elizabeth.J.Doering at wellsfargo.com Sent: Thursday, March 27, 2008 7:12 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedureorfunction I am embarrassed to be held up as any kind of example in this company of experts. I searched BOL for 'copy database', something that I do regularly instead of bringing my simple questions to gurus. I got an answer from BOL in less time than it took JC to formulate his original question. Which, coincidentally, is much much less time than all the combined rants on this topic. Of course, I've found much to learn, even in the rants, which is what is continuously wonderful about this list. Thanks, Liz -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 8:15 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using a stored procedureorfunction Yes, Robert, it was a huge waste of MY time, and undoubtedly yours. It just shows how little you read from my posts. I have clearly stated that I know nothing. Your response is two pages of stuff that I have no clue what it is and am entirely incapable of understanding, then you state that is only half the solution and it is now time for me to go write the other half. OTOH look at Elizabeth's solution. It apparently works and is compact and readable. And no snotty "now go learn enough to be worthy to be in my presence" comments. Yes, Robert, it was a huge waste of MY time, and probably yours. I have no doubt that you know this stuff, you are just useless to me. It is not my fault that you are useless to me BTW. Take off your Priest robes, roll up your sleeves, get the "tone" out of your voice and write simple code with explanations of what it does and you could be helpful. Until such time, do not bother to respond to my requests for help because you are useless to me, and you are just irritating (apparently your intent). If you want to be treated as the professional that you seem to be, act like it. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 8:55 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a stored procedure orfunction John, So the code I sent you for a parameterized stored procedure to do everything except the restore was "less than useful." I apologize for the "huge waste of everybody's time" (including mine) to give you a good, solid, viable way of solving your problem. Robert At 09:33 PM 3/26/2008, you wrote: >So yea, for some reason I do find this list less than useful. A full >day of lectures, and ONE response that actually looks like it might be helpful. >Thanks Elizabeth! _______________________________________________ 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 Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Thu Mar 27 11:40:43 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 09:40:43 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000501c89022$cc33be10$0201a8c0@M90> Message-ID: <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> Perhaps we can all make it a practice or habit to present a workable solution first (with code and comments as much as possible) AND THEN include best practices to explain why the code we recommended is the way to go. I'm sure that we would all appreciate getting a quick-turn-around solution AND a best practices RELATED to the solution. For the most part we all have priorities... 1. Get the job done as quick and efficiently as possible to satisfy our customers 2. Develop systems and procedures using the quick solutions as a spring board. Sometimes we will need to align our quick and dirty solutions with best practices. And let's not forget that when someone takes the time to explain their situation (like JC) with detailed information, they are honestly seeking solutions that will work for their immediate situation AND the future as well. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 8:54 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Francisco, that is all true. However TONE inserted in the best practices is inflammatory and needs to be addressed. I also think that best practices can and should be carved out into separate threads of their own, as they tend to degrade into debates about the best practices. Another issue is that "best practices" is often just not useful to someone at my level. It is absolutely useful to you, but this is my thread, trying to get an answer to my question. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 11:12 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful John, I've come back to you on the basis that this new thread even has to get started. All posts are welcomed so long as they are ontopic. Read the database asvisors netiquette rules. Best of practices are completly within scope, I see that type of posts on the access list all the time. Because on this list we deal with really big dbs in general, best of practices are completly appropriate. On 3/27/08, jwcolby wrote: > Francisco, > > Everyone on this list needs to: > > 1) READ THE QUESTION. > 2) RESPOND TO THE QUESTION, in a manner that is at all likely to be > useful to the person asking the question. > 3) Leave the lectures to a new thread of your own making. > > Francisco, > > You keep coming back to ME. I asked a simple question and got useless > junk and lectures about the right way to do things. I got exactly TWO > responses that were useful and indicated that the respondent even > LOOKED at my question, one from Elizabeth and another from James, both > of whom I thanked. > > Robert writes a Doctoral thesis and then inserts crap like "now you > can go learn enough to even be worthy of being here" and you don't say > a word. If you want to be a moderator why don't you step in at the > very beginning and ask the people to respond to the questions in a > useful and civil manner, at a level likely to be useful to the person. > I don't need their lectures, and I don't need yours (and I don't need > a Doctoral thesis). > > Please everybody, do not respond to the thread unless you have > actually READ it and are willing to write answers on my level. And > start your own threads if you want to discuss "the right way to" or > "how you should NEVER" or write a Doctoral thesis, or anything else > not directly related to my question. > > The question is not answered, though I am certainly on my way, and > have started another thread to discuss it further. > > Thanks, > > John W. Colby > Colby Consulting > www.ColbyConsulting.com _______________________________________________ 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 Mar 27 11:50:58 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 12:50:58 -0400 Subject: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 44 In-Reply-To: References: Message-ID: <000a01c8902a$bb9cc9e0$0201a8c0@M90> David, It is just an encapsulation technique to me. In the case of count orders, the entire database is only a meg or so file size. The business is just complex enough to need to completely encapsulate the entire order and save it for later. I actually have about 5 or 6 different "list" databases from which I pull names and addresses. Most come from just one but occasionally the client references another. By encapsulating the database I get exact copies of any slight modifications I have to make to the views that filter down the result sets. Likewise the client occasionally changes his count requirements, adding new counts etc. By having an exact copy of what I used in a past order I can go back to that database and be working in exactly the environment that I was originally working in. It would perhaps make less sense if these were gigabyte databases but USUALLY they are not. Very occasionally, if they ask for millions of names in the result set, then the db gets up to a fairly hefty size but in the end I still need to be able to see exactly what I did to get my results without any "hmmm did the changes I made three months ago change what I am getting on this order". If I tell the client that he has 2.45 million records, I darned well better be able to show HOW I arrived at those records, and pull exactly those names if he comes back later. As I mentioned, I disconnect the old databases so that I don't see them from inside of SQL Server. As they get really old I RAR them to get them out of the database directory. I can always get back to them though. My client has told me that another fulfillment house he used could never come back later and give him consistent results, could never say how or why they came up with the names that they came up with. I can do that using this technique. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Thursday, March 27, 2008 12:15 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 44 OK, I think I understand this a little better, but I get the feeling that copying the result set to a new DATABASE is overkill -- why not just to a new table within the current db? Creating databases is a fairly drastic solution, in my opinion. There is a lot of overhead to them, all sorts of views, procedures, roles, etc associated, even when they are not explicitly used. I think it will unnecessarily bog down your server. Tables are much easier to manage. Just my opinion. D. Lewis ------------------------------ Message: 5 Date: Thu, 27 Mar 2008 11:54:19 -0400 From: "jwcolby" Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 To: "'Discussion concerning MS SQL Server'" Message-ID: <000601c89022$d1f2d7a0$0201a8c0 at M90> Content-Type: text/plain; charset="us-ascii" David, There are several reasons for saving the results. First, I take the addresses and run them through Address validation to find anyone who has moved. Once I do that, there are now people in the original list that are no longer in the zips specified. So I have to get rid of anyone not in the zips specified. Second, the lists potentially contain "duplicate" records. Often times the same person answered questions in several different questionnaires and thus got their name in the db multiple times but with completely different data fields filled in. Also, there may be several members of the same household. The client wants ONE piece of mail per address, so I have to DEDUPE the result set. And finally the client asks for lets say 100K records out of 2.4 million. He wants me to MARK those records as shipped so that he can come back next month and ask for another 100K records. His clients do "test runs" to see what the response is. If the response is good, they come back for more, but each time they come back they want new records. In fact, if the time between orders is long enough, I have to go do the Address Validation, remove moved people thing all over again. I could in fact store just the PKs of the records shipped to handle that part, but I have found a date field to be a good flag of shipped and also tells me WHEN those records were shipped. It is for these reasons that I copy a template each time I fill a NEW order. I store the WHERE views that do the data selection, I do the deduping, and I store flags of records shipped, all inside of the new copy of the template. I name the database with the order name and I can always get back to it. I take the order databases offline after a few weeks (to keep the database list less busy), but can always find them again if the client comes back asking for more addresses. I am in fact trying to build a "business" database that stores all of MY business stuff having to so with this. The clients the order goes to, the order specifications, the directories and databases that the stuff is stored in, how long it took to do stuff (for billing) and all that. However that is the "little database" that I mentioned as an aside, not the one that I get the data from to fill the orders. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David Lewis Sent: Thursday, March 27, 2008 11:02 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] dba-SQLServer Digest, Vol 61, Issue 38 Hi John: A few thoughts unrelated to the copy database issue: I'm not sure I follow everything you do, but it sounds like you receive raw data, scrub it, then use it as a basis of reports (run queries, send the results to the client...). It also sounds like you physically save the recordset results of those queries, and that the underlying base table does not change. If that is the case, why not save only the queries you run, rather than the rows they return? Create the queries as either views, or better yet build views and call them from stored procedures that can accept where clauses, topN parameters, etc.? That approach would mean you don't have to manage tables, or entire databases, and instead only manage views and stored procedures. That, by the way, is a use of sql server that is more in line with how it was designed. One approach might be to have some base views, and a table that might look like: tblOrders Customer RequestDate BaseView WhereClause TopClause Etc. Some sample rows might be: Abc Company 3/1/08 Column1, Column2 FROM dbo.vwSomeBaseView WHERE BLAH = 'Blah' AND BLAHBLAH= ' BlahB%' Top 3000 Abc Company 3/12/08 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Top 10000 Using this approach, you only need to build a smaller number of views, you keep a record of who asked for what, when, and you can recreate the actual query very simply. A stored procedure to do that might look like: CREATE PROCEDURE usp_GetResultSet @Customer VARCHAR(50) , at Date DATETIME AS DECLARE @strSQL VARCHAR(500) DECLARE @Top VARCHAR(50) SELECT @strSQL= 'SELECT ' + ISNULL(TopClause,'') + BaseView + WhereClause FROM tblOrders WHERE Customer=@Customer AND RequestDate=@Date PRINT @strSQL --just for debugging... EXEC(@strSQL) Calling this procedure as usp_GetResultSet 'Abc Company','3/12/08' would give you: SELECT Top 10000 Column1, Column2, Column3 FROM dbo.vwSomeOtherBaseView WHERE Humbug = 'Blah' AND Yada= ' BlahB%' Voila, no messy storing of new tables, etc. I dunno, maybe that helps keep things tidier? 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 Mar 27 12:16:49 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 13:16:49 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> References: <000501c89022$cc33be10$0201a8c0@M90> <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> Message-ID: <000b01c8902e$58387710$0201a8c0@M90> Hear hear. And remember that sometimes just giving a person a fish is all they really need. Not everyone needs to learn to fish, or at least they do not need to learn all the advanced techniques. I am a programmer and I love programming, but I am not heavily involved in SQL Server. All I need is a solution and a few light reading tips on how and why. If the solution is at all readable I can look at it and learn what it is doing, but it is often the case that I would NEVER find that solution on my own (and I have always tried). And if it is too complex, then my eyes glaze over and I just move on to the next message. I read every post to this board, every day. Most of them cause my eyes to glaze over, but I am here, silently reading. I was trying to do my entire project in .Net, then I realized that I could do some of the stuff much more efficiently (and perhaps in some cases ONLY) using SPs and UDFs, so I started reading up on them and got a bunch working on my own. Much of my frustrations come from switching from a development environment like .Net or Access to the query editor in SQL Server. Even in the relatively basic Access we have modules and classes, intellisense, syntax checking, error handlers, compile time errors that actually mean something and so forth. What a jarring contrast to switch to SQL Server query editor. But I am making progress. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Eric Barro Sent: Thursday, March 27, 2008 12:41 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Perhaps we can all make it a practice or habit to present a workable solution first (with code and comments as much as possible) AND THEN include best practices to explain why the code we recommended is the way to go. I'm sure that we would all appreciate getting a quick-turn-around solution AND a best practices RELATED to the solution. For the most part we all have priorities... 1. Get the job done as quick and efficiently as possible to satisfy our customers 2. Develop systems and procedures using the quick solutions as a spring board. Sometimes we will need to align our quick and dirty solutions with best practices. And let's not forget that when someone takes the time to explain their situation (like JC) with detailed information, they are honestly seeking solutions that will work for their immediate situation AND the future as well. From fhtapia at gmail.com Thu Mar 27 12:24:53 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 10:24:53 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000b01c8902e$58387710$0201a8c0@M90> References: <000501c89022$cc33be10$0201a8c0@M90> <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> <000b01c8902e$58387710$0201a8c0@M90> Message-ID: it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development environment > like .Net or > Access to the query editor in SQL Server. Even in the relatively basic > Access we have modules and classes, intellisense, syntax checking, error > handlers, compile time errors that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Thu Mar 27 12:38:35 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 13:38:35 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: References: <000501c89022$cc33be10$0201a8c0@M90><0JYE00H03E75HVA1@vms173003.mailsrvcs.net><000b01c8902e$58387710$0201a8c0@M90> Message-ID: <000d01c89031$6309e810$0201a8c0@M90> >The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 Mar 27 12:45:11 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 13:45:11 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: References: <000501c89022$cc33be10$0201a8c0@M90><0JYE00H03E75HVA1@vms173003.mailsrvcs.net><000b01c8902e$58387710$0201a8c0@M90> Message-ID: <000e01c89032$4ebcf4f0$0201a8c0@M90> SQL Prompt 2.0 still free? I am not finding it. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 Mar 27 12:49:19 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 10:49:19 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000d01c89031$6309e810$0201a8c0@M90> References: <000501c89022$cc33be10$0201a8c0@M90> <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> <000b01c8902e$58387710$0201a8c0@M90> <000d01c89031$6309e810$0201a8c0@M90> Message-ID: i'll be looking out for some as I will want some for myself as well. On Thu, Mar 27, 2008 at 10:38 AM, jwcolby wrote: > >The follow up upgrade to sql server, that is SqlServer 2008 will provide > a > lot of really cool tools such as intellisense, and the ability to run the > same script across multiple servers etc. neat stuff, along w/ things like > db > compression etc. > > I shall sit on my wallet then and wait for SQL Server 2008. I am going to > a > product launch down in Charlotte next month and should get my copy there. > It sounds like it will be worth the time to learn the new environment. > > Of course that means a whole new set of books. My wife HATES my books, at > $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? > BASIC PROGRAMMING! ;-) > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco > Tapia > Sent: Thursday, March 27, 2008 1:25 PM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Being helpful > > it would seem that you may look forward to the ever upgrade path from M$. > while there are current purchasable apps you can get for Sql Server such > as > Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really > help speed up much of the syntax building process there are also other > tools > from similar vendors that will help with syntax problems etc. The follow > up > upgrade to sql server, that is SqlServer 2008 will provide a lot of really > cool tools such as intellisense, and the ability to run the same script > accross multiple servers etc. neat stuff, along w/ things like db > comrpession etc. > > Until then, I think the community has been helpful, and so long as we all > try to stay ontopic we can avoid another rant gone wrong. > -- > Francisco > > On Thu, Mar 27, 2008 at 10:16 AM, jwcolby > wrote: > > > Much of my frustrations come from switching from a development > > environment like .Net or Access to the query editor in SQL Server. > > Even in the relatively basic Access we have modules and classes, > > intellisense, syntax checking, error handlers, compile time errors > > that actually mean something and so forth. > > What a jarring contrast to switch to SQL Server query editor. > > > > But I am making progress. > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > > > > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > 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 > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From fhtapia at gmail.com Thu Mar 27 12:49:36 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 10:49:36 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000e01c89032$4ebcf4f0$0201a8c0@M90> References: <000501c89022$cc33be10$0201a8c0@M90> <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> <000b01c8902e$58387710$0201a8c0@M90> <000e01c89032$4ebcf4f0$0201a8c0@M90> Message-ID: let me search for it. On Thu, Mar 27, 2008 at 10:45 AM, jwcolby wrote: > SQL Prompt 2.0 still free? I am not finding it. > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco > Tapia > Sent: Thursday, March 27, 2008 1:25 PM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Being helpful > > it would seem that you may look forward to the ever upgrade path from M$. > while there are current purchasable apps you can get for Sql Server such > as > Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really > help speed up much of the syntax building process there are also other > tools > from similar vendors that will help with syntax problems etc. The follow > up > upgrade to sql server, that is SqlServer 2008 will provide a lot of really > cool tools such as intellisense, and the ability to run the same script > accross multiple servers etc. neat stuff, along w/ things like db > comrpession etc. > > Until then, I think the community has been helpful, and so long as we all > try to stay ontopic we can avoid another rant gone wrong. > -- > Francisco > > On Thu, Mar 27, 2008 at 10:16 AM, jwcolby > wrote: > > > Much of my frustrations come from switching from a development > > environment like .Net or Access to the query editor in SQL Server. > > Even in the relatively basic Access we have modules and classes, > > intellisense, syntax checking, error handlers, compile time errors > > that actually mean something and so forth. > > What a jarring contrast to switch to SQL Server query editor. > > > > But I am making progress. > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > > > > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > 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 > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From fhtapia at gmail.com Thu Mar 27 12:51:38 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 10:51:38 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000e01c89032$4ebcf4f0$0201a8c0@M90> References: <000501c89022$cc33be10$0201a8c0@M90> <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> <000b01c8902e$58387710$0201a8c0@M90> <000e01c89032$4ebcf4f0$0201a8c0@M90> Message-ID: you can find it here: http://www.bustercollings.com/blog/2006/06/14/m-sql-query-analyzer-auto-complete-intellisense/ On Thu, Mar 27, 2008 at 10:45 AM, jwcolby wrote: > SQL Prompt 2.0 still free? I am not finding it. > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco > Tapia > Sent: Thursday, March 27, 2008 1:25 PM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Being helpful > > it would seem that you may look forward to the ever upgrade path from M$. > while there are current purchasable apps you can get for Sql Server such > as > Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really > help speed up much of the syntax building process there are also other > tools > from similar vendors that will help with syntax problems etc. The follow > up > upgrade to sql server, that is SqlServer 2008 will provide a lot of really > cool tools such as intellisense, and the ability to run the same script > accross multiple servers etc. neat stuff, along w/ things like db > comrpession etc. > > Until then, I think the community has been helpful, and so long as we all > try to stay ontopic we can avoid another rant gone wrong. > -- > Francisco > > On Thu, Mar 27, 2008 at 10:16 AM, jwcolby > wrote: > > > Much of my frustrations come from switching from a development > > environment like .Net or Access to the query editor in SQL Server. > > Even in the relatively basic Access we have modules and classes, > > intellisense, syntax checking, error handlers, compile time errors > > that actually mean something and so forth. > > What a jarring contrast to switch to SQL Server query editor. > > > > But I am making progress. > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > > > > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > 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 > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From fhtapia at gmail.com Thu Mar 27 12:53:27 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 27 Mar 2008 10:53:27 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: References: <000501c89022$cc33be10$0201a8c0@M90> <0JYE00H03E75HVA1@vms173003.mailsrvcs.net> <000b01c8902e$58387710$0201a8c0@M90> <000e01c89032$4ebcf4f0$0201a8c0@M90> Message-ID: Having said this, and having used both 2.0 and 3.0... I really prefer 3.0 it is a very robust and very helpful tool. Not to mention it is lightning fast, it does a much better job of caching and updating as you add new objects to the database. in 2.0 the only way to see your new objects was to manually refresh the cache for 2.0, in 3.0 this seems to have been taken care of in the background for you. On Thu, Mar 27, 2008 at 10:51 AM, Francisco Tapia wrote: > you can find it here: > > > http://www.bustercollings.com/blog/2006/06/14/m-sql-query-analyzer-auto-complete-intellisense/ > > > On Thu, Mar 27, 2008 at 10:45 AM, jwcolby > wrote: > > > SQL Prompt 2.0 still free? I am not finding it. > > > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > -----Original Message----- > > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of > > Francisco > > Tapia > > Sent: Thursday, March 27, 2008 1:25 PM > > To: Discussion concerning MS SQL Server > > Subject: Re: [dba-SQLServer] Being helpful > > > > it would seem that you may look forward to the ever upgrade path from > > M$. > > while there are current purchasable apps you can get for Sql Server such > > as > > Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and > > really > > help speed up much of the syntax building process there are also other > > tools > > from similar vendors that will help with syntax problems etc. The > > follow up > > upgrade to sql server, that is SqlServer 2008 will provide a lot of > > really > > cool tools such as intellisense, and the ability to run the same script > > accross multiple servers etc. neat stuff, along w/ things like db > > comrpession etc. > > > > Until then, I think the community has been helpful, and so long as we > > all > > try to stay ontopic we can avoid another rant gone wrong. > > -- > > Francisco > > > > On Thu, Mar 27, 2008 at 10:16 AM, jwcolby > > wrote: > > > > > Much of my frustrations come from switching from a development > > > environment like .Net or Access to the query editor in SQL Server. > > > Even in the relatively basic Access we have modules and classes, > > > intellisense, syntax checking, error handlers, compile time errors > > > that actually mean something and so forth. > > > What a jarring contrast to switch to SQL Server query editor. > > > > > > But I am making progress. > > > > > > John W. Colby > > > Colby Consulting > > > www.ColbyConsulting.com > > > > > > > > > > > > -- > > -Francisco > > http://sqlthis.blogspot.com | Tsql and More... > > _______________________________________________ > > 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 > > > > > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Thu Mar 27 13:07:35 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 14:07:35 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: References: <000501c89022$cc33be10$0201a8c0@M90><0JYE00H03E75HVA1@vms173003.mailsrvcs.net><000b01c8902e$58387710$0201a8c0@M90><000e01c89032$4ebcf4f0$0201a8c0@M90> Message-ID: <001201c89035$70052170$0201a8c0@M90> I can appreciate that. However as one who writes code in SQL Server very rarely, spending the bucks just doesn't seem to make sense for me, even less so if similar functionality may be available in SQL Server 2008. I have downloaded the 2.0 version and will play with that. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:53 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful Having said this, and having used both 2.0 and 3.0... I really prefer 3.0 it is a very robust and very helpful tool. Not to mention it is lightning fast, it does a much better job of caching and updating as you add new objects to the database. in 2.0 the only way to see your new objects was to manually refresh the cache for 2.0, in 3.0 this seems to have been taken care of in the background for you. On Thu, Mar 27, 2008 at 10:51 AM, Francisco Tapia wrote: > you can find it here: > > > http://www.bustercollings.com/blog/2006/06/14/m-sql-query-analyzer-aut > o-complete-intellisense/ > > > On Thu, Mar 27, 2008 at 10:45 AM, jwcolby > > wrote: > > > SQL Prompt 2.0 still free? I am not finding it. > > > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > -----Original Message----- > > From: dba-sqlserver-bounces at databaseadvisors.com > > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of > > Francisco Tapia > > Sent: Thursday, March 27, 2008 1:25 PM > > To: Discussion concerning MS SQL Server > > Subject: Re: [dba-SQLServer] Being helpful > > > > it would seem that you may look forward to the ever upgrade path > > from M$. > > while there are current purchasable apps you can get for Sql Server > > such as Sql Prompt (2.0 free or 3.0purchase) that provide > > intellisense and really help speed up much of the syntax building > > process there are also other tools from similar vendors that will > > help with syntax problems etc. The follow up upgrade to sql server, > > that is SqlServer 2008 will provide a lot of really cool tools such > > as intellisense, and the ability to run the same script accross > > multiple servers etc. neat stuff, along w/ things like db > > comrpession etc. > > > > Until then, I think the community has been helpful, and so long as > > we all try to stay ontopic we can avoid another rant gone wrong. > > -- > > Francisco > > > > On Thu, Mar 27, 2008 at 10:16 AM, jwcolby > > > > wrote: > > > > > Much of my frustrations come from switching from a development > > > environment like .Net or Access to the query editor in SQL Server. > > > Even in the relatively basic Access we have modules and classes, > > > intellisense, syntax checking, error handlers, compile time errors > > > that actually mean something and so forth. > > > What a jarring contrast to switch to SQL Server query editor. > > > > > > But I am making progress. > > > > > > John W. Colby > > > Colby Consulting > > > www.ColbyConsulting.com > > > > > > > > > > > > -- > > -Francisco > > http://sqlthis.blogspot.com | Tsql and More... > > _______________________________________________ > > 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 > > > > > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From mikedorism at verizon.net Thu Mar 27 13:20:28 2008 From: mikedorism at verizon.net (Doris Manning) Date: Thu, 27 Mar 2008 14:20:28 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000d01c89031$6309e810$0201a8c0@M90> References: <000501c89022$cc33be10$0201a8c0@M90><0JYE00H03E75HVA1@vms173003.mailsrvcs.net><000b01c8902e$58387710$0201a8c0@M90> <000d01c89031$6309e810$0201a8c0@M90> Message-ID: <000c01c89037$3cf1f4f0$10fe2e0a@Kermit> Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. JC, Where are you based? You need to visit the Green Valley Bookfair once in a while. I have an entire library of $45-60 books that I have picked up for less than $20 a piece. http://www.gvbookfair.com/ Doris Manning Database Administrator Hargrove Inc. From jwcolby at colbyconsulting.com Thu Mar 27 13:29:56 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 14:29:56 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000c01c89037$3cf1f4f0$10fe2e0a@Kermit> References: <000501c89022$cc33be10$0201a8c0@M90><0JYE00H03E75HVA1@vms173003.mailsrvcs.net><000b01c8902e$58387710$0201a8c0@M90><000d01c89031$6309e810$0201a8c0@M90> <000c01c89037$3cf1f4f0$10fe2e0a@Kermit> Message-ID: <001301c89038$8f15d480$0201a8c0@M90> Cool. I often buy out of date books for a few dollars used on Amazon.com. But the new stuff is rarely available. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Doris Manning Sent: Thursday, March 27, 2008 2:20 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. JC, Where are you based? You need to visit the Green Valley Bookfair once in a while. I have an entire library of $45-60 books that I have picked up for less than $20 a piece. http://www.gvbookfair.com/ Doris Manning Database Administrator Hargrove Inc. _______________________________________________ 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 Mar 27 13:47:20 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 14:47:20 -0400 Subject: [dba-SQLServer] Copy a database using James example code In-Reply-To: <002301c8901b$3c325f30$0201a8c0@M90> References: <001a01c8900f$456beff0$0201a8c0@M90><008b01c89014$d11c5620$6a00a8c0@fci.local> <002301c8901b$3c325f30$0201a8c0@M90> Message-ID: <001701c8903a$fd901400$0201a8c0@M90> James, I created the SP, and executed it from the query window. execute usp_CopyDatabase "IRGeneric", "IRTest", "\\Stonehenge\SQLServerData\" And received the following: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 1. Processed 2 pages for database 'IRGeneric', file 'IRGeneric_log' on file 1. BACKUP DATABASE successfully processed 194 pages in 0.061 seconds (25.935 MB/sec). Msg 3234, Level 16, State 2, Procedure usp_CopyDatabase, Line 30 Logical file 'IRGeneric_Data' is not part of database 'IRTest'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 30 RESTORE DATABASE is terminating abnormally. It certainly sounds like the backup happened, and if I go to the \\Stonehenge\SQLServerData\ directory there is a file IRGeneric.BAK. It would seem that restoring the backup file to a different file name is causing an issue? One obvious question, how do I compute the line number referenced? Is that "line 30 from the top of the file" or line 30 from the procedure declaration? My uneducated guess is from the function declaration line. After that, any clue on what the failure is actually saying. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ 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 From djkr at msn.com Thu Mar 27 14:12:19 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Thu, 27 Mar 2008 19:12:19 -0000 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000d01c89031$6309e810$0201a8c0@M90> Message-ID: Hi John Enjoy the launch, and make sure to pick up your Heroes wallet. Nope, you won't find SQLS 2008 in there (apart from the Nov 07 CTP), because MS haven't got it working yet! But you do get a nice Appreciation Voucher card (wow!) - which will entitle you to the Standard Edition when it does come out... John -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 27 March 2008 17:39 To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful >The follow up upgrade to sql server, that is SqlServer 2008 will >provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 From jwcolby at colbyconsulting.com Thu Mar 27 14:29:34 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 15:29:34 -0400 Subject: [dba-SQLServer] Being helpful In-Reply-To: References: <000d01c89031$6309e810$0201a8c0@M90> Message-ID: <000101c89040$e3a57fc0$0201a8c0@M90> LOL. I forgot that SQL Server 2008 was one of the launch products missing from the launch. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: Thursday, March 27, 2008 3:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Hi John Enjoy the launch, and make sure to pick up your Heroes wallet. Nope, you won't find SQLS 2008 in there (apart from the Nov 07 CTP), because MS haven't got it working yet! But you do get a nice Appreciation Voucher card (wow!) - which will entitle you to the Standard Edition when it does come out... John -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 27 March 2008 17:39 To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful >The follow up upgrade to sql server, that is SqlServer 2008 will >provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From dwaters at usinternet.com Thu Mar 27 15:00:58 2008 From: dwaters at usinternet.com (Dan Waters) Date: Thu, 27 Mar 2008 15:00:58 -0500 Subject: [dba-SQLServer] MS Launch Event (was: Being helpful) In-Reply-To: References: <000d01c89031$6309e810$0201a8c0@M90> Message-ID: <002001c89045$469a2730$0300a8c0@danwaters> John, What software are they giving away (or give a 'voucher' for at the launch event)? Thanks, Dan -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: Thursday, March 27, 2008 2:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Hi John Enjoy the launch, and make sure to pick up your Heroes wallet. Nope, you won't find SQLS 2008 in there (apart from the Nov 07 CTP), because MS haven't got it working yet! But you do get a nice Appreciation Voucher card (wow!) - which will entitle you to the Standard Edition when it does come out... John -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 27 March 2008 17:39 To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful >The follow up upgrade to sql server, that is SqlServer 2008 will >provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From robert at webedb.com Thu Mar 27 15:26:37 2008 From: robert at webedb.com (Robert L. Stewart) Date: Thu, 27 Mar 2008 15:26:37 -0500 Subject: [dba-SQLServer] Create, Backup, and Restore to new location In-Reply-To: References: Message-ID: <200803272027.m2RKRNM9005278@databaseadvisors.com> All of the following has been tested and works in our production environment except the restore portion. What was missing from your code you last posted, John, was the move syntax. Maybe there are enough comments in it this time and it is definitely not doctoral thesis. I am on the list to learn from the likes of Paul. Robert CREATE PROCEDURE dbo. pCreate_Load_DB -- initialize all of the variables that need to be passed in @DBNameCreate VARCHAR ( 64 ), @DBNameBackup VARCHAR ( 64 ), @data_path NVARCHAR ( 256 ) = NULL, @BackupLocation VARCHAR ( 500 ) = NULL, @Drive CHAR ( 1 ), @InstanceName SYSNAME = NULL, @Drive VARCHAR ( 1 ) = NULL, @strDBDir varchar ( 200 ) AS BEGIN -- set the record count to off SET NOCOUNT ON ; -- setup some local variables DECLARE @Sql NVARCHAR ( MAX ), @ErrorMessage VARCHAR ( 500 ) -- set the default value of the error message SET @ErrorMessage = 'No Error' -- if the path is not passed in, get the path used by the database as the default IF @data_path IS NULL BEGIN SET @data_path = ( SELECT SUBSTRING ( physical_name , 1, CHARINDEX ( N 'master.mdf' , LOWER ( physical_name )) - 1) FROM master. sys.master_files WHERE database_id = 1 AND file_id = 1 ) ; END -- execute the CREATE DATABASE statement -- build a string to hold the create dastabase statement SET @Sql = 'CREATE DATABASE Sales ON ( NAME = ' + @DBNameCreate + '_dat, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'dat.mdf' + CHAR ( 39 ) + ', SIZE = 10, FILEGROWTH = 5 ) LOG ON ( NAME = ' + @DBNameCreate + '_log, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'log.ldf' + CHAR ( 39 ) + ', SIZE = 5MB )' -- execute the sql statement you created above EXEC sp_executesql @Sql -- check to see if the drive letter was passed in IF @Drive IS NULL SET @Drive = 'F' -- check to see if the sql server instance name was passed in IF @InstanceName IS NULL SET @InstanceName = CAST ( ISNULL ( SERVERPROPERTY ( 'InstanceName' ), SERVERPROPERTY ( 'ServerName' )) AS SYSNAME ) -- check to see if the location for the backup was passed in if @BackupLocation is null SET @BackupLocation = @Drive + ':\SQL_Backups\' + @InstanceName + '\' -- wrap backing up the database into a TRY/Catch BEGIN TRY -- Create the string to do the backup -- use 'WITH INIT' to make sure only a single backup is stored in the backup file SET @SQL = 'BACKUP DATABASE ' + @DBNameBackup + ' TO DISK=' + CHAR ( 39 ) + @BackupLocation + @DBNameBackup + '_BACKUP.BAK' + CHAR ( 39 ) + ' WITH INIT' -- execute the SQL string created above EXEC sp_ExecuteSql @SQL -- truncate the log files -- the following code to the first END TRY can be left out -- it is used to truncate the logs on the database -- after a backup BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY SIMPLE' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + CHAR ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'TRUE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN CHECKPOINT END BEGIN SET @Sql = 'DBCC SHRINKFILE (' + @DBNameBackup + '_Log,1)' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + CHAR ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'FALSE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY FULL' EXEC sp_executesql @Sql END END TRY BEGIN CATCH SELECT @ErrorMessage = ERROR_MESSAGE () ; END CATCH -- now we can 'MOVE' the database to another location and restore it into the -- database we created in the beginning of this. BEGIN TRY -- build the restore database command with the MOVE function specified SET @Sql = 'RESTORE DATABASE ' + char ( 39 ) + @DBNameCreate + char ( 39 ) SET @Sql = @Sql + ' FROM DISK = ' + CHAR ( 39 ) + @strDBDir + @DBNameBackup + '.bak' + CHAR ( 39 ) SET @Sql = @Sql + ' WITH MOVE ' + char ( 13 ) + @DBNameBackup + '_Data' + CHAR ( 39 ) SET @Sql = @Sql + ' TO ' + CHAR ( 39 ) + @strDBDir + @strDBNameTo + '.mdf' + ChaR ( 39 ), SET @Sql = @Sql + ' MOVE ' + char ( 39 ) + @DBNameBackup + '_Log' + char ( 39 ) SET @Sql = @Sql + ' TO ' + CHAR ( 39 ) + @strDBDir + @DBNameCreate + '.ldf' + CHAR ( 39 ) -- Execute the sql statement created above EXEC sp_executesql @Sql END TRY BEGIN CATCH SELECT @ErrorMessage = ERROR_MESSAGE () ; END CATCH END From jwcolby at colbyconsulting.com Thu Mar 27 15:27:39 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 16:27:39 -0400 Subject: [dba-SQLServer] MS Launch Event (was: Being helpful) In-Reply-To: <002001c89045$469a2730$0300a8c0@danwaters> References: <000d01c89031$6309e810$0201a8c0@M90> <002001c89045$469a2730$0300a8c0@danwaters> Message-ID: <000701c89049$014f84a0$0201a8c0@M90> One of each - Windows 2008, SQL Server 2008 and Visual Studio 2008. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Dan Waters Sent: Thursday, March 27, 2008 4:01 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] MS Launch Event (was: Being helpful) John, What software are they giving away (or give a 'voucher' for at the launch event)? Thanks, Dan -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: Thursday, March 27, 2008 2:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Hi John Enjoy the launch, and make sure to pick up your Heroes wallet. Nope, you won't find SQLS 2008 in there (apart from the Nov 07 CTP), because MS haven't got it working yet! But you do get a nice Appreciation Voucher card (wow!) - which will entitle you to the Standard Edition when it does come out... John -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 27 March 2008 17:39 To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful >The follow up upgrade to sql server, that is SqlServer 2008 will >provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 _______________________________________________ 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 From James at fcidms.com Thu Mar 27 15:51:01 2008 From: James at fcidms.com (James Barash) Date: Thu, 27 Mar 2008 16:51:01 -0400 Subject: [dba-SQLServer] Copy a database using James example code In-Reply-To: <001701c8903a$fd901400$0201a8c0@M90> Message-ID: <00f301c8904c$44665310$6a00a8c0@fci.local> John: It is failing because the stored procedure makes certain assumptions about the logical and physical names of the mdf and ldf files, which is seems do not apply to your test database. It assumes the data file is called IRGeneric_Data.mdf and the log file is called IRGeneric_Log.ndf. According to the output, it looks as though your files are called IRGeneric.mdf and IRGeneric_Log.ndf. If you change the line: Select @strDBNameData = @strDBNameFrom + '_Data' To Select @strDBNameData = @strDBNameFrom then it should work. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 2:47 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using James example code James, I created the SP, and executed it from the query window. execute usp_CopyDatabase "IRGeneric", "IRTest", "\\Stonehenge\SQLServerData\" And received the following: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 1. Processed 2 pages for database 'IRGeneric', file 'IRGeneric_log' on file 1. BACKUP DATABASE successfully processed 194 pages in 0.061 seconds (25.935 MB/sec). Msg 3234, Level 16, State 2, Procedure usp_CopyDatabase, Line 30 Logical file 'IRGeneric_Data' is not part of database 'IRTest'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 30 RESTORE DATABASE is terminating abnormally. It certainly sounds like the backup happened, and if I go to the \\Stonehenge\SQLServerData\ directory there is a file IRGeneric.BAK. It would seem that restoring the backup file to a different file name is causing an issue? One obvious question, how do I compute the line number referenced? Is that "line 30 from the top of the file" or line 30 from the procedure declaration? My uneducated guess is from the function declaration line. After that, any clue on what the failure is actually saying. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ 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 Mar 27 15:56:57 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 16:56:57 -0400 Subject: [dba-SQLServer] Create, Backup, and Restore to new location In-Reply-To: <200803272027.m2RKRNM9005278@databaseadvisors.com> References: <200803272027.m2RKRNM9005278@databaseadvisors.com> Message-ID: <000901c8904d$1902e200$0201a8c0@M90> Thanks Robert, I will give it a try. And I do see your comments. When I looked at your last version my eyes glazed over (as they still do here) so it may be that there were comments there as well and I was just too glassy eyed to see them. I can mostly read this stuff if I take the time. I cannot troubleshoot it however. Thanks you very much for the code and I will try it out right now to see where I get. I must say I like the begin / end as well as the error handling stuff. It kinds of breaks the code up into definable parts. There are two Drive parameters specified, and I get an immediate error when I try to parse it. Msg 134, Level 15, State 1, Procedure pCreate_Load_DB, Line 14 The variable name '@Drive' has already been declared. Variable names must be unique within a query batch or stored procedure. Msg 102, Level 15, State 1, Procedure pCreate_Load_DB, Line 32 Incorrect syntax near 'master.mdf'. Msg 137, Level 15, State 2, Procedure pCreate_Load_DB, Line 113 Must declare the scalar variable "@strDBDir". Msg 137, Level 15, State 2, Procedure pCreate_Load_DB, Line 115 Must declare the scalar variable "@strDBDir". Msg 137, Level 15, State 2, Procedure pCreate_Load_DB, Line 117 Must declare the scalar variable "@strDBDir". I deleted the first one on the idea that the second one was the same thing that would allow a null. Now when I parse I get: Msg 102, Level 15, State 1, Procedure pCreate_Load_DB, Line 31 Incorrect syntax near 'master.mdf'. Msg 137, Level 15, State 2, Procedure pCreate_Load_DB, Line 114 Must declare the scalar variable "@strDBNameTo" Is there anyway to turn on line numbering so that I can see what line number means? Is the line number an absolute count down from the Procedure declaration? John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Thursday, March 27, 2008 4:27 PM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Create, Backup, and Restore to new location All of the following has been tested and works in our production environment except the restore portion. What was missing from your code you last posted, John, was the move syntax. Maybe there are enough comments in it this time and it is definitely not doctoral thesis. I am on the list to learn from the likes of Paul. Robert CREATE PROCEDURE dbo. pCreate_Load_DB -- initialize all of the variables that need to be passed in @DBNameCreate VARCHAR ( 64 ), @DBNameBackup VARCHAR ( 64 ), @data_path NVARCHAR ( 256 ) = NULL, @BackupLocation VARCHAR ( 500 ) = NULL, @Drive CHAR ( 1 ), @InstanceName SYSNAME = NULL, @Drive VARCHAR ( 1 ) = NULL, @strDBDir varchar ( 200 ) AS BEGIN -- set the record count to off SET NOCOUNT ON ; -- setup some local variables DECLARE @Sql NVARCHAR ( MAX ), @ErrorMessage VARCHAR ( 500 ) -- set the default value of the error message SET @ErrorMessage = 'No Error' -- if the path is not passed in, get the path used by the database as the default IF @data_path IS NULL BEGIN SET @data_path = ( SELECT SUBSTRING ( physical_name , 1, CHARINDEX ( N 'master.mdf' , LOWER ( physical_name )) - 1) FROM master. sys.master_files WHERE database_id = 1 AND file_id = 1 ) ; END -- execute the CREATE DATABASE statement -- build a string to hold the create dastabase statement SET @Sql = 'CREATE DATABASE Sales ON ( NAME = ' + @DBNameCreate + '_dat, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'dat.mdf' + CHAR ( 39 ) + ', SIZE = 10, FILEGROWTH = 5 ) LOG ON ( NAME = ' + @DBNameCreate + '_log, FILENAME = ' + CHAR ( 39 ) + @data_path + @DBNameCreate + 'log.ldf' + CHAR ( 39 ) + ', SIZE = 5MB )' -- execute the sql statement you created above EXEC sp_executesql @Sql -- check to see if the drive letter was passed in IF @Drive IS NULL SET @Drive = 'F' -- check to see if the sql server instance name was passed in IF @InstanceName IS NULL SET @InstanceName = CAST ( ISNULL ( SERVERPROPERTY ( 'InstanceName' ), SERVERPROPERTY ( 'ServerName' )) AS SYSNAME ) -- check to see if the location for the backup was passed in if @BackupLocation is null SET @BackupLocation = @Drive + ':\SQL_Backups\' + @InstanceName + '\' -- wrap backing up the database into a TRY/Catch BEGIN TRY -- Create the string to do the backup -- use 'WITH INIT' to make sure only a single backup is stored in the backup file SET @SQL = 'BACKUP DATABASE ' + @DBNameBackup + ' TO DISK=' + CHAR ( 39 ) + @BackupLocation + @DBNameBackup + '_BACKUP.BAK' + CHAR ( 39 ) + ' WITH INIT' -- execute the SQL string created above EXEC sp_ExecuteSql @SQL -- truncate the log files -- the following code to the first END TRY can be left out -- it is used to truncate the logs on the database -- after a backup BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY SIMPLE' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + CHAR ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'TRUE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN CHECKPOINT END BEGIN SET @Sql = 'DBCC SHRINKFILE (' + @DBNameBackup + '_Log,1)' EXEC sp_executesql @Sql END BEGIN SET @Sql = 'EXEC sp_dboption ' + CHAR ( 39 ) + @DBNameBackup + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'trunc. log on chkpt.' + CHAR ( 39 ) + ', ' + CHAR ( 39 ) + 'FALSE' + CHAR ( 39 ) EXEC sp_executesql @Sql END BEGIN SET @Sql = 'ALTER DATABASE ' + @DBNameBackup + ' SET RECOVERY FULL' EXEC sp_executesql @Sql END END TRY BEGIN CATCH SELECT @ErrorMessage = ERROR_MESSAGE () ; END CATCH -- now we can 'MOVE' the database to another location and restore it into the -- database we created in the beginning of this. BEGIN TRY -- build the restore database command with the MOVE function specified SET @Sql = 'RESTORE DATABASE ' + char ( 39 ) + @DBNameCreate + char ( 39 ) SET @Sql = @Sql + ' FROM DISK = ' + CHAR ( 39 ) + @strDBDir + @DBNameBackup + '.bak' + CHAR ( 39 ) SET @Sql = @Sql + ' WITH MOVE ' + char ( 13 ) + @DBNameBackup + '_Data' + CHAR ( 39 ) SET @Sql = @Sql + ' TO ' + CHAR ( 39 ) + @strDBDir + @strDBNameTo + '.mdf' + ChaR ( 39 ), SET @Sql = @Sql + ' MOVE ' + char ( 39 ) + @DBNameBackup + '_Log' + char ( 39 ) SET @Sql = @Sql + ' TO ' + CHAR ( 39 ) + @strDBDir + @DBNameCreate + '.ldf' + CHAR ( 39 ) -- Execute the sql statement created above EXEC sp_executesql @Sql END TRY BEGIN CATCH SELECT @ErrorMessage = ERROR_MESSAGE () ; END CATCH END _______________________________________________ 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 Mar 27 16:14:09 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 17:14:09 -0400 Subject: [dba-SQLServer] Copy a database using James example code In-Reply-To: <00f301c8904c$44665310$6a00a8c0@fci.local> References: <001701c8903a$fd901400$0201a8c0@M90> <00f301c8904c$44665310$6a00a8c0@fci.local> Message-ID: <000a01c8904f$80075740$0201a8c0@M90> James, that does indeed execute properly if it is executed from the server computer, using local paths (E:\SQLServerData instead of \\Stonehenge\SQLServerData\). If I try to run it from my laptop it gives errors: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 2. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 2. BACKUP DATABASE successfully processed 193 pages in 0.007 seconds (225.865 MB/sec). Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.mdf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.mdf'. Use WITH MOVE to identify a valid location for the file. Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.ldf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric_log' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.ldf'. Use WITH MOVE to identify a valid location for the file. Msg 3119, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 Problems were identified while planning for the RESTORE statement. Previous messages provide details. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. AFAIK the \\ directories are read / write. Perhaps SQL Server will not perform some operations to network paths? If I run it from my Server machine substituting e:\SQLServerData\ it runs. If I try to execute the SP from my laptop using E:\ (which exists on the server but not on my laptop) it throws an error: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 4. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 4. BACKUP DATABASE successfully processed 193 pages in 0.024 seconds (65.877 MB/sec). Msg 3159, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 The tail of the log for the database "IRTest" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. I suspect that this is a "something fails the second time" kind of thing since it is throwing the same error when executed again directly on the server. I tried the following: RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName WITH REPLACE But it now gives the infamous "incorrect syntax near WITH" error. RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH REPLACE WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName Gives me the same thing. GETTING CLOSE!! 8-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 4:51 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code John: It is failing because the stored procedure makes certain assumptions about the logical and physical names of the mdf and ldf files, which is seems do not apply to your test database. It assumes the data file is called IRGeneric_Data.mdf and the log file is called IRGeneric_Log.ndf. According to the output, it looks as though your files are called IRGeneric.mdf and IRGeneric_Log.ndf. If you change the line: Select @strDBNameData = @strDBNameFrom + '_Data' To Select @strDBNameData = @strDBNameFrom then it should work. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 2:47 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using James example code James, I created the SP, and executed it from the query window. execute usp_CopyDatabase "IRGeneric", "IRTest", "\\Stonehenge\SQLServerData\" And received the following: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 1. Processed 2 pages for database 'IRGeneric', file 'IRGeneric_log' on file 1. BACKUP DATABASE successfully processed 194 pages in 0.061 seconds (25.935 MB/sec). Msg 3234, Level 16, State 2, Procedure usp_CopyDatabase, Line 30 Logical file 'IRGeneric_Data' is not part of database 'IRTest'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 30 RESTORE DATABASE is terminating abnormally. It certainly sounds like the backup happened, and if I go to the \\Stonehenge\SQLServerData\ directory there is a file IRGeneric.BAK. It would seem that restoring the backup file to a different file name is causing an issue? One obvious question, how do I compute the line number referenced? Is that "line 30 from the top of the file" or line 30 from the procedure declaration? My uneducated guess is from the function declaration line. After that, any clue on what the failure is actually saying. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ 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 From James at fcidms.com Thu Mar 27 16:52:46 2008 From: James at fcidms.com (James Barash) Date: Thu, 27 Mar 2008 17:52:46 -0400 Subject: [dba-SQLServer] Copy a database using James example code In-Reply-To: <000a01c8904f$80075740$0201a8c0@M90> Message-ID: <010701c89054$e534bb30$6a00a8c0@fci.local> I've only tried to run it from the server using a local path since SQL Server can only create database files on a local drive. I use Remote Desktop to connect to the server and run everything from there. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 5:14 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code James, that does indeed execute properly if it is executed from the server computer, using local paths (E:\SQLServerData instead of \\Stonehenge\SQLServerData\). If I try to run it from my laptop it gives errors: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 2. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 2. BACKUP DATABASE successfully processed 193 pages in 0.007 seconds (225.865 MB/sec). Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.mdf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.mdf'. Use WITH MOVE to identify a valid location for the file. Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.ldf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric_log' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.ldf'. Use WITH MOVE to identify a valid location for the file. Msg 3119, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 Problems were identified while planning for the RESTORE statement. Previous messages provide details. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. AFAIK the \\ directories are read / write. Perhaps SQL Server will not perform some operations to network paths? If I run it from my Server machine substituting e:\SQLServerData\ it runs. If I try to execute the SP from my laptop using E:\ (which exists on the server but not on my laptop) it throws an error: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 4. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 4. BACKUP DATABASE successfully processed 193 pages in 0.024 seconds (65.877 MB/sec). Msg 3159, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 The tail of the log for the database "IRTest" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. I suspect that this is a "something fails the second time" kind of thing since it is throwing the same error when executed again directly on the server. I tried the following: RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName WITH REPLACE But it now gives the infamous "incorrect syntax near WITH" error. RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH REPLACE WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName Gives me the same thing. GETTING CLOSE!! 8-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 4:51 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code John: It is failing because the stored procedure makes certain assumptions about the logical and physical names of the mdf and ldf files, which is seems do not apply to your test database. It assumes the data file is called IRGeneric_Data.mdf and the log file is called IRGeneric_Log.ndf. According to the output, it looks as though your files are called IRGeneric.mdf and IRGeneric_Log.ndf. If you change the line: Select @strDBNameData = @strDBNameFrom + '_Data' To Select @strDBNameData = @strDBNameFrom then it should work. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 2:47 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using James example code James, I created the SP, and executed it from the query window. execute usp_CopyDatabase "IRGeneric", "IRTest", "\\Stonehenge\SQLServerData\" And received the following: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 1. Processed 2 pages for database 'IRGeneric', file 'IRGeneric_log' on file 1. BACKUP DATABASE successfully processed 194 pages in 0.061 seconds (25.935 MB/sec). Msg 3234, Level 16, State 2, Procedure usp_CopyDatabase, Line 30 Logical file 'IRGeneric_Data' is not part of database 'IRTest'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 30 RESTORE DATABASE is terminating abnormally. It certainly sounds like the backup happened, and if I go to the \\Stonehenge\SQLServerData\ directory there is a file IRGeneric.BAK. It would seem that restoring the backup file to a different file name is causing an issue? One obvious question, how do I compute the line number referenced? Is that "line 30 from the top of the file" or line 30 from the procedure declaration? My uneducated guess is from the function declaration line. After that, any clue on what the failure is actually saying. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ 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 Mar 27 17:43:56 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 27 Mar 2008 18:43:56 -0400 Subject: [dba-SQLServer] Copy a database using James example code In-Reply-To: <010701c89054$e534bb30$6a00a8c0@fci.local> References: <000a01c8904f$80075740$0201a8c0@M90> <010701c89054$e534bb30$6a00a8c0@fci.local> Message-ID: <001601c8905c$0b061c80$0201a8c0@M90> It failed the second time though, even when run locally. Something to do with the log file. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 5:53 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code I've only tried to run it from the server using a local path since SQL Server can only create database files on a local drive. I use Remote Desktop to connect to the server and run everything from there. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 5:14 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code James, that does indeed execute properly if it is executed from the server computer, using local paths (E:\SQLServerData instead of \\Stonehenge\SQLServerData\). If I try to run it from my laptop it gives errors: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 2. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 2. BACKUP DATABASE successfully processed 193 pages in 0.007 seconds (225.865 MB/sec). Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.mdf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.mdf'. Use WITH MOVE to identify a valid location for the file. Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.ldf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric_log' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.ldf'. Use WITH MOVE to identify a valid location for the file. Msg 3119, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 Problems were identified while planning for the RESTORE statement. Previous messages provide details. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. AFAIK the \\ directories are read / write. Perhaps SQL Server will not perform some operations to network paths? If I run it from my Server machine substituting e:\SQLServerData\ it runs. If I try to execute the SP from my laptop using E:\ (which exists on the server but not on my laptop) it throws an error: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 4. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 4. BACKUP DATABASE successfully processed 193 pages in 0.024 seconds (65.877 MB/sec). Msg 3159, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 The tail of the log for the database "IRTest" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. I suspect that this is a "something fails the second time" kind of thing since it is throwing the same error when executed again directly on the server. I tried the following: RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName WITH REPLACE But it now gives the infamous "incorrect syntax near WITH" error. RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH REPLACE WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName Gives me the same thing. GETTING CLOSE!! 8-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 4:51 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code John: It is failing because the stored procedure makes certain assumptions about the logical and physical names of the mdf and ldf files, which is seems do not apply to your test database. It assumes the data file is called IRGeneric_Data.mdf and the log file is called IRGeneric_Log.ndf. According to the output, it looks as though your files are called IRGeneric.mdf and IRGeneric_Log.ndf. If you change the line: Select @strDBNameData = @strDBNameFrom + '_Data' To Select @strDBNameData = @strDBNameFrom then it should work. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 2:47 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using James example code James, I created the SP, and executed it from the query window. execute usp_CopyDatabase "IRGeneric", "IRTest", "\\Stonehenge\SQLServerData\" And received the following: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 1. Processed 2 pages for database 'IRGeneric', file 'IRGeneric_log' on file 1. BACKUP DATABASE successfully processed 194 pages in 0.061 seconds (25.935 MB/sec). Msg 3234, Level 16, State 2, Procedure usp_CopyDatabase, Line 30 Logical file 'IRGeneric_Data' is not part of database 'IRTest'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 30 RESTORE DATABASE is terminating abnormally. It certainly sounds like the backup happened, and if I go to the \\Stonehenge\SQLServerData\ directory there is a file IRGeneric.BAK. It would seem that restoring the backup file to a different file name is causing an issue? One obvious question, how do I compute the line number referenced? Is that "line 30 from the top of the file" or line 30 from the procedure declaration? My uneducated guess is from the function declaration line. After that, any clue on what the failure is actually saying. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ 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 From ab-mi at post3.tele.dk Thu Mar 27 17:50:01 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Thu, 27 Mar 2008 23:50:01 +0100 Subject: [dba-SQLServer] Copy a database using James example code In-Reply-To: <20080327211759.UNOA22541.fep23.mail.dk@databaseadvisors.com> Message-ID: <002301c8905c$f8d8ae00$2101a8c0@AB> John, You wrote: >I tried the following: > >RESTORE DATABASE @strDBNameTo > FROM DISK = @FileName > WITH MOVE @strDBNameData TO @MDFName, > MOVE @strDBNameLog TO @NDFName > WITH REPLACE > >But it now gives the infamous "incorrect syntax near WITH" error. > >RESTORE DATABASE @strDBNameTo > FROM DISK = @FileName > WITH REPLACE > WITH MOVE @strDBNameData TO @MDFName, > MOVE @strDBNameLog TO @NDFName > >Gives me the same thing. > >GETTING CLOSE!! 8-) You are close indeed... But your syntax should be: RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName, REPLACE - according to BOL ... and experience ;-) Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 27. marts 2008 22:14 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] Copy a database using James example code James, that does indeed execute properly if it is executed from the server computer, using local paths (E:\SQLServerData instead of \\Stonehenge\SQLServerData\). If I try to run it from my laptop it gives errors: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 2. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 2. BACKUP DATABASE successfully processed 193 pages in 0.007 seconds (225.865 MB/sec). Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.mdf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.mdf'. Use WITH MOVE to identify a valid location for the file. Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.ldf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric_log' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.ldf'. Use WITH MOVE to identify a valid location for the file. Msg 3119, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 Problems were identified while planning for the RESTORE statement. Previous messages provide details. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. AFAIK the \\ directories are read / write. Perhaps SQL Server will not perform some operations to network paths? If I run it from my Server machine substituting e:\SQLServerData\ it runs. If I try to execute the SP from my laptop using E:\ (which exists on the server but not on my laptop) it throws an error: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 4. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 4. BACKUP DATABASE successfully processed 193 pages in 0.024 seconds (65.877 MB/sec). Msg 3159, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 The tail of the log for the database "IRTest" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. I suspect that this is a "something fails the second time" kind of thing since it is throwing the same error when executed again directly on the server. I tried the following: RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName WITH REPLACE But it now gives the infamous "incorrect syntax near WITH" error. RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH REPLACE WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName Gives me the same thing. GETTING CLOSE!! 8-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 4:51 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code John: It is failing because the stored procedure makes certain assumptions about the logical and physical names of the mdf and ldf files, which is seems do not apply to your test database. It assumes the data file is called IRGeneric_Data.mdf and the log file is called IRGeneric_Log.ndf. According to the output, it looks as though your files are called IRGeneric.mdf and IRGeneric_Log.ndf. If you change the line: Select @strDBNameData = @strDBNameFrom + '_Data' To Select @strDBNameData = @strDBNameFrom then it should work. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 2:47 PM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using James example code James, I created the SP, and executed it from the query window. execute usp_CopyDatabase "IRGeneric", "IRTest", "\\Stonehenge\SQLServerData\" And received the following: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 1. Processed 2 pages for database 'IRGeneric', file 'IRGeneric_log' on file 1. BACKUP DATABASE successfully processed 194 pages in 0.061 seconds (25.935 MB/sec). Msg 3234, Level 16, State 2, Procedure usp_CopyDatabase, Line 30 Logical file 'IRGeneric_Data' is not part of database 'IRTest'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 30 RESTORE DATABASE is terminating abnormally. It certainly sounds like the backup happened, and if I go to the \\Stonehenge\SQLServerData\ directory there is a file IRGeneric.BAK. It would seem that restoring the backup file to a different file name is causing an issue? One obvious question, how do I compute the line number referenced? Is that "line 30 from the top of the file" or line 30 from the procedure declaration? My uneducated guess is from the function declaration line. After that, any clue on what the failure is actually saying. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Thursday, March 27, 2008 10:14 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using Elizabeth's suggestionplusparameters John: Try this: Create PROCEDURE [dbo].[usp_CopyDatabase] ( @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) ) AS BEGIN SET NOCOUNT ON; declare @FileName varchar(255), @MDFName varchar(255), @NDFName varchar(255), @strDBNameData varchar(255), @strDBNameLog varchar(255) Select @FileName = @strDBDir + @strDBNameFrom + '.bak' BACKUP DATABASE @strDBNameFrom TO DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' RESTORE FILELISTONLY FROM DISK = @FileName Select @FileName = @strDBDir + @strDBNameFrom + '.bak' Select @MDFName = @strDBDir + @strDBNameTo + '.mdf' Select @NDFName = @strDBDir + @strDBNameTo + '.ldf' Select @strDBNameData = @strDBNameFrom + '_Data' Select @strDBNameLog = @strDBNameFrom + '_Log' RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName END It should do exactly what you need. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 9:34 AM To: 'Discussion concerning MS SQL Server' Subject: [dba-SQLServer] Copy a database using Elizabeth's suggestion plusparameters Thanks Elizabeth and Gustav. I tried to get it working using passed in parameters, but promptly got bogged down in the ever helpful "error near ." error messages. I need a "FromDbName", a "ToDbName", and a "DbLocationPath" parameter. Just to show the kinds of issues that more advanced users never even think about anymore, but which stop me cold... I created these parameters in a stored procedure, copied the code in and started replacing the various pieces with @ParamThis and @paramThat. I immediately got the one and only error message that SQL Server knows "error near @". I got out BOL "the ever helpful.." ... Oh, different rant. I immediately commented out the code pasted in to the SP template and voila, it "ran". Uncommented just the first line and get "error near +" ALTER PROCEDURE [dbo].[usp_CopyDatabase] -- Add the parameters for the stored procedure here @strDBNameFrom varchar(100), @strDBNameTo varchar(100), @strDBDir varchar(255) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here --BACKUP DATABASE @strDBNameFrom -- TO DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE FILELISTONLY -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' --RESTORE DATABASE @strDBNameTo -- FROM DISK = @strDBDir + @strDBNameFrom + '.bak' -- WITH MOVE strDBNameFrom + '_Data' TO @strDBDir + @strDBNameTo + '.mdf', -- MOVE strDBNameFrom + '_Log' TO @strDBDir + @strDBNameTo + '.ldf' END My uneducated guess is that as soon as I start actually trying to run this thing, the parameters have nothing in them so they will not run. But... Running it is the only way to "SAVE" the changes right? So I am kind of stuck. So do I have to make my parameters have default values just so the changes to the code will save? Or is it even that? I can't imagine why I would get frustrated when I get the ever helpful "error near +". John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, March 27, 2008 4:57 AM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Copy a database using a store procedureor function Hi Elizabeth - and John The gun smoke distracted me so much from the original question that I had lost the request of John - to be able to perform this parameterized from code. But it seems like your suggestion could be the key of a solution. I found a minor error ('AdventureWorks_Data' should read just 'AdventureWorks'). With that corrected I simply moved your code (skipping the GO) into a pass-through query in Access: BACKUP DATABASE somedb TO DISK = 'c:\template2.bak' RESTORE FILELISTONLY FROM DISK = 'c:\template2.bak' RESTORE DATABASE newfromtemplate2 FROM DISK = 'c:\template2.bak' WITH MOVE 'somedb' TO 'c:\newfromtemplate2.mdf', MOVE 'somedb_log' TO 'c:\newfromtemplate2.ldf' Wow! In a few seconds you have a brand new database. Of course, once a template has been created you can skip the first part with the backup. Now, for this to work as to fulfill John's request, you will have to rewrite the SQL above to reflect the name of the new database but that can be done with a simple replace of "newfromtemplate2" to the actual new database name and then execute the query. This John can code with his left hand in Access and it shouldn't take much to write a small class in VB.net to perform the same two actions: replace the database name and send the SQL command to the server. /gustav >>> Elizabeth.J.Doering at wellsfargo.com 25-03-2008 21:10 >>> I haven't used this (being pretty new to this myself), but I'm sure some one else here can speak to it: E. Make a copy of a database using BACKUP and RESTORE This example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL). Copy Code BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak' RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.bak' RESTORE DATABASE TestDB FROM DISK = 'C:\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\testdb.mdf', MOVE 'AdventureWorks_Log' TO 'C:\testdb.ldf' GO This is from BOL for SQL Server 2005, which is often amazingly helpful. HTH, Liz Liz Doering elizabeth.j.doering at wellsfargo.com 612.667.2447 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Gustav at cactus.dk Thu Mar 27 17:51:55 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 27 Mar 2008 23:51:55 +0100 Subject: [dba-SQLServer] Copy a database using James example code Message-ID: Hi John Always read my gems carefully! Also, there seems to be several ways to name the data and log files. Some use a suffix of _data and _log, some only _log, and some nothing. As the file extension, .mdf or .ldf, tells it all I see no reason to use a suffix at all. However, my example base used _log. >>> jwcolby at colbyconsulting.com 27-03-2008 19:47 >>> Logical file 'IRGeneric_Data' is not part of database 'IRTest'. .. From djkr at msn.com Thu Mar 27 18:27:54 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Thu, 27 Mar 2008 23:27:54 -0000 Subject: [dba-SQLServer] MS Launch Event (was: Being helpful) In-Reply-To: <000701c89049$014f84a0$0201a8c0@M90> Message-ID: Specifically, Windows Server 2008 Enterprise 32-bit - one year evaluation Windows Server 2008 Enterprise 64-bit - one year evaluation Visual Studio 2008 Standard Edition SQL Server 2008 Developer 32-bit, Nov 2007 CTP SQL Server 2008 Developer 64-bit, Nov 2007 CTP And in a separate pack, Windows Vista Ultimate with SP1 32-bit, with a bit of paper inside saying "Your right to use the software will expire 365 days after its installment." Windows Live services and 90-day free trial of Windows Live OneCare John -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 27 March 2008 20:28 To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] MS Launch Event (was: Being helpful) One of each - Windows 2008, SQL Server 2008 and Visual Studio 2008. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Dan Waters Sent: Thursday, March 27, 2008 4:01 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] MS Launch Event (was: Being helpful) John, What software are they giving away (or give a 'voucher' for at the launch event)? Thanks, Dan -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: Thursday, March 27, 2008 2:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Hi John Enjoy the launch, and make sure to pick up your Heroes wallet. Nope, you won't find SQLS 2008 in there (apart from the Nov 07 CTP), because MS haven't got it working yet! But you do get a nice Appreciation Voucher card (wow!) - which will entitle you to the Standard Edition when it does come out... John -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 27 March 2008 17:39 To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful >The follow up upgrade to sql server, that is SqlServer 2008 will >provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. What a jarring contrast to > switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Thu Mar 27 19:53:25 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 17:53:25 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000d01c89031$6309e810$0201a8c0@M90> Message-ID: <0JYF000OB152P5Z2@vms173001.mailsrvcs.net> John, The launch event is a good one to go to not to mention the fact that you get FREE software from Microsoft. I just came back from one in Spokane, WA and I was amazed at how far the technology has developed. I'm still developing web-based apps on .NET 1.1 and here Microsoft already has .NET 3.5 out there. I'm glad I skipped over 2.0 because the presentation I saw (specifically Visual Studio 2008) had better ways of doing stuff. LINQ for SQL takes querying SQL to another level. In fact the presenter went as far as to say that the "old notion" of creating stored procedures for faster code execution no longer holds true in some cases because the compiler and LINQ and the whole architecture takes programming (using those tools) to a new paradigm. Ah, yes...more learning to take place in the coming months. The presenters typed in and ran actual code and explained everything and did away with all the standard presentation slides from Microsoft. It was truly a developer's presentation. I saw them connect to a SQL server database, drag and drop a couple of related tables, drag and drop the stored procedures they wanted to run and then develop right in Visual Studio 2008. Of course someone still has to write the sprocs but as mentioned by the presenters, there will be cases when you won't need to write sprocs when you use LINQ. Here's a LINK to LINQ... ;) http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.a spx And yes...my eyes are glazed over as well. Mind you...this is not child's play because of the totally new concepts and ways of doing things. Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 10:39 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful >The follow up upgrade to sql server, that is SqlServer 2008 will >provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 From ebarro at verizon.net Thu Mar 27 19:56:09 2008 From: ebarro at verizon.net (Eric Barro) Date: Thu, 27 Mar 2008 17:56:09 -0700 Subject: [dba-SQLServer] Being helpful In-Reply-To: <000101c89040$e3a57fc0$0201a8c0@M90> Message-ID: <0JYF00EOO1FD58B3@vms040.mailsrvcs.net> But you get Vista Ultimate with SP1 as part of the FREE stuff along with the coupon for SQL server 2008 for when it comes out. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, March 27, 2008 12:30 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful LOL. I forgot that SQL Server 2008 was one of the launch products missing from the launch. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: Thursday, March 27, 2008 3:12 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful Hi John Enjoy the launch, and make sure to pick up your Heroes wallet. Nope, you won't find SQLS 2008 in there (apart from the Nov 07 CTP), because MS haven't got it working yet! But you do get a nice Appreciation Voucher card (wow!) - which will entitle you to the Standard Edition when it does come out... John -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 27 March 2008 17:39 To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Being helpful >The follow up upgrade to sql server, that is SqlServer 2008 will >provide a lot of really cool tools such as intellisense, and the ability to run the same script across multiple servers etc. neat stuff, along w/ things like db compression etc. I shall sit on my wallet then and wait for SQL Server 2008. I am going to a product launch down in Charlotte next month and should get my copy there. It sounds like it will be worth the time to learn the new environment. Of course that means a whole new set of books. My wife HATES my books, at $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? BASIC PROGRAMMING! ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 27, 2008 1:25 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Being helpful it would seem that you may look forward to the ever upgrade path from M$. while there are current purchasable apps you can get for Sql Server such as Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really help speed up much of the syntax building process there are also other tools from similar vendors that will help with syntax problems etc. The follow up upgrade to sql server, that is SqlServer 2008 will provide a lot of really cool tools such as intellisense, and the ability to run the same script accross multiple servers etc. neat stuff, along w/ things like db comrpession etc. Until then, I think the community has been helpful, and so long as we all try to stay ontopic we can avoid another rant gone wrong. -- Francisco On Thu, Mar 27, 2008 at 10:16 AM, jwcolby wrote: > Much of my frustrations come from switching from a development > environment like .Net or Access to the query editor in SQL Server. > Even in the relatively basic Access we have modules and classes, > intellisense, syntax checking, error handlers, compile time errors > that actually mean something and so forth. > What a jarring contrast to switch to SQL Server query editor. > > But I am making progress. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ 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 _______________________________________________ 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 From fhtapia at gmail.com Fri Mar 28 10:12:59 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Fri, 28 Mar 2008 08:12:59 -0700 Subject: [dba-SQLServer] MS Launch Event (was: Being helpful) In-Reply-To: <000701c89049$014f84a0$0201a8c0@M90> References: <000d01c89031$6309e810$0201a8c0@M90> <002001c89045$469a2730$0300a8c0@danwaters> <000701c89049$014f84a0$0201a8c0@M90> Message-ID: I just received my confirmation for apr8 in aneheim, ca On 3/27/08, jwcolby wrote: > One of each - Windows 2008, SQL Server 2008 and Visual Studio 2008. > > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Dan Waters > Sent: Thursday, March 27, 2008 4:01 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] MS Launch Event (was: Being helpful) > > John, > > What software are they giving away (or give a 'voucher' for at the launch > event)? > > Thanks, > Dan > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of DJK(John) > Robinson > Sent: Thursday, March 27, 2008 2:12 PM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Being helpful > > Hi John > > Enjoy the launch, and make sure to pick up your Heroes wallet. Nope, you > won't find SQLS 2008 in there (apart from the Nov 07 CTP), because MS > haven't got it working yet! But you do get a nice Appreciation Voucher card > (wow!) - which will entitle you to the Standard Edition when it does come > out... > > John > > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: 27 March 2008 17:39 > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] Being helpful > > > >The follow up upgrade to sql server, that is SqlServer 2008 will > >provide a > lot of really cool tools such as intellisense, and the ability to run the > same script across multiple servers etc. neat stuff, along w/ things like db > compression etc. > > I shall sit on my wallet then and wait for SQL Server 2008. I am going to a > product launch down in Charlotte next month and should get my copy there. It > sounds like it will be worth the time to learn the new environment. > > Of course that means a whole new set of books. My wife HATES my books, at > $45-$60 apiece. Has anyone seen any 2008 books that they can recommend? > BASIC PROGRAMMING! ;-) > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco > Tapia > Sent: Thursday, March 27, 2008 1:25 PM > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] Being helpful > > it would seem that you may look forward to the ever upgrade path from M$. > while there are current purchasable apps you can get for Sql Server such as > Sql Prompt (2.0 free or 3.0purchase) that provide intellisense and really > help speed up much of the syntax building process there are also other tools > from similar vendors that will help with syntax problems etc. The follow up > upgrade to sql server, that is SqlServer 2008 will provide a lot of really > cool tools such as intellisense, and the ability to run the same script > accross multiple servers etc. neat stuff, along w/ things like db > comrpession etc. > > Until then, I think the community has been helpful, and so long as we all > try to stay ontopic we can avoid another rant gone wrong. > -- > Francisco > > On Thu, Mar 27, 2008 at 10:16 AM, jwcolby > wrote: > > > Much of my frustrations come from switching from a development > > environment like .Net or Access to the query editor in SQL Server. > > Even in the relatively basic Access we have modules and classes, > > intellisense, syntax checking, error handlers, compile time errors > > that actually mean something and so forth. > > What a jarring contrast to switch to SQL Server query editor. > > > > But I am making progress. > > > > John W. Colby > > Colby Consulting > > www.ColbyConsulting.com > > > > > > > -- > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > _______________________________________________ > 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 > > > > _______________________________________________ > 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 > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- Sent from Gmail for mobile | mobile.google.com -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Fri Mar 28 14:01:14 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 28 Mar 2008 15:01:14 -0400 Subject: [dba-SQLServer] Dynamic SQL Message-ID: <001e01c89106$18ecc2e0$0201a8c0@M90> I know that dynamic SQL is frowned upon for obvious reasons. Please phrase your responses understanding the following: 1) I work by myself, there are no other DB users. 2) My network is connected through a "consumer grade" router / firewall to the internet. 3) I run Avs, software firewalls and the newer "zero day" malware detectors such as Counterspy and Threatfire. 4) I have never (to my knowledge) been infected by any viruses, key loggers, Trojans or other such malware. 5) There ARE other computers in the house that also connect to the internet, specifically my wife's laptop and my son's laptop. Both of them run Avs and software firewalls. I am trying to build SPs and such to perform functionality such as Delete * from tblTemp Bulk Insert 'SomeDbName.SomeTblName' from 'SomeFilePath' Obviously if I am going to use this to process files in my many different databases then I will need a way to pass in SomeDbName, SomeTblName, and SomeFileName. ATM I am doing this by using dynamic SQL, i.e. building up SQL strings and then Executing those strings. It all seems to be working. I am SPECIFICALLY ASKING for "best practices" couched within the situation that I work in. I am not using a database that directly faces the internet or is ever touched (to my knowledge) by any outsiders. Even considering my situation, if the "better way" is actually attainable (by ME, and you already know what THAT means) I will do things the better way. 1) Is there another way besides the dynamic SQL? 2) Is this "other way" generic, can it be applied to all of my databases, or would I need to store the same SP in each db and use local table names. Or would I need to do something else entirely. Please please do not respond with how to handle this for an internet company taking orders from the internet or an IBM with 6 thousand direct users of the database. But please do let me know if or why I should take the same precautions anyway and what those precautions would be IF I really need to be doing more. I am asking for all opinions, and yet I am still asking you to consider my circumstances and offer your opinions based around that. Obviously I want to be as secure as I can be while accepting the fact that it is just lonely me with no dedicated security guru. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Fri Mar 28 14:38:37 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 28 Mar 2008 15:38:37 -0400 Subject: [dba-SQLServer] Append temp table to tbl in SP Message-ID: <001f01c8910b$52149ed0$0201a8c0@M90> I have a bunch of databases with name / address info. With all of them I need to validate the name / address portion periodically, which means exporting to CSV, feeding those files to a validation program, and then reimporting the results into SQL Server. AFAICT however I go about this I will end up working with temporary tables. I know how to "script to query window as..." and then cut and paste that to get an append for example. When I do that though it ends up with a list of field names specific to the tables that I do this on. That is fine for a specific situation but not so fine if I want to do this over a dozen databases. Do I simply need to build this kind of SPs directly in each database and then call that SP. Doing that has the disadvantage of having to build each such SP individually, and having the SPs fail if the tables ever change field names or table names. However it has the advantage that once done, it just works until something breaks it (table name change, field name change etc). I don't know enough about SQL Server and TSQL to see any alternative though. Are there doable alternatives for situations like this? If so can you provide example code that is close enough to running that I can get it working? John W. Colby Colby Consulting www.ColbyConsulting.com From Gustav at cactus.dk Fri Mar 28 17:44:38 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 28 Mar 2008 23:44:38 +0100 Subject: [dba-SQLServer] Append temp table to tbl in SP Message-ID: Hi John I would write SQL strings in .Net and then fire these as pass-through queries to the SQL Server engine. /gustav >>> jwcolby at colbyconsulting.com 28-03-2008 20:38 >>> I have a bunch of databases with name / address info. With all of them I need to validate the name / address portion periodically, which means exporting to CSV, feeding those files to a validation program, and then reimporting the results into SQL Server. AFAICT however I go about this I will end up working with temporary tables. I know how to "script to query window as..." and then cut and paste that to get an append for example. When I do that though it ends up with a list of field names specific to the tables that I do this on. That is fine for a specific situation but not so fine if I want to do this over a dozen databases. Do I simply need to build this kind of SPs directly in each database and then call that SP. Doing that has the disadvantage of having to build each such SP individually, and having the SPs fail if the tables ever change field names or table names. However it has the advantage that once done, it just works until something breaks it (table name change, field name change etc). I don't know enough about SQL Server and TSQL to see any alternative though. Are there doable alternatives for situations like this? If so can you provide example code that is close enough to running that I can get it working? John W. Colby Colby Consulting www.ColbyConsulting.com From michael at ddisolutions.com.au Fri Mar 28 19:42:31 2008 From: michael at ddisolutions.com.au (Michael Maddison) Date: Sat, 29 Mar 2008 11:42:31 +1100 Subject: [dba-SQLServer] Dynamic SQL References: <001e01c89106$18ecc2e0$0201a8c0@M90> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D013BF4A1@ddi-01.DDI.local> Hi John, Dynamic SQL seems like the obvious solution in your circumstance. If you are executing the strings from code then another option is to build some generic global sprocs on your server. I would do something like... USE MASTER GO CREATE PROCEDURE dbo.DeleteFrom ( @DB nvarchar(100), @table nvarchar(100) ) AS DECLARE @SQL [nvarchar](4000) IF @DB <> N'' AND @table <> N'' BEGIN SET @SQL = 'DELETE FROM ' + @DB + '.' + LTRIM(RTRIM(@table)) PRINT @SQL EXEC sp_executesql @SQL PRINT @@ROWCOUNT END And call it like EXEC [master].[dbo].[DeleteFrom] 'databasename', 'dbo.tablename' HTH Michael M I know that dynamic SQL is frowned upon for obvious reasons. Please phrase your responses understanding the following: 1) I work by myself, there are no other DB users. 2) My network is connected through a "consumer grade" router / firewall to the internet. 3) I run Avs, software firewalls and the newer "zero day" malware detectors such as Counterspy and Threatfire. 4) I have never (to my knowledge) been infected by any viruses, key loggers, Trojans or other such malware. 5) There ARE other computers in the house that also connect to the internet, specifically my wife's laptop and my son's laptop. Both of them run Avs and software firewalls. I am trying to build SPs and such to perform functionality such as Delete * from tblTemp Bulk Insert 'SomeDbName.SomeTblName' from 'SomeFilePath' Obviously if I am going to use this to process files in my many different databases then I will need a way to pass in SomeDbName, SomeTblName, and SomeFileName. ATM I am doing this by using dynamic SQL, i.e. building up SQL strings and then Executing those strings. It all seems to be working. I am SPECIFICALLY ASKING for "best practices" couched within the situation that I work in. I am not using a database that directly faces the internet or is ever touched (to my knowledge) by any outsiders. Even considering my situation, if the "better way" is actually attainable (by ME, and you already know what THAT means) I will do things the better way. 1) Is there another way besides the dynamic SQL? 2) Is this "other way" generic, can it be applied to all of my databases, or would I need to store the same SP in each db and use local table names. Or would I need to do something else entirely. Please please do not respond with how to handle this for an internet company taking orders from the internet or an IBM with 6 thousand direct users of the database. But please do let me know if or why I should take the same precautions anyway and what those precautions would be IF I really need to be doing more. I am asking for all opinions, and yet I am still asking you to consider my circumstances and offer your opinions based around that. Obviously I want to be as secure as I can be while accepting the fact that it is just lonely me with no dedicated security guru. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Gustav at cactus.dk Sat Mar 29 04:59:13 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sat, 29 Mar 2008 10:59:13 +0100 Subject: [dba-SQLServer] Article: LINQ and stored procedures Message-ID: Hi all It looks like MS is thinking of Visual Studio as a major tool for controlling SQL Server. An interesting article by William Sheldon in SQL Server Magazine tells more, indeed about the SQLMetal tool: Microsoft Visual Studio 2008 and Language Integrated Query (LINQ) queries convert Visual Basic and C# code into T-SQL*based database calls, which are executed against SQL Server. Your Microsoft Visual Studio 2008 projects will need to target the Microsoft .NET Framework 3.5 to use LINQ. SQLMetal generates the necessary data entity and DataContext object as either a .vb or .cs source file. http://sqlmag-pwf.texterity.com/sqlmag/200804/ Pick article: LINQ to Your SQL Server Data A registration is needed but that is free. /gustav From Gustav at cactus.dk Sat Mar 29 05:50:58 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sat, 29 Mar 2008 11:50:58 +0100 Subject: [dba-SQLServer] Article: LINQ and stored procedures Message-ID: As requested recently by JC: >From the cover story "The Next Generation: Visual Studio 2008": LINQ speeds up application development by providing immediate fedback through IntelliSense and compile time error checking that wasn't possible using the older dual-mode ADO.NET and T-SQL development methodology. /gustav >>> Gustav at cactus.dk 29-03-2008 10:59 >>> Hi all It looks like MS is thinking of Visual Studio as a major tool for controlling SQL Server. An interesting article by William Sheldon in SQL Server Magazine tells more, indeed about the SQLMetal tool: Microsoft Visual Studio 2008 and Language Integrated Query (LINQ) queries convert Visual Basic and C# code into T-SQL*based database calls, which are executed against SQL Server. Your Microsoft Visual Studio 2008 projects will need to target the Microsoft .NET Framework 3.5 to use LINQ. SQLMetal generates the necessary data entity and DataContext object as either a .vb or .cs source file. http://sqlmag-pwf.texterity.com/sqlmag/200804/ Pick article: LINQ to Your SQL Server Data A registration is needed but that is free. /gustav From Gustav at cactus.dk Sat Mar 29 06:58:27 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sat, 29 Mar 2008 12:58:27 +0100 Subject: [dba-SQLServer] SQLsafe: Backup, restore, compressed Message-ID: Hi all In SQL Server Magazine: http://sqlmag-pwf.texterity.com/sqlmag/200804/ I noticed this link to a free backup tool that backups large databases in half the time of the native backup tool: http://www.idera.com/FreeTools/default.aspx /gustav From fuller.artful at gmail.com Sat Mar 29 08:09:41 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sat, 29 Mar 2008 09:09:41 -0400 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: <59A61174B1F5B54B97FD4ADDE71E7D013BF4A1@ddi-01.DDI.local> References: <001e01c89106$18ecc2e0$0201a8c0@M90> <59A61174B1F5B54B97FD4ADDE71E7D013BF4A1@ddi-01.DDI.local> Message-ID: <29f585dd0803290609i3f73ba6cme66c6d9fe569eb23@mail.gmail.com> JC, I think Michael is quite right in his advice. I would add only one thing (welcome to the world of SQL Server)... Back up master database every time you touch it. There's nothing inherently wrong with touching it, but you must be aware that there's a reason it's called master. So every time you add to it or change something in it, do a backup. There's another item I may have mentioned previously, but repetition is good for the soul. If you have sprocs or UDFs or even tables that you want in every db, add these objects to model. Model is so named because it is the model for every new db you create, so anything in it is "inherited" by the new db. I have played with this quite a bit, and found it to be one of the under-used capabilities of SQL Server. A while back I posted some functions that strip the time part from a DateTime column and the converse. I plonked these (and several other such reusables) into model and presto, every new db I create has them instantly. A. On 3/28/08, Michael Maddison wrote: > > Hi John, > > Dynamic SQL seems like the obvious solution in your circumstance. > If you are executing the strings from code then another option is to > build some generic global > sprocs on your server. > > I would do something like... > > USE MASTER > GO > CREATE PROCEDURE dbo.DeleteFrom ( > @DB nvarchar(100), > @table nvarchar(100) > ) > AS > DECLARE @SQL [nvarchar](4000) > > IF @DB <> N'' AND @table <> N'' > BEGIN > SET @SQL = 'DELETE FROM ' + @DB + '.' + LTRIM(RTRIM(@table)) > PRINT @SQL > EXEC sp_executesql @SQL > PRINT @@ROWCOUNT > END > > > And call it like > EXEC [master].[dbo].[DeleteFrom] 'databasename', 'dbo.tablename' > > HTH > > Michael M > > From fuller.artful at gmail.com Sat Mar 29 08:57:08 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sat, 29 Mar 2008 09:57:08 -0400 Subject: [dba-SQLServer] Article: LINQ and stored procedures In-Reply-To: References: Message-ID: <29f585dd0803290657k4636bb33u358f20f768ccee48@mail.gmail.com> IMO we are coming to a crossroad here. I ought to indicate my perspective on this at once, so that anything I write subsequently can be understood as coming from said perspective. Fuller's Sixth Law states "Anything the database can do, the database shoulddo." This law applies to every db from dBASE to Access to MS SQL to DB2 to Oracle to Objectivity and so on. To rephrase it in practical terms, this means that the FE ought to be stripped of everything the db engine itself can do. This would include FK constraints, to name just one thing. The FE should never never never touch tables directly, but instead always go through a query (in Access) or a view (in MS SQL and others) or a table UDF (in MS SQL). Nobody but God (i.e. me) should be able to touch the tables directly. Db-oriented logic encased in the FE is a bad idea for several reasons. Perhaps the most notable is that said logic would have to be encased in every FE that touches the db, which is career suicide. On the opposite extreme, if everything is in the db itself then all the FE has to do is fire a sproc and pass the appropriate parms. It is not trivial to translate a call from VB6 or Delphi or .NET or PHP or Python into any other of these languages, but it is much less work than to rebuild the logic in any new language. A call to a sproc is basically a one-liner in any language. Populate the parms, call the sproc, deal with the result set. Ok, that's my take. Linq is going in an entirely new direction, and to be fair, I've read the docs (well some of them) and been impressed by some of the new language techniques, and also been thankful that one can use Linq to call sprocs. But Linq overall seems to me a method of eliminating the profession of SQL Developer. It attempts and suggests to move increasing amounts of business logic upwards, to either the middle tier or the FE, and in both cases I deem this incorrect. The push ought to be down not up, IMO. I want the db to be a magic black box and the FE to simply follow some basic communication rules, and everything will automagically happen. Moving the logic of result-set-handling up to the MT or the FE is a bad choice, IMO. All this said, I am still investigating Linq big-time. When I noticed that one did not have to construct the SQL statements inside it, but could instead call a sproc or table-udf, I was much relieved and much more intrigued. So I shall pursue this path but also stick to my previously stated law until it has been refuted. I will pursue the path of setting up parms and calling sprocs, and totally ignore the idea of dynamically constructing SQL statements within Linq. And finally, I think that any investment in Linq for SQL is a dead end. Linq for Entities is clearly the future. Linq for SQL is dead in the water, subsumed completely by Linq for Entities. I can see some future there, for sure. The idea that anything is encapsulated as a data source has promise. But I still want the real logic and business in the back end. A. On 3/29/08, Gustav Brock wrote: > > As requested recently by JC: > > >From the cover story "The Next Generation: Visual Studio 2008": > > > LINQ speeds up application development by providing immediate fedback > through IntelliSense and compile time error checking that wasn't possible > using the older dual-mode ADO.NET and T-SQL development methodology. > > > /gustav > > From jwcolby at colbyconsulting.com Sat Mar 29 10:31:04 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sat, 29 Mar 2008 11:31:04 -0400 Subject: [dba-SQLServer] Copy a database using James example code In-Reply-To: <002301c8905c$f8d8ae00$2101a8c0@AB> References: <20080327211759.UNOA22541.fep23.mail.dk@databaseadvisors.com> <002301c8905c$f8d8ae00$2101a8c0@AB> Message-ID: <000001c891b1$e7254f00$0201a8c0@M90> SUCCESS! Thanks Asger, and thanks James. I now have a SP that copies my template database to a name of my choice. Woohoooo. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Thursday, March 27, 2008 6:50 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Copy a database using James example code John, You wrote: >I tried the following: > >RESTORE DATABASE @strDBNameTo > FROM DISK = @FileName > WITH MOVE @strDBNameData TO @MDFName, > MOVE @strDBNameLog TO @NDFName > WITH REPLACE > >But it now gives the infamous "incorrect syntax near WITH" error. > >RESTORE DATABASE @strDBNameTo > FROM DISK = @FileName > WITH REPLACE > WITH MOVE @strDBNameData TO @MDFName, > MOVE @strDBNameLog TO @NDFName > >Gives me the same thing. > >GETTING CLOSE!! 8-) You are close indeed... But your syntax should be: RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName, REPLACE - according to BOL ... and experience ;-) Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 27. marts 2008 22:14 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] Copy a database using James example code James, that does indeed execute properly if it is executed from the server computer, using local paths (E:\SQLServerData instead of \\Stonehenge\SQLServerData\). If I try to run it from my laptop it gives errors: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 2. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 2. BACKUP DATABASE successfully processed 193 pages in 0.007 seconds (225.865 MB/sec). Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.mdf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.mdf'. Use WITH MOVE to identify a valid location for the file. Msg 5110, Level 16, State 2, Procedure usp_CopyDatabase, Line 33 The file "\\Stonehenge\SQLServerData\IRTest.ldf" is on a network path that is not supported for database files. Msg 3156, Level 16, State 3, Procedure usp_CopyDatabase, Line 33 File 'IRGeneric_log' cannot be restored to '\\Stonehenge\SQLServerData\IRTest.ldf'. Use WITH MOVE to identify a valid location for the file. Msg 3119, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 Problems were identified while planning for the RESTORE statement. Previous messages provide details. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. AFAIK the \\ directories are read / write. Perhaps SQL Server will not perform some operations to network paths? If I run it from my Server machine substituting e:\SQLServerData\ it runs. If I try to execute the SP from my laptop using E:\ (which exists on the server but not on my laptop) it throws an error: Processed 192 pages for database 'IRGeneric', file 'IRGeneric' on file 4. Processed 1 pages for database 'IRGeneric', file 'IRGeneric_log' on file 4. BACKUP DATABASE successfully processed 193 pages in 0.024 seconds (65.877 MB/sec). Msg 3159, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 The tail of the log for the database "IRTest" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log. Msg 3013, Level 16, State 1, Procedure usp_CopyDatabase, Line 33 RESTORE DATABASE is terminating abnormally. I suspect that this is a "something fails the second time" kind of thing since it is throwing the same error when executed again directly on the server. I tried the following: RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName WITH REPLACE But it now gives the infamous "incorrect syntax near WITH" error. RESTORE DATABASE @strDBNameTo FROM DISK = @FileName WITH REPLACE WITH MOVE @strDBNameData TO @MDFName, MOVE @strDBNameLog TO @NDFName Gives me the same thing. GETTING CLOSE!! 8-) From jwcolby at colbyconsulting.com Sat Mar 29 10:31:33 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sat, 29 Mar 2008 11:31:33 -0400 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: <29f585dd0803290609i3f73ba6cme66c6d9fe569eb23@mail.gmail.com> References: <001e01c89106$18ecc2e0$0201a8c0@M90><59A61174B1F5B54B97FD4ADDE71E7D013BF4A1@ddi-01.DDI.local> <29f585dd0803290609i3f73ba6cme66c6d9fe569eb23@mail.gmail.com> Message-ID: <000301c891b1$f8352310$0201a8c0@M90> Thanks for that Arthur. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Saturday, March 29, 2008 9:10 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Dynamic SQL JC, I think Michael is quite right in his advice. I would add only one thing (welcome to the world of SQL Server)... Back up master database every time you touch it. There's nothing inherently wrong with touching it, but you must be aware that there's a reason it's called master. So every time you add to it or change something in it, do a backup. There's another item I may have mentioned previously, but repetition is good for the soul. If you have sprocs or UDFs or even tables that you want in every db, add these objects to model. Model is so named because it is the model for every new db you create, so anything in it is "inherited" by the new db. I have played with this quite a bit, and found it to be one of the under-used capabilities of SQL Server. A while back I posted some functions that strip the time part from a DateTime column and the converse. I plonked these (and several other such reusables) into model and presto, every new db I create has them instantly. A. On 3/28/08, Michael Maddison wrote: > > Hi John, > > Dynamic SQL seems like the obvious solution in your circumstance. > If you are executing the strings from code then another option is to > build some generic global sprocs on your server. > > I would do something like... > > USE MASTER > GO > CREATE PROCEDURE dbo.DeleteFrom ( > @DB nvarchar(100), > @table nvarchar(100) > ) > AS > DECLARE @SQL [nvarchar](4000) > > IF @DB <> N'' AND @table <> N'' > BEGIN > SET @SQL = 'DELETE FROM ' + @DB + '.' + LTRIM(RTRIM(@table)) > PRINT @SQL > EXEC sp_executesql @SQL > PRINT @@ROWCOUNT > END > > > And call it like > EXEC [master].[dbo].[DeleteFrom] 'databasename', 'dbo.tablename' > > HTH > > Michael M > > _______________________________________________ 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 Sat Mar 29 10:32:07 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sat, 29 Mar 2008 11:32:07 -0400 Subject: [dba-SQLServer] Article: LINQ and stored procedures In-Reply-To: <29f585dd0803290657k4636bb33u358f20f768ccee48@mail.gmail.com> References: <29f585dd0803290657k4636bb33u358f20f768ccee48@mail.gmail.com> Message-ID: <000401c891b2$0ca400a0$0201a8c0@M90> Arthur, I have always agreed with that perspective (the DB does whatever it can) however... I have to say that until the DB has modern programming tools to accomplish these objectives then it simply takes more time that it is worth to do that. I understand the "every application that touches the data needs to know the rules" issue, but in fact millions of very real and useful databases only ever have a single application that touches the database, and to be so pedantic is often not useful. There is a time and a place for that concept, but it is not every time and place. There is also another thing to consider. I know that we really in fact seldom do so but in order to move an application from one data store to another REQUIRES that the application logic NOT be in the data store, or moving will be a non-starter. There are often valid reasons for being able to run on different platforms and data stores. Having all the logic embedded in SQL Server makes moving to MySQL completely impossible. If only the data and basic "they can all do this" kinds of things like constraints and perhaps triggers actually reside in the data store then having an application that can work on SQL Server and oracle and MySQL suddenly becomes at least possible if still not always feasible. And finally, I have a very interesting book, Expert VB 2005 business objects by Rockford Lhotka. Just a bit over my head but interesting none the less. In that book Rockford designs a "execute where it belongs" method. Class objects are actually passed back and forth between machines, filled by the SQL Server, processed by a business server, changes saved back to the data store by the SQL Server. The SQL Server does what it is supposed to do, filling class instances with data, and storing them back into the tables. All the logic of doing that including rules about what is legal (in terms of data validation) are processed by the SQL Server. Business rules OTOH are processed by the Business server. They can be on the same machine, or two different machines, even on two different continents. There is a very real case to be made for the fact that while the data may be common, laws and customs, currencies and time zones and languages can make it useful to have a program able to operate on a common set of data but apply different business ruled based on location. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Saturday, March 29, 2008 9:57 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Article: LINQ and stored procedures IMO we are coming to a crossroad here. I ought to indicate my perspective on this at once, so that anything I write subsequently can be understood as coming from said perspective. Fuller's Sixth Law states "Anything the database can do, the database shoulddo." This law applies to every db from dBASE to Access to MS SQL to DB2 to Oracle to Objectivity and so on. To rephrase it in practical terms, this means that the FE ought to be stripped of everything the db engine itself can do. This would include FK constraints, to name just one thing. The FE should never never never touch tables directly, but instead always go through a query (in Access) or a view (in MS SQL and others) or a table UDF (in MS SQL). Nobody but God (i.e. me) should be able to touch the tables directly. Db-oriented logic encased in the FE is a bad idea for several reasons. Perhaps the most notable is that said logic would have to be encased in every FE that touches the db, which is career suicide. On the opposite extreme, if everything is in the db itself then all the FE has to do is fire a sproc and pass the appropriate parms. It is not trivial to translate a call from VB6 or Delphi or .NET or PHP or Python into any other of these languages, but it is much less work than to rebuild the logic in any new language. A call to a sproc is basically a one-liner in any language. Populate the parms, call the sproc, deal with the result set. Ok, that's my take. Linq is going in an entirely new direction, and to be fair, I've read the docs (well some of them) and been impressed by some of the new language techniques, and also been thankful that one can use Linq to call sprocs. But Linq overall seems to me a method of eliminating the profession of SQL Developer. It attempts and suggests to move increasing amounts of business logic upwards, to either the middle tier or the FE, and in both cases I deem this incorrect. The push ought to be down not up, IMO. I want the db to be a magic black box and the FE to simply follow some basic communication rules, and everything will automagically happen. Moving the logic of result-set-handling up to the MT or the FE is a bad choice, IMO. All this said, I am still investigating Linq big-time. When I noticed that one did not have to construct the SQL statements inside it, but could instead call a sproc or table-udf, I was much relieved and much more intrigued. So I shall pursue this path but also stick to my previously stated law until it has been refuted. I will pursue the path of setting up parms and calling sprocs, and totally ignore the idea of dynamically constructing SQL statements within Linq. And finally, I think that any investment in Linq for SQL is a dead end. Linq for Entities is clearly the future. Linq for SQL is dead in the water, subsumed completely by Linq for Entities. I can see some future there, for sure. The idea that anything is encapsulated as a data source has promise. But I still want the real logic and business in the back end. A. From jlawrenc1 at shaw.ca Sat Mar 29 12:03:27 2008 From: jlawrenc1 at shaw.ca (Jim Lawrence) Date: Sat, 29 Mar 2008 10:03:27 -0700 Subject: [dba-SQLServer] Article: LINQ and stored procedures In-Reply-To: <29f585dd0803290657k4636bb33u358f20f768ccee48@mail.gmail.com> References: <29f585dd0803290657k4636bb33u358f20f768ccee48@mail.gmail.com> Message-ID: Hi Arthur: I think you are right on the mark. Traditionally, the FE is only for Presentation and the BE should handle all the business logic and data management.... just let MS SQL do what MS SQL does best and does fastest. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Saturday, March 29, 2008 6:57 AM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Article: LINQ and stored procedures IMO we are coming to a crossroad here. I ought to indicate my perspective on this at once, so that anything I write subsequently can be understood as coming from said perspective. Fuller's Sixth Law states "Anything the database can do, the database shoulddo." This law applies to every db from dBASE to Access to MS SQL to DB2 to Oracle to Objectivity and so on. To rephrase it in practical terms, this means that the FE ought to be stripped of everything the db engine itself can do. This would include FK constraints, to name just one thing. The FE should never never never touch tables directly, but instead always go through a query (in Access) or a view (in MS SQL and others) or a table UDF (in MS SQL). Nobody but God (i.e. me) should be able to touch the tables directly. Db-oriented logic encased in the FE is a bad idea for several reasons. Perhaps the most notable is that said logic would have to be encased in every FE that touches the db, which is career suicide. On the opposite extreme, if everything is in the db itself then all the FE has to do is fire a sproc and pass the appropriate parms. It is not trivial to translate a call from VB6 or Delphi or .NET or PHP or Python into any other of these languages, but it is much less work than to rebuild the logic in any new language. A call to a sproc is basically a one-liner in any language. Populate the parms, call the sproc, deal with the result set. Ok, that's my take. Linq is going in an entirely new direction, and to be fair, I've read the docs (well some of them) and been impressed by some of the new language techniques, and also been thankful that one can use Linq to call sprocs. But Linq overall seems to me a method of eliminating the profession of SQL Developer. It attempts and suggests to move increasing amounts of business logic upwards, to either the middle tier or the FE, and in both cases I deem this incorrect. The push ought to be down not up, IMO. I want the db to be a magic black box and the FE to simply follow some basic communication rules, and everything will automagically happen. Moving the logic of result-set-handling up to the MT or the FE is a bad choice, IMO. All this said, I am still investigating Linq big-time. When I noticed that one did not have to construct the SQL statements inside it, but could instead call a sproc or table-udf, I was much relieved and much more intrigued. So I shall pursue this path but also stick to my previously stated law until it has been refuted. I will pursue the path of setting up parms and calling sprocs, and totally ignore the idea of dynamically constructing SQL statements within Linq. And finally, I think that any investment in Linq for SQL is a dead end. Linq for Entities is clearly the future. Linq for SQL is dead in the water, subsumed completely by Linq for Entities. I can see some future there, for sure. The idea that anything is encapsulated as a data source has promise. But I still want the real logic and business in the back end. A. On 3/29/08, Gustav Brock wrote: > > As requested recently by JC: > > >From the cover story "The Next Generation: Visual Studio 2008": > > > LINQ speeds up application development by providing immediate fedback > through IntelliSense and compile time error checking that wasn't possible > using the older dual-mode ADO.NET and T-SQL development methodology. > > > /gustav > > _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Gustav at cactus.dk Sat Mar 29 17:51:34 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sat, 29 Mar 2008 23:51:34 +0100 Subject: [dba-SQLServer] Article: LINQ and stored procedures Message-ID: Hi Arthur I think that law of yours is up for revision, if for nothing else because it neglects a middle-tier in a three- or more tier system. If it is very important for a setup that "anything" can communicate safely with the database, that "something" should be isolated from the back end completely by offering a neutral API to the outside world. A good example of this are web-services. The interface is fully standardised. You can access it from any application which understands to communicate with a web-service and these applications may be programmed with any language. What is behind the web-service is of no importance - in fact it can be replaced completely as long as the new back end system provides the same information. In my opinion the mechanics of the back end should be limited to the basics which will "never" change, like autoincrement/random/GUID generated IDs, relations and enforced referential integrity, rules like a start date cannot be later than an end date and a month value is between 1 and 12, materialized or aggregated tables for lookup or statistics etc. On the other hand, rules that will change - and that is the business logic - should be kept in a middle-tier or - when this is not present - the front end. After all this is how most of us built front end/back end systems with Access. But I only regard this as general rules. Most systems have a twist of some sort. /gustav >>> fuller.artful at gmail.com 29-03-2008 14:57 >>> IMO we are coming to a crossroad here. I ought to indicate my perspective on this at once, so that anything I write subsequently can be understood as coming from said perspective. Fuller's Sixth Law states "Anything the database can do, the database shoulddo." This law applies to every db from dBASE to Access to MS SQL to DB2 to Oracle to Objectivity and so on. To rephrase it in practical terms, this means that the FE ought to be stripped of everything the db engine itself can do. This would include FK constraints, to name just one thing. The FE should never never never touch tables directly, but instead always go through a query (in Access) or a view (in MS SQL and others) or a table UDF (in MS SQL). Nobody but God (i.e. me) should be able to touch the tables directly. Db-oriented logic encased in the FE is a bad idea for several reasons. Perhaps the most notable is that said logic would have to be encased in every FE that touches the db, which is career suicide. On the opposite extreme, if everything is in the db itself then all the FE has to do is fire a sproc and pass the appropriate parms. It is not trivial to translate a call from VB6 or Delphi or .NET or PHP or Python into any other of these languages, but it is much less work than to rebuild the logic in any new language. A call to a sproc is basically a one-liner in any language. Populate the parms, call the sproc, deal with the result set. Ok, that's my take. Linq is going in an entirely new direction, and to be fair, I've read the docs (well some of them) and been impressed by some of the new language techniques, and also been thankful that one can use Linq to call sprocs. But Linq overall seems to me a method of eliminating the profession of SQL Developer. It attempts and suggests to move increasing amounts of business logic upwards, to either the middle tier or the FE, and in both cases I deem this incorrect. The push ought to be down not up, IMO. I want the db to be a magic black box and the FE to simply follow some basic communication rules, and everything will automagically happen. Moving the logic of result-set-handling up to the MT or the FE is a bad choice, IMO. All this said, I am still investigating Linq big-time. When I noticed that one did not have to construct the SQL statements inside it, but could instead call a sproc or table-udf, I was much relieved and much more intrigued. So I shall pursue this path but also stick to my previously stated law until it has been refuted. I will pursue the path of setting up parms and calling sprocs, and totally ignore the idea of dynamically constructing SQL statements within Linq. And finally, I think that any investment in Linq for SQL is a dead end. Linq for Entities is clearly the future. Linq for SQL is dead in the water, subsumed completely by Linq for Entities. I can see some future there, for sure. The idea that anything is encapsulated as a data source has promise. But I still want the real logic and business in the back end. A. On 3/29/08, Gustav Brock wrote: > > As requested recently by JC: > > >From the cover story "The Next Generation: Visual Studio 2008": > > > LINQ speeds up application development by providing immediate fedback > through IntelliSense and compile time error checking that wasn't possible > using the older dual-mode ADO.NET and T-SQL development methodology. > > > /gustav From jwcolby at colbyconsulting.com Sun Mar 30 12:20:25 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sun, 30 Mar 2008 13:20:25 -0400 Subject: [dba-SQLServer] Drop restore indexes Message-ID: <001901c8928a$5985eb30$0201a8c0@M90> I am looking for a generic method to drop and then restore the indexes on a table. IOW, I have a bunch of tables that I have to do appends to, tens of millions of records. These tables may have dozens of indexes. I have always set up my indexes using the wizard so I don't have scripts already set up to create the indexes. I need to have some tool that will build scripts to recreate the indexes fond on a table and then remoce the indexes. Once the records are appended, I need to then run the scripts to rebuild all the saved index scripts. Is there such a tool? John W. Colby Colby Consulting www.ColbyConsulting.com From ssharkins at gmail.com Sun Mar 30 14:24:38 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Sun, 30 Mar 2008 15:24:38 -0400 Subject: [dba-SQLServer] Drop restore indexes References: <001901c8928a$5985eb30$0201a8c0@M90> Message-ID: <005b01c8929b$b4388bd0$4b3a8343@SusanOne> You're looking for a third party tool as opposed to a dynamic procedure? Susan H. > set up to create the indexes. I need to have some tool that will build > scripts to recreate the indexes fond on a table and then remoce the > indexes. > Once the records are appended, I need to then run the scripts to rebuild > all > the saved index scripts. > > Is there such a tool? From fuller.artful at gmail.com Sun Mar 30 15:07:09 2008 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sun, 30 Mar 2008 16:07:09 -0400 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <005b01c8929b$b4388bd0$4b3a8343@SusanOne> References: <001901c8928a$5985eb30$0201a8c0@M90> <005b01c8929b$b4388bd0$4b3a8343@SusanOne> Message-ID: <29f585dd0803301307y2f1660c2o2404d727fe513956@mail.gmail.com> It's built-in, JC. Once you've used the gui to build your table(s) and indexes, then you can be in MSMS and right-click on either the db or a selected table and select Script To and then choose your destination for said script and you will see what click-click-type-click did behind the scenes. Not that I ever expect you to write a Cert for MS-SQL, JC, but this is a good way to learn what's under the covers. And I also add, that virtually all these IDEs are script languages in disguise. Some of the IDEs make this readily apparent, such as Visual Studio, DreamWeaver, and others. Click here and you see the Gui, click there and you see the code behind. In Access it's a teensy bit more difficult to see, but export a form and then read the code and you shall see what I mean. They are ALL scripting languages. If you like the IDE then you like to click and drag and drop etc., but what's going on under the covers is script-generation. Back in the initial days of VS.NET there was a popular thread called "Alternatives to .NET IDE" or similar. People noticed that the IDE cost money but the framework didn't, and asked if there were an alternative IDE. The classic answer was, "Yes, NotePad". A sword that cuts both ways: you can learn the scripting language and write it free in NotePad or any other text editor, or you can drag and drop and pay money for the privilege. Last week I met a guy named John McKay who never never never used any of the gui tools in SQL 2005+. He preferred to type in all the commands and he could do it way more quickly than I could match, using the gui drag and drop stuff. Admittedly, he came from a Linux and Oracle background, but he could type so quickly and knew so precisely what he was doing that it blew me away. I prefer to see a picture: use the gui interface, add tables and views and udfs and so on, click this and drag there and I get the job done, but he knew this stuff so well that he could simply type join this and join that and presto, done in a fraction of the time it took me. Back to the topic at hand. Once you've created what you want in the gui, right-click at the appropriate level and then choose Generate Scripts. Choose your output destination and click OK and you're there. A. On Sun, Mar 30, 2008 at 3:24 PM, Susan Harkins wrote: > You're looking for a third party tool as opposed to a dynamic procedure? > > Susan H. > > set up to create the indexes. I need to have some tool that will build > > scripts to recreate the indexes fond on a table and then remoce the > > indexes. > > Once the records are appended, I need to then run the scripts to rebuild > > all > > the saved index scripts. > > > > Is there such a tool? > > _______________________________________________ > 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 Sun Mar 30 16:20:13 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sun, 30 Mar 2008 17:20:13 -0400 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <29f585dd0803301307y2f1660c2o2404d727fe513956@mail.gmail.com> References: <001901c8928a$5985eb30$0201a8c0@M90><005b01c8929b$b4388bd0$4b3a8343@SusanOne> <29f585dd0803301307y2f1660c2o2404d727fe513956@mail.gmail.com> Message-ID: <001a01c892ab$d85bd8e0$0201a8c0@M90> I do the "script to window" all the time. It is definitely cool, and I use it for building append queries from one db / table to another etc. Using it I am becoming familiar with SQL syntax, occasionally even "just writing it", though without a full on editor with all the good stuff it is often just faster to do the "script to" and cut and paste. I found where I can script just the individual indexes and that is good enough. I will cut and paste them one after another into a SP which I can then store and run as desired. So I am "close enough". I thought that there might be a "script all indexes to a window" kind of thing but have not found one. Thanks for the advice though. The scripting of a table I use a lot to "build" a similar table in a completely different database. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Sunday, March 30, 2008 4:07 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Drop restore indexes It's built-in, JC. Once you've used the gui to build your table(s) and indexes, then you can be in MSMS and right-click on either the db or a selected table and select Script To and then choose your destination for said script and you will see what click-click-type-click did behind the scenes. Not that I ever expect you to write a Cert for MS-SQL, JC, but this is a good way to learn what's under the covers. And I also add, that virtually all these IDEs are script languages in disguise. Some of the IDEs make this readily apparent, such as Visual Studio, DreamWeaver, and others. Click here and you see the Gui, click there and you see the code behind. In Access it's a teensy bit more difficult to see, but export a form and then read the code and you shall see what I mean. They are ALL scripting languages. If you like the IDE then you like to click and drag and drop etc., but what's going on under the covers is script-generation. Back in the initial days of VS.NET there was a popular thread called "Alternatives to .NET IDE" or similar. People noticed that the IDE cost money but the framework didn't, and asked if there were an alternative IDE. The classic answer was, "Yes, NotePad". A sword that cuts both ways: you can learn the scripting language and write it free in NotePad or any other text editor, or you can drag and drop and pay money for the privilege. Last week I met a guy named John McKay who never never never used any of the gui tools in SQL 2005+. He preferred to type in all the commands and he could do it way more quickly than I could match, using the gui drag and drop stuff. Admittedly, he came from a Linux and Oracle background, but he could type so quickly and knew so precisely what he was doing that it blew me away. I prefer to see a picture: use the gui interface, add tables and views and udfs and so on, click this and drag there and I get the job done, but he knew this stuff so well that he could simply type join this and join that and presto, done in a fraction of the time it took me. Back to the topic at hand. Once you've created what you want in the gui, right-click at the appropriate level and then choose Generate Scripts. Choose your output destination and click OK and you're there. A. On Sun, Mar 30, 2008 at 3:24 PM, Susan Harkins wrote: > You're looking for a third party tool as opposed to a dynamic procedure? > > Susan H. > > set up to create the indexes. I need to have some tool that will > > build scripts to recreate the indexes fond on a table and then > > remoce the indexes. > > Once the records are appended, I need to then run the scripts to > > rebuild all the saved index scripts. > > > > Is there such a tool? > > _______________________________________________ > 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 From ab-mi at post3.tele.dk Sun Mar 30 16:28:27 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Sun, 30 Mar 2008 23:28:27 +0200 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <20080330172213.QHJC11715.fep26.mail.dk@databaseadvisors.com> Message-ID: <000001c892ac$fe54ce20$2101a8c0@AB> John, Two options: 1. If your indexes are non-clustered the easiest way is: a) ALTER INDEX indexname ON tablename DISABLE - b) Do your appends - c) ALTER INDEX indexname ON tablename REBUILD. 2. If your indexes are clustered the first option is a no go, because disabling a clustered index will make the table inaccessible. Instead you can use SSMS to generate scripts for create and drop index, as pointed out by Arthur. In SSMS use Object Explorer to expand your table, expand Indexes, right-click an index and choose Script Index As -> Create / Drop. Repeat this for all indexes and all tables wanted. Then a) Run drop indexes scripts - b) Do your appends - c) Run create indexes scripts. For both options you can create a sproc for the DISABLE or DROP and another sproc for the REBUILD or CREATE on all wanted indexes on all wanted tables a once. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 30. marts 2008 19:20 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Drop restore indexes I am looking for a generic method to drop and then restore the indexes on a table. IOW, I have a bunch of tables that I have to do appends to, tens of millions of records. These tables may have dozens of indexes. I have always set up my indexes using the wizard so I don't have scripts already set up to create the indexes. I need to have some tool that will build scripts to recreate the indexes fond on a table and then remoce the indexes. Once the records are appended, I need to then run the scripts to rebuild all the saved index scripts. Is there such a tool? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Sun Mar 30 16:44:25 2008 From: ebarro at verizon.net (Eric Barro) Date: Sun, 30 Mar 2008 14:44:25 -0700 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <001a01c892ab$d85bd8e0$0201a8c0@M90> Message-ID: <0JYK004HKCE2AN94@vms173001.mailsrvcs.net> Actually, one thing I liked about Enterprise Manager for SQL server 2000 (can also be used with SQL server 2005), is the ability to script several objects (tables, indexes, security, databases, views, sprocs, UDFs) in one batch and save it as one big script file or several unique script files. You could also include scripts to DROP objects by checking a checkbox. I haven't found the same functionality using SSMS. Has anyone found the equivalent functionality? So...John, if you have Enterprise Manager you can do a "batch script" operation. I believe you can download Enterprise Manager since it's a FREE install. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Sunday, March 30, 2008 2:20 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Drop restore indexes I do the "script to window" all the time. It is definitely cool, and I use it for building append queries from one db / table to another etc. Using it I am becoming familiar with SQL syntax, occasionally even "just writing it", though without a full on editor with all the good stuff it is often just faster to do the "script to" and cut and paste. I found where I can script just the individual indexes and that is good enough. I will cut and paste them one after another into a SP which I can then store and run as desired. So I am "close enough". I thought that there might be a "script all indexes to a window" kind of thing but have not found one. Thanks for the advice though. The scripting of a table I use a lot to "build" a similar table in a completely different database. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Sunday, March 30, 2008 4:07 PM To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] Drop restore indexes It's built-in, JC. Once you've used the gui to build your table(s) and indexes, then you can be in MSMS and right-click on either the db or a selected table and select Script To and then choose your destination for said script and you will see what click-click-type-click did behind the scenes. Not that I ever expect you to write a Cert for MS-SQL, JC, but this is a good way to learn what's under the covers. And I also add, that virtually all these IDEs are script languages in disguise. Some of the IDEs make this readily apparent, such as Visual Studio, DreamWeaver, and others. Click here and you see the Gui, click there and you see the code behind. In Access it's a teensy bit more difficult to see, but export a form and then read the code and you shall see what I mean. They are ALL scripting languages. If you like the IDE then you like to click and drag and drop etc., but what's going on under the covers is script-generation. Back in the initial days of VS.NET there was a popular thread called "Alternatives to .NET IDE" or similar. People noticed that the IDE cost money but the framework didn't, and asked if there were an alternative IDE. The classic answer was, "Yes, NotePad". A sword that cuts both ways: you can learn the scripting language and write it free in NotePad or any other text editor, or you can drag and drop and pay money for the privilege. Last week I met a guy named John McKay who never never never used any of the gui tools in SQL 2005+. He preferred to type in all the commands and he could do it way more quickly than I could match, using the gui drag and drop stuff. Admittedly, he came from a Linux and Oracle background, but he could type so quickly and knew so precisely what he was doing that it blew me away. I prefer to see a picture: use the gui interface, add tables and views and udfs and so on, click this and drag there and I get the job done, but he knew this stuff so well that he could simply type join this and join that and presto, done in a fraction of the time it took me. Back to the topic at hand. Once you've created what you want in the gui, right-click at the appropriate level and then choose Generate Scripts. Choose your output destination and click OK and you're there. A. On Sun, Mar 30, 2008 at 3:24 PM, Susan Harkins wrote: > You're looking for a third party tool as opposed to a dynamic procedure? > > Susan H. > > set up to create the indexes. I need to have some tool that will > > build scripts to recreate the indexes fond on a table and then > > remoce the indexes. > > Once the records are appended, I need to then run the scripts to > > rebuild all the saved index scripts. > > > > Is there such a tool? > > _______________________________________________ > 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ebarro at verizon.net Sun Mar 30 16:45:58 2008 From: ebarro at verizon.net (Eric Barro) Date: Sun, 30 Mar 2008 14:45:58 -0700 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <000001c892ac$fe54ce20$2101a8c0@AB> Message-ID: <0JYK00G5MCBVZFCA@vms173003.mailsrvcs.net> Yeah, see...using Enterprise Manager you can just right click and go to Tasks and then Generate scripts and you are presented with a dialog box that allows you what objects you want to script. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Sunday, March 30, 2008 2:28 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Drop restore indexes John, Two options: 1. If your indexes are non-clustered the easiest way is: a) ALTER INDEX indexname ON tablename DISABLE - b) Do your appends - c) ALTER INDEX indexname ON tablename REBUILD. 2. If your indexes are clustered the first option is a no go, because disabling a clustered index will make the table inaccessible. Instead you can use SSMS to generate scripts for create and drop index, as pointed out by Arthur. In SSMS use Object Explorer to expand your table, expand Indexes, right-click an index and choose Script Index As -> Create / Drop. Repeat this for all indexes and all tables wanted. Then a) Run drop indexes scripts - b) Do your appends - c) Run create indexes scripts. For both options you can create a sproc for the DISABLE or DROP and another sproc for the REBUILD or CREATE on all wanted indexes on all wanted tables a once. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 30. marts 2008 19:20 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Drop restore indexes I am looking for a generic method to drop and then restore the indexes on a table. IOW, I have a bunch of tables that I have to do appends to, tens of millions of records. These tables may have dozens of indexes. I have always set up my indexes using the wizard so I don't have scripts already set up to create the indexes. I need to have some tool that will build scripts to recreate the indexes fond on a table and then remoce the indexes. Once the records are appended, I need to then run the scripts to rebuild all the saved index scripts. Is there such a tool? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 From ab-mi at post3.tele.dk Sun Mar 30 17:15:52 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Mon, 31 Mar 2008 00:15:52 +0200 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <20080330214731.PAMU5833.fep27.mail.dk@databaseadvisors.com> Message-ID: <000101c892b3$9e2d2860$2101a8c0@AB> Same in SSMS. In Enterprise Manager and in SSMS you can choose to script indexes for all tables in a db - BUT: your script will include CREATE TABLE as well - AND: it will also include an IF EXISTS MyDearTable THEN DROP MyDearTable before the script to create named dear table, so be careful to extract only the wanted parts of the script... Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af Eric Barro Sendt: 30. marts 2008 23:46 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] Drop restore indexes Yeah, see...using Enterprise Manager you can just right click and go to Tasks and then Generate scripts and you are presented with a dialog box that allows you what objects you want to script. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Sunday, March 30, 2008 2:28 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Drop restore indexes John, Two options: 1. If your indexes are non-clustered the easiest way is: a) ALTER INDEX indexname ON tablename DISABLE - b) Do your appends - c) ALTER INDEX indexname ON tablename REBUILD. 2. If your indexes are clustered the first option is a no go, because disabling a clustered index will make the table inaccessible. Instead you can use SSMS to generate scripts for create and drop index, as pointed out by Arthur. In SSMS use Object Explorer to expand your table, expand Indexes, right-click an index and choose Script Index As -> Create / Drop. Repeat this for all indexes and all tables wanted. Then a) Run drop indexes scripts - b) Do your appends - c) Run create indexes scripts. For both options you can create a sproc for the DISABLE or DROP and another sproc for the REBUILD or CREATE on all wanted indexes on all wanted tables a once. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 30. marts 2008 19:20 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Drop restore indexes I am looking for a generic method to drop and then restore the indexes on a table. IOW, I have a bunch of tables that I have to do appends to, tens of millions of records. These tables may have dozens of indexes. I have always set up my indexes using the wizard so I don't have scripts already set up to create the indexes. I need to have some tool that will build scripts to recreate the indexes fond on a table and then remoce the indexes. Once the records are appended, I need to then run the scripts to rebuild all the saved index scripts. Is there such a tool? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ 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 Sun Mar 30 19:56:14 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sun, 30 Mar 2008 20:56:14 -0400 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <000001c892ac$fe54ce20$2101a8c0@AB> References: <20080330172213.QHJC11715.fep26.mail.dk@databaseadvisors.com> <000001c892ac$fe54ce20$2101a8c0@AB> Message-ID: <001b01c892ca$05a94e90$0201a8c0@M90> Thanks, the Disable thing sounds like a good option. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Sunday, March 30, 2008 5:28 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Drop restore indexes John, Two options: 1. If your indexes are non-clustered the easiest way is: a) ALTER INDEX indexname ON tablename DISABLE - b) Do your appends - c) ALTER INDEX indexname ON tablename REBUILD. 2. If your indexes are clustered the first option is a no go, because disabling a clustered index will make the table inaccessible. Instead you can use SSMS to generate scripts for create and drop index, as pointed out by Arthur. In SSMS use Object Explorer to expand your table, expand Indexes, right-click an index and choose Script Index As -> Create / Drop. Repeat this for all indexes and all tables wanted. Then a) Run drop indexes scripts - b) Do your appends - c) Run create indexes scripts. For both options you can create a sproc for the DISABLE or DROP and another sproc for the REBUILD or CREATE on all wanted indexes on all wanted tables a once. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 30. marts 2008 19:20 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Drop restore indexes I am looking for a generic method to drop and then restore the indexes on a table. IOW, I have a bunch of tables that I have to do appends to, tens of millions of records. These tables may have dozens of indexes. I have always set up my indexes using the wizard so I don't have scripts already set up to create the indexes. I need to have some tool that will build scripts to recreate the indexes fond on a table and then remoce the indexes. Once the records are appended, I need to then run the scripts to rebuild all the saved index scripts. Is there such a tool? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 From ebarro at verizon.net Sun Mar 30 20:39:16 2008 From: ebarro at verizon.net (Eric Barro) Date: Sun, 30 Mar 2008 18:39:16 -0700 Subject: [dba-SQLServer] Drop restore indexes In-Reply-To: <000101c892b3$9e2d2860$2101a8c0@AB> Message-ID: <0JYK003P0N9I99D0@vms048.mailsrvcs.net> My bad...I found it in SSMS. Right clicking on the database name gives you the Tasks option on the context menu and Generate Scripts on the sub-menu. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Sunday, March 30, 2008 3:16 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Drop restore indexes Same in SSMS. In Enterprise Manager and in SSMS you can choose to script indexes for all tables in a db - BUT: your script will include CREATE TABLE as well - AND: it will also include an IF EXISTS MyDearTable THEN DROP MyDearTable before the script to create named dear table, so be careful to extract only the wanted parts of the script... Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af Eric Barro Sendt: 30. marts 2008 23:46 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] Drop restore indexes Yeah, see...using Enterprise Manager you can just right click and go to Tasks and then Generate scripts and you are presented with a dialog box that allows you what objects you want to script. -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Sunday, March 30, 2008 2:28 PM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] Drop restore indexes John, Two options: 1. If your indexes are non-clustered the easiest way is: a) ALTER INDEX indexname ON tablename DISABLE - b) Do your appends - c) ALTER INDEX indexname ON tablename REBUILD. 2. If your indexes are clustered the first option is a no go, because disabling a clustered index will make the table inaccessible. Instead you can use SSMS to generate scripts for create and drop index, as pointed out by Arthur. In SSMS use Object Explorer to expand your table, expand Indexes, right-click an index and choose Script Index As -> Create / Drop. Repeat this for all indexes and all tables wanted. Then a) Run drop indexes scripts - b) Do your appends - c) Run create indexes scripts. For both options you can create a sproc for the DISABLE or DROP and another sproc for the REBUILD or CREATE on all wanted indexes on all wanted tables a once. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 30. marts 2008 19:20 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] Drop restore indexes I am looking for a generic method to drop and then restore the indexes on a table. IOW, I have a bunch of tables that I have to do appends to, tens of millions of records. These tables may have dozens of indexes. I have always set up my indexes using the wizard so I don't have scripts already set up to create the indexes. I need to have some tool that will build scripts to recreate the indexes fond on a table and then remoce the indexes. Once the records are appended, I need to then run the scripts to rebuild all the saved index scripts. Is there such a tool? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ 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 From jwcolby at colbyconsulting.com Sun Mar 30 21:36:07 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Sun, 30 Mar 2008 22:36:07 -0400 Subject: [dba-SQLServer] To Drop or not to Drop, that is the question Message-ID: <001c01c892d7$fa073760$0201a8c0@M90> I have a largish database, currently 92 million records. I get an update with ~1 million records every week. At what point does dropping / rebuilding the indexes become more expensive than adding the records with the index in place? Is there a tool to predict such a thing? John W. Colby Colby Consulting www.ColbyConsulting.com From ab-mi at post3.tele.dk Mon Mar 31 03:51:52 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Mon, 31 Mar 2008 10:51:52 +0200 Subject: [dba-SQLServer] To Drop or not to Drop, that is the question In-Reply-To: <20080331023804.LYTK1539.fep24.mail.dk@databaseadvisors.com> Message-ID: <000001c8930c$777c61f0$2101a8c0@AB> Don't think you can *predict* it. But one way to *test* it is to run your updates from a query window in SSMS using Query | Include Client Statistics, which will give you an extra result-tab with informations such as "Total execution time". Another way is to use SQL Server Profiler. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 31. marts 2008 04:36 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] To Drop or not to Drop, that is the question I have a largish database, currently 92 million records. I get an update with ~1 million records every week. At what point does dropping / rebuilding the indexes become more expensive than adding the records with the index in place? Is there a tool to predict such a thing? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ab-mi at post3.tele.dk Mon Mar 31 05:23:41 2008 From: ab-mi at post3.tele.dk (Asger Blond) Date: Mon, 31 Mar 2008 12:23:41 +0200 Subject: [dba-SQLServer] To Drop or not to Drop, that is the question In-Reply-To: <20080331084817.UOZD10334.fep25.mail.dk@databaseadvisors.com> Message-ID: <000501c89319$4aca0c40$2101a8c0@AB> A small test inserting just 100000 rows in a table with one non-clustered index gave me this Client Statistics for Total Execution Time: Insert with Disable and Rebuild index: 2994 Insert with Drop and Create index: 3044 Insert with existing index active: 5547 No big difference between Disable/Rebuild and Drop/Create, but a huge difference between having and not having an active index (even with a small number of inserts and just a single index). Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af Asger Blond Sendt: 31. marts 2008 10:52 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] To Drop or not to Drop, that is the question Don't think you can *predict* it. But one way to *test* it is to run your updates from a query window in SSMS using Query | Include Client Statistics, which will give you an extra result-tab with informations such as "Total execution time". Another way is to use SQL Server Profiler. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 31. marts 2008 04:36 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] To Drop or not to Drop, that is the question I have a largish database, currently 92 million records. I get an update with ~1 million records every week. At what point does dropping / rebuilding the indexes become more expensive than adding the records with the index in place? Is there a tool to predict such a thing? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 From jwcolby at colbyconsulting.com Mon Mar 31 06:41:03 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 31 Mar 2008 07:41:03 -0400 Subject: [dba-SQLServer] To Drop or not to Drop, that is the question In-Reply-To: <000501c89319$4aca0c40$2101a8c0@AB> References: <20080331084817.UOZD10334.fep25.mail.dk@databaseadvisors.com> <000501c89319$4aca0c40$2101a8c0@AB> Message-ID: <002801c89324$19f63250$0201a8c0@M90> Yea, I figured I would likely just have to time it. The updates are not critical either, so I can gather perhaps 4 of them and do them at once. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Asger Blond Sent: Monday, March 31, 2008 6:24 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] To Drop or not to Drop, that is the question A small test inserting just 100000 rows in a table with one non-clustered index gave me this Client Statistics for Total Execution Time: Insert with Disable and Rebuild index: 2994 Insert with Drop and Create index: 3044 Insert with existing index active: 5547 No big difference between Disable/Rebuild and Drop/Create, but a huge difference between having and not having an active index (even with a small number of inserts and just a single index). Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af Asger Blond Sendt: 31. marts 2008 10:52 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] To Drop or not to Drop, that is the question Don't think you can *predict* it. But one way to *test* it is to run your updates from a query window in SSMS using Query | Include Client Statistics, which will give you an extra result-tab with informations such as "Total execution time". Another way is to use SQL Server Profiler. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jwcolby Sendt: 31. marts 2008 04:36 Til: 'Discussion concerning MS SQL Server' Emne: [dba-SQLServer] To Drop or not to Drop, that is the question I have a largish database, currently 92 million records. I get an update with ~1 million records every week. At what point does dropping / rebuilding the indexes become more expensive than adding the records with the index in place? Is there a tool to predict such a thing? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ 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 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Gustav at cactus.dk Mon Mar 31 08:33:59 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Mon, 31 Mar 2008 15:33:59 +0200 Subject: [dba-SQLServer] [dba-SQLserver] Article: LINQ and stored procedures Message-ID: Hi all And here is what looks like a clever (and free) tool for SQL freaks to get a jumpstart with LINQ in Visual Studio: http://www.linqpad.net/ Just download and run. Visual Studio is not(!) needed. A bunch of help and examples and several chapters from the book "C# in a nutshell" is included. /gustav >>> Gustav at cactus.dk 29-03-2008 10:59 >>> Hi all It looks like MS is thinking of Visual Studio as a major tool for controlling SQL Server. An interesting article by William Sheldon in SQL Server Magazine tells more, indeed about the SQLMetal tool: Microsoft Visual Studio 2008 and Language Integrated Query (LINQ) queries convert Visual Basic and C# code into T-SQL*based database calls, which are executed against SQL Server. Your Microsoft Visual Studio 2008 projects will need to target the Microsoft .NET Framework 3.5 to use LINQ. SQLMetal generates the necessary data entity and DataContext object as either a .vb or .cs source file. http://sqlmag-pwf.texterity.com/sqlmag/200804/ Pick article: LINQ to Your SQL Server Data A registration is needed but that is free. /gustav