August 12, 2010 at 7:44 am
Brandie Tarvin (8/12/2010)
Kwit larnin' things! That ain't what this here site be for!😀
Well not this thread anyway 🙂
Unless you count accent and bacon preferences.
August 12, 2010 at 7:45 am
Brandie Tarvin (8/12/2010)
Are you saying you can't give the PK & Unique constraints names on a table variable or names at all?
The first.
On a real table, you can use either of these syntaxes
CREATE TABLE #tmp (
Col1 int,
Col2 datetime,
Filler Char(50),
Constraint pk_temp Primary Key Clustered (Col1, Col2) -- explicitly named
)
Or
CREATE TABLE #tmp (
Col1 int,
Col2 datetime,
Filler Char(50),
Primary Key Clustered (Col1, Col2) -- SQL generates name
)
But with a table variable only the second is allowed. The first throws an error 'Incorrect syntax near the keyword 'CONSTRAINT'.'
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 12, 2010 at 7:47 am
jcrawf02 (8/12/2010)
Jack Corbett (8/12/2010)
My kids start school today. I can't believe how early school starts in FL. We are starting earlier than most other schools, but still, it is only August 12th. What happened to starting around Labor Day?You gotta start early...
...cause of all the snow days...
...couldn't help myself :hehe:
Not snow days...Hurricane Days, and I am not kidding, they are part of the school schedule down here.
When I went to school in Maine the school district I attended added 5 days to the school year to cover snow days and fro every snow day not used we got of school earlier. That was nice, because you either got "extra" days off during the year or got out earlier than scheduled.
Even then we started no earlier than the Wednesday before Labor day and always out by the second week in June. It seems that there are more teacher workdays and such now so that there are more student breaks during the year, but a shorter summer.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
August 12, 2010 at 7:57 am
Jack Corbett (8/12/2010)
jcrawf02 (8/12/2010)
Jack Corbett (8/12/2010)
My kids start school today. I can't believe how early school starts in FL. We are starting earlier than most other schools, but still, it is only August 12th. What happened to starting around Labor Day?You gotta start early...
...cause of all the snow days...
...couldn't help myself :hehe:
Not snow days...Hurricane Days, and I am not kidding, they are part of the school schedule down here.
When I went to school in Maine the school district I attended added 5 days to the school year to cover snow days and fro every snow day not used we got of school earlier. That was nice, because you either got "extra" days off during the year or got out earlier than scheduled.
Even then we started no earlier than the Wednesday before Labor day and always out by the second week in June. It seems that there are more teacher workdays and such now so that there are more student breaks during the year, but a shorter summer.
Agreed, too many teacher work days or in-service days. Break up the training and bring in substitutes for the teachers out for training. You can't teach the kids if they aren't in class.
And I seem to remember Parent/Teacher Conferences being scheduled in the evenings when I was in elementary school.
August 12, 2010 at 8:04 am
Brandie Tarvin (8/12/2010)
Back on topic, someone decided to post a request for T-SQL problem solution in the commentary of the new article I wrote. Did the whole "Here's my problem. Solve it and I'll give you credit for it." bit.Is this a one time thing or a growing trend?
At least they offered to give you credit...
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 12, 2010 at 8:20 am
Brandie Tarvin (8/12/2010)
Paul White NZ (8/12/2010)
Dave Ballantyne (8/12/2010)
So if you want to use an index you generally have to use a hint.What sort of hint did you have in mind? Index hints don't work with table variables, and you can't give the PRIMARY KEY or UNIQUE constraints names anyway!
Are you saying you can't give the PK & Unique constraints names on a table variable or names at all? It's been a while (so I'd have to look up the code), but I'm pretty sure I've given both constraints names on temp tables and user tables before.
Just table variables. You can name constraints on # and ## temporary tables, but it is a pretty bad idea.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
August 12, 2010 at 8:23 am
Brandie Tarvin (8/12/2010)
Back on topic, someone decided to post a request for T-SQL problem solution in the commentary of the new article I wrote. Did the whole "Here's my problem. Solve it and I'll give you credit for it." bit.Is this a one time thing or a growing trend?
It looks almost like a homework assignment.
--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
August 12, 2010 at 8:23 am
Gail & Paul, that's for the clarification.
August 12, 2010 at 8:44 am
In case any of you threadizens are available or interested
Grant will be presenting to my UG tonight. You can start joining the livemeeting at 6PM PST.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
August 12, 2010 at 8:45 am
cant stop my laugh.... when I read the first article in this post that people submitting the query like anything....
and then last update we still helping people.....
I think we should accept all queries whatever get submitted(obviously related to DBAs but do we need to reply or not, depends on individual.
----------
Ashish
August 12, 2010 at 8:48 am
Paul White NZ (8/12/2010)
You can name constraints on # and ## temporary tables, but it is a pretty bad idea.
I haven't had a need to do this (or even consider it yet) but wondering what makes it a "bad idea"? Thanks in advance for the knowledge share.
David
@SQLTentmaker“He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot
August 12, 2010 at 8:52 am
CirquedeSQLeil (8/12/2010)
In case any of you threadizens are available or interestedGrant will be presenting to my UG tonight. You can start joining the livemeeting at 6PM PST.
I'd love to join you online, but we'll be wrapping up our meeting when yours starts.
Are you recording the presentation?
P.S. If you're in the Memphis area tonight, come join us for:
Dan Evans - Creating an EPM Environment Using Microsoft SQL Server 2008 R2 and SharePoint 2010
Check our humble website for more details: http://Mem-PASS.org
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
August 12, 2010 at 9:41 am
David Benoit (8/12/2010)
Paul White NZ (8/12/2010)
You can name constraints on # and ## temporary tables, but it is a pretty bad idea.I haven't had a need to do this (or even consider it yet) but wondering what makes it a "bad idea"? Thanks in advance for the knowledge share.
A constraint name is scoped to the database, but # and ## tables are all created in the same database: tempdb.
Because # and ## tables can be created independently on more than one connection, this can lead to a name collision.
Try running the following code from two separate connections to the same server:
CREATE TABLE #temp (a INTEGER NOT NULL CONSTRAINT pk_temp PRIMARY KEY);
You'll get an error on the second connection:
.Net SqlClient Data Provider: Msg 2714, Level 16, State 4, Line 1
There is already an object named 'pk_temp' in the database.
.Net SqlClient Data Provider: Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
August 12, 2010 at 9:46 am
GilaMonster (8/12/2010)
Dave Ballantyne (8/12/2010)
Remember that the optimizer uses statistics to decide to use an index. Table variables have none, it is assumed that they will have 1 row. So if you want to use an index you generally have to use a hint.Unless the index is covering, in which case it will be used without a hint.
In case anyone would like to see a plan with a table variable using a non-clustered index + bookmark lookup without a hint:
DECLARE @a
TABLE (
row_id INTEGER IDENTITY PRIMARY KEY,
data INTEGER NOT NULL UNIQUE,
padding CHAR(1000) NOT NULL DEFAULT ''
);
DECLARE @b-2
TABLE (
row_id INTEGER IDENTITY PRIMARY KEY,
data INTEGER NOT NULL UNIQUE,
padding CHAR(1000) NOT NULL DEFAULT ''
);
INSERT @a (data) SELECT ROW_NUMBER() OVER (ORDER BY A.allocation_unit_id) FROM master.sys.allocation_units A;
INSERT @b-2 (data) SELECT data FROM @a;
SELECT A.data, B.padding, A.padding
FROM @a A
JOIN @b-2 B
ON B.data = A.data;
Plan:
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
August 12, 2010 at 9:50 am
Paul White NZ (8/12/2010)
David Benoit (8/12/2010)
Paul White NZ (8/12/2010)
You can name constraints on # and ## temporary tables, but it is a pretty bad idea.I haven't had a need to do this (or even consider it yet) but wondering what makes it a "bad idea"? Thanks in advance for the knowledge share.
A constraint name is scoped to the database, but # and ## tables are all created in the same database: tempdb.
Because # and ## tables can be created independently on more than one connection, this can lead to a name collision.
Try running the following code from two separate connections to the same server:
CREATE TABLE #temp (a INTEGER NOT NULL CONSTRAINT pk_temp PRIMARY KEY);
You'll get an error on the second connection:
.Net SqlClient Data Provider: Msg 2714, Level 16, State 4, Line 1
There is already an object named 'pk_temp' in the database.
.Net SqlClient Data Provider: Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
:blush: Funny, wasn't even considering it from that perspective. I was thinking there was some performance implication but you're right, that would be a bit of a problem.
David
@SQLTentmaker“He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot
Viewing 15 posts - 17,416 through 17,430 (of 66,712 total)
You must be logged in to reply to this topic. Login to reply