Viewing 15 posts - 6,481 through 6,495 (of 7,619 total)
seshu67 (8/7/2012)
Can a table have two primary keys
Absolutely no, period. The fact that separate unique constraints can be defined does not make them primary keys as well.
Similarly, a table...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 12, 2013 at 12:31 pm
Stefan_G (8/9/2013)
Easy enough to change the WHERE on the date to an OR with the two specific date ranges.
If the @StartDate is the start of the current period -- which...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 9, 2013 at 3:16 pm
You can't do it as part of the restore. You could do it after it was restored, but it would involve some serious effort though.
Maybe you could instead restore...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 9, 2013 at 3:12 pm
SQL has a command to do that directly:
DBCC CHECKIDENT ( <table_name>, RESEED, <new_reseed_value> ) --WITH NO_INFOMSGS
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 9, 2013 at 3:08 pm
Hmm, interesting. SQL's still "dumber" than I thought :-).
We'll need to UNION the query results instead of using "OR".
Also, as always, we want the variable to be exactly the...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 9, 2013 at 12:24 pm
You might want to allow for no comma being in the string (just in case).
And you can remove some unnecessary elements from the code:
SELECT CAST(LEFT(@buyer, CHARINDEX(',', @buyer + ',') -...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 9, 2013 at 9:54 am
You don't need separate indexes on StartDateTime and EndDateTime, you need them in the same index.
SQL will only be able to do a seek on that index if it's headed...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 9, 2013 at 9:26 am
Stefan_G (8/9/2013)
I also get both years in a single SELECT to (try to) avoid double-reading of the tables.
Unfortunately your code will read all data for all invoices from 1 year...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 9, 2013 at 8:33 am
Here's my version of it. I delayed the lookup of CustomerName to avoid having to GROUP on it -- GROUP BY is an especially expensive operation on varchar columns.
I...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 8, 2013 at 4:14 pm
I had detached a SolarWinds database called NetPerfMon that consisted of three data (mdf) files and one log(ldf) file.
That might be the problem. Detaching a db in SQL...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 8, 2013 at 3:39 pm
I prefer a "template" approach. I find it much easier to write, follow and maintain. For example:
DECLARE @backupcommand_template varchar(8000)
DECLARE @backupcommand varchar(8000)
SET @backupcommand_template = '
BACKUP DATABASE [$db$]
TO DISK =...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 8, 2013 at 10:54 am
Do you really need only the TestId column in the result set? You don't all the columns?
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 7, 2013 at 4:06 pm
If you start a single transaction before the loop begins (or, more awkwardly, only on the first loop), then any rollback will rollback all activity for that transaction. If...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 7, 2013 at 3:59 pm
CTEs do not do that, from what I've seen looking at query plans. Instead, SQL re-runs the entire query every time you refer to the CTE.
For the most performance...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 7, 2013 at 1:36 pm
Yes, it's possible; I've done it several times. In fact, you don't even have to pass in the db name -- the proc will automatically run in the current...
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 7, 2013 at 1:31 pm
Viewing 15 posts - 6,481 through 6,495 (of 7,619 total)