Showing posts with label friends. Show all posts
Showing posts with label friends. Show all posts

Tuesday, March 20, 2012

Clarification on Joins

Dear friends,

Can any one clearly explain about all type of joins or any tutorials for that. please help me b'se i failed it to explain in an interview clearly

samy

Quote:

Originally Posted by samycbe

Dear friends,

Can any one clearly explain about all type of joins or any tutorials for that. please help me b'se i failed it to explain in an interview clearly

samy


These are SQL server specification.

Inner joins (the typical join operation, which uses some comparison operator like = or <>). These include equi-joins and natural joins.
Inner joins use a comparison operator to match rows from two tables based on the values in common columns from each table. For example, retrieving all rows where the student identification number is the same in both the students and courses tables.

Outer joins. Outer joins can be a left, a right, or full outer join.
Outer joins are specified with one of the following sets of keywords when they are specified in the FROM clause:

LEFT JOIN or LEFT OUTER JOIN
The result set of a left outer join includes all the rows from the left table specified in the LEFT OUTER clause, not just the ones in which the joined columns match. When a row in the left table has no matching rows in the right table, the associated result set row contains null values for all select list columns coming from the right table.

RIGHT JOIN or RIGHT OUTER JOIN.
A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table.

FULL JOIN or FULL OUTER JOIN.
A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables.

Cross joins.
Cross joins return all rows from the left table, each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.|||Thanks and Its really helpful

Saturday, February 25, 2012

checkpoint

Hi friends,
I came across the recommendation to do checkpoint to flush a buffer pool out
when doing massive modification in small chunks under simple recovery mode.
Can someone elaborate a bit more on it? Is it reasonable? And why?
Thanks a lot in advance.
AlexAlex,
This is my understanding...
When you execute a CHECKPOINT Statement it forces SQL Server to write
all dirty pages to Disk. (Dirty pages being Data/Log Pages that have
been modified but not written to Disk). Once the Checkpoint is issued
the Transaction Log is Truncated. SQL Server marks the transaction log
at the start of the active portion i.e Where there are still active
transactions. The rest of log is discarded as all transactions have
either had commit or rollback statement issued.
To be honest I can't really see the need to do this when you are using
Simple Recovery anyway - unless space is an issue. SQL Server issues
Checkpoint commands automatically, so the Log would return to the
minimum size anyway. I think SQL Server issues Checkpoint commands
every 10 mins - I think!
Hope this helps
Barry|||thanks Barry,
That was my understanding too, I just thought maybe I was missing
something,- such recommendation couldn't emerge out of nowhere, right?
Alex
"Barry" <barry.oconnor@.singers.co.im> wrote in message
news:1138908677.612627.55190@.g43g2000cwa.googlegroups.com...
> Alex,
> This is my understanding...
> When you execute a CHECKPOINT Statement it forces SQL Server to write
> all dirty pages to Disk. (Dirty pages being Data/Log Pages that have
> been modified but not written to Disk). Once the Checkpoint is issued
> the Transaction Log is Truncated. SQL Server marks the transaction log
> at the start of the active portion i.e Where there are still active
> transactions. The rest of log is discarded as all transactions have
> either had commit or rollback statement issued.
> To be honest I can't really see the need to do this when you are using
> Simple Recovery anyway - unless space is an issue. SQL Server issues
> Checkpoint commands automatically, so the Log would return to the
> minimum size anyway. I think SQL Server issues Checkpoint commands
> every 10 mins - I think!
> Hope this helps
> Barry
>|||Well, there's no harm in forcing checkpoints in between batches. I
think the recommendation comes from the problems around long running
transactions and large data modifications.
Even in SIMPLE recovery mode the transaction log can grow very large
when there is some long running transaction (thereby preventing the
checkpoint from occurring, because the server can't flush an open
transaction) and it's making lots of changes (thereby producing many log
records). By breaking up the single big transaction into many smaller
batches, that gives the server a chance to checkpoint in between batches
thereby keeping the transaction log under control (and not locking out
other users for long periods of time).
The server will do automatic checkpoints based on a formula (it's not
just every x seconds). It's different depending on the recovery mode.
In simple recovery mode the server will do an automatic checkpoint when
the log becomes 70% full or the number of log records is more than what
SQL Server estimates it can get through in the recovery interval period
(which ever comes sooner). So it's possible that the log is not quite
full enough to do an auto checkpoint at the time you start the next
batch. In which case the log will then continue to be filled and quite
possibly have to do an autogrow operation (at which time the 70% full
mark is even bigger). So there's no harm in doing a manual checkpoint
in between batches and possible benefit.
Personally, when I have to do this kind of stuff I always do manual
checkpoints between batches (although I do it mostly on DBs in full
recovery mode that have their logs backed up pretty regularly - like
every 15 minutes for example - so it's slightly different, but the same
concept).
*mike hodgson*
http://sqlnerd.blogspot.com
AlexM wrote:

>thanks Barry,
>That was my understanding too, I just thought maybe I was missing
>something,- such recommendation couldn't emerge out of nowhere, right?
>Alex
>
>"Barry" <barry.oconnor@.singers.co.im> wrote in message
>news:1138908677.612627.55190@.g43g2000cwa.googlegroups.com...
>
>
>|||I've had some discussions with Storage engine people at MS about this. I've
had cases where forcing
a checkpoint in simple recovery with *not* long running transaction seemed t
o increate re-use of the
log. But this shouldn't happen, and the person I spoke to would consider suc
h cases a bug. The way I
interpreted it: If we can provide a repro, and provide them with that, they
will have a look at it
and "fix" it.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Mike Hodgson" <e1minst3r@.gmail.com> wrote in message news:%23NPOQWGKGHA.668@.TK2MSFTNGP11.p
hx.gbl...
> Well, there's no harm in forcing checkpoints in between batches. I
> think the recommendation comes from the problems around long running
> transactions and large data modifications.
> Even in SIMPLE recovery mode the transaction log can grow very large
> when there is some long running transaction (thereby preventing the
> checkpoint from occurring, because the server can't flush an open
> transaction) and it's making lots of changes (thereby producing many log
> records). By breaking up the single big transaction into many smaller
> batches, that gives the server a chance to checkpoint in between batches
> thereby keeping the transaction log under control (and not locking out
> other users for long periods of time).
> The server will do automatic checkpoints based on a formula (it's not
> just every x seconds). It's different depending on the recovery mode.
> In simple recovery mode the server will do an automatic checkpoint when
> the log becomes 70% full or the number of log records is more than what
> SQL Server estimates it can get through in the recovery interval period
> (which ever comes sooner). So it's possible that the log is not quite
> full enough to do an auto checkpoint at the time you start the next
> batch. In which case the log will then continue to be filled and quite
> possibly have to do an autogrow operation (at which time the 70% full
> mark is even bigger). So there's no harm in doing a manual checkpoint
> in between batches and possible benefit.
> Personally, when I have to do this kind of stuff I always do manual
> checkpoints between batches (although I do it mostly on DBs in full
> recovery mode that have their logs backed up pretty regularly - like
> every 15 minutes for example - so it's slightly different, but the same
> concept).
> --
> *mike hodgson*
> http://sqlnerd.blogspot.com
>
> AlexM wrote:
>
>|||TIbor, Mike - Thanks for additional comments - further info is always
helpful.
Barry|||>> Even in SIMPLE recovery mode the transaction log can grow very large when
there is some long running transaction (thereby preventing the checkpoint f
rom occurring, because the server can't flush an open transaction)<<
I'm not sure exactly what you mean saying SQL Server can't flush an open tra
nsaction. It's true that the log space can't be reused, but that has nothing
to do with checkpoint. Checkpoint happens at regular intervals, as you sugg
est, but it will write ALL dirty pages to disk, even those that are part of
an uncommitted transaction.
The log space can't be reused, so the log can grow quite large, but the chec
kpoints DO occur.
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"Mike Hodgson" <e1minst3r@.gmail.com> wrote in message news:%23NPOQWGKGHA.668
@.TK2MSFTNGP11.phx.gbl...
Well, there's no harm in forcing checkpoints in between batches. I think th
e recommendation comes from the problems around long running transactions an
d large data modifications.
Even in SIMPLE recovery mode the transaction log can grow very large when th
ere is some long running transaction (thereby preventing the checkpoint from
occurring, because the server can't flush an open transaction) and it's mak
ing lots of changes (thereby producing many log records). By breaking up th
e single big transaction into many smaller batches, that gives the server a
chance to checkpoint in between batches thereby keeping the transaction log
under control (and not locking out other users for long periods of time).
The server will do automatic checkpoints based on a formula (it's not just e
very x seconds). It's different depending on the recovery mode. In simple
recovery mode the server will do an automatic checkpoint when the log become
s 70% full or the number of log records is more than what SQL Server estimat
es it can get through in the recovery interval period (which ever comes soon
er). So it's possible that the log is not quite full enough to do an auto c
heckpoint at the time you start the next batch. In which case the log will
then continue to be filled and quite possibly have to do an autogrow operati
on (at which time the 70% full mark is even bigger). So there's no harm in
doing a manual checkpoint in between batches and possible benefit.
Personally, when I have to do this kind of stuff I always do manual checkpoi
nts between batches (although I do it mostly on DBs in full recovery mode th
at have their logs backed up pretty regularly - like every 15 minutes for ex
ample - so it's slightly different, but the same concept).
mike hodgson
http://sqlnerd.blogspot.com
AlexM wrote:
thanks Barry,
That was my understanding too, I just thought maybe I was missing
something,- such recommendation couldn't emerge out of nowhere, right?
Alex
"Barry" <barry.oconnor@.singers.co.im> wrote in message
news:1138908677.612627.55190@.g43g2000cwa.googlegroups.com...
Alex,
This is my understanding...
When you execute a CHECKPOINT Statement it forces SQL Server to write
all dirty pages to Disk. (Dirty pages being Data/Log Pages that have
been modified but not written to Disk). Once the Checkpoint is issued
the Transaction Log is Truncated. SQL Server marks the transaction log
at the start of the active portion i.e Where there are still active
transactions. The rest of log is discarded as all transactions have
either had commit or rollback statement issued.
To be honest I can't really see the need to do this when you are using
Simple Recovery anyway - unless space is an issue. SQL Server issues
Checkpoint commands automatically, so the Log would return to the
minimum size anyway. I think SQL Server issues Checkpoint commands
every 10 mins - I think!
Hope this helps
Barry|||Sorry, I shouldn't have used the term "flush". My bad - mixing terminology.
I guess where I was coming from was, and it may since have changed so
I'm prepared to admit I'm wrong, in the old days (with SQL 6.5 and
earlier from memory) the simple recovery model was implemented with the
"trunc. log on checkpoint" dboption (and also depended on the value of
the "bcp/bulk insert" option too). So I was thinking that in simple
recovery mode with SQL 2000 the checkpoint truncates up to the minimum
recovery LSN, but in this case the earliest open transaction represents
the minimum recovery LSN and hence the log cannot be truncated past that
point until those open transactions are complete. (In fact, I just
found the BOL page
<http://msdn.microsoft.com/library/e...ar_da2_8y3y.asp>
that confirms the checkpoint process is responsible for truncating log
records before the MinLSN when the DB is in SIMPLE recovery mode and it
also confirms what I'm trying to say in the "Long-Running Transaction"
section.) And so, while the checkpoint still occurs and flushes all
dirty pages from memory to disk, as far as the size of the physical log
goes, the checkpoint effectively does nothing. I wasn't focused on
memory to disk operations but rather on log truncation operations.
I stand corrected in saying the checkpoint doesn't occur. My point was
that the open transaction would prevent the log from getting truncated
and therefore increased the likelihood of the log needing an autogrow
operation, but you're right (as always) - the checkpoint still occurs.
(I guess I really should have said "thereby preventing the checkpoint
from /truncating the physical log/, because the server can't /truncate
the log record associated with/ an open transaction".)
*mike hodgson*
http://sqlnerd.blogspot.com
Kalen Delaney wrote:
> large when there is some long running transaction (thereby preventing
> the checkpoint from occurring, because the server can't flush an open
> transaction)<<
> I'm not sure exactly what you mean saying SQL Server can't flush an
> open transaction. It's true that the log space can't be reused, but
> that has nothing to do with checkpoint. Checkpoint happens at regular
> intervals, as you suggest, but it will write ALL dirty pages to disk,
> even those that are part of an uncommitted transaction.
> The log space can't be reused, so the log can grow quite large, but
> the checkpoints DO occur.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.solidqualitylearning.com <http://www.solidqualitylearning.com>
>
> "Mike Hodgson" <e1minst3r@.gmail.com <mailto:e1minst3r@.gmail.com>>
> wrote in message news:%23NPOQWGKGHA.668@.TK2MSFTNGP11.phx.gbl...
> Well, there's no harm in forcing checkpoints in between batches.
> I think the recommendation comes from the problems around long
> running transactions and large data modifications.
> Even in SIMPLE recovery mode the transaction log can grow very
> large when there is some long running transaction (thereby
> preventing the checkpoint from occurring, because the server can't
> flush an open transaction) and it's making lots of changes
> (thereby producing many log records). By breaking up the single
> big transaction into many smaller batches, that gives the server a
> chance to checkpoint in between batches thereby keeping the
> transaction log under control (and not locking out other users for
> long periods of time).
> The server will do automatic checkpoints based on a formula (it's
> not just every x seconds). It's different depending on the
> recovery mode. In simple recovery mode the server will do an
> automatic checkpoint when the log becomes 70% full or the number
> of log records is more than what SQL Server estimates it can get
> through in the recovery interval period (which ever comes
> sooner). So it's possible that the log is not quite full enough
> to do an auto checkpoint at the time you start the next batch. In
> which case the log will then continue to be filled and quite
> possibly have to do an autogrow operation (at which time the 70%
> full mark is even bigger). So there's no harm in doing a manual
> checkpoint in between batches and possible benefit.
> Personally, when I have to do this kind of stuff I always do
> manual checkpoints between batches (although I do it mostly on DBs
> in full recovery mode that have their logs backed up pretty
> regularly - like every 15 minutes for example - so it's slightly
> different, but the same concept).
> --
> *mike hodgson*
> http://sqlnerd.blogspot.com
>
> AlexM wrote:
>

Thursday, February 16, 2012

checking for file existence within an udf

hi ng,
hi friends,
i've a problem within an udf to find out wheter a file or a path exists or
not. unc pathes and wildcards have to be supported.
i've already checked the following solutions:
- exec master..xp_fileexist @.filename, @.file_exists=@.exists output
=> wildcards are not supported
=> pathes can't be checked
- exec master..sp_MSget_file_existence @.filename,@.exists=@.exists output
=> no extended stored procedure but works perfect in tsql
=> stored procedures can't be used in udfs
- exec master..xp_cmdshell @.command
=> no reuseable output value
maybe someone can help me.
thanks
dengo
-- hope you'll understand my englishxp_cmdshell *does* return a usable output value. Try this:
declare @.i as integer
exec @.i = master..xp_cmdshell 'dir c:\config.* /b'
print @.i
If @.i = 0 then the command executed successfully and one or more matching
files were found. If @.i <> 0, then no file was found or there was an error,
as might be the case here:
declare @.i as integer
exec @.i = master..xp_cmdshell 'dir c:\config.zzzz* /b'
print @.i
"Robert Denkmayr" <RobertDenkmayr@.discussions.microsoft.com> wrote in
message news:0D9C2CCD-B335-479C-B10B-E944D34A74FF@.microsoft.com...
> hi ng,
> hi friends,
> i've a problem within an udf to find out wheter a file or a path exists or
> not. unc pathes and wildcards have to be supported.
> i've already checked the following solutions:
> - exec master..xp_fileexist @.filename, @.file_exists=@.exists output
> => wildcards are not supported
> => pathes can't be checked
> - exec master..sp_MSget_file_existence @.filename,@.exists=@.exists output
> => no extended stored procedure but works perfect in tsql
> => stored procedures can't be used in udfs
> - exec master..xp_cmdshell @.command
> => no reuseable output value
> maybe someone can help me.
> thanks
> dengo
> -- hope you'll understand my english|||hi michael,
thanks for your reply.
you're right but your reply is my answer - see returncode on errors.
additional a remark from <sp_MSget_file_existence>.
/*
** The return code from xp_cmdshell is not a reliable way to check whether
** the file exists or not. It is always 0 on Win95 as long as xp_cmdshell
succeeds.
*/
another weak spot is that you need an other command for checking the
existence of a path.
dengo
"Michael C#" wrote:

> xp_cmdshell *does* return a usable output value. Try this:
> declare @.i as integer
> exec @.i = master..xp_cmdshell 'dir c:\config.* /b'
> print @.i
> If @.i = 0 then the command executed successfully and one or more matching
> files were found. If @.i <> 0, then no file was found or there was an erro
r,
> as might be the case here:
> declare @.i as integer
> exec @.i = master..xp_cmdshell 'dir c:\config.zzzz* /b'
> print @.i
> "Robert Denkmayr" <RobertDenkmayr@.discussions.microsoft.com> wrote in
> message news:0D9C2CCD-B335-479C-B10B-E944D34A74FF@.microsoft.com...
>
>|||Ahhh you're using Win95 are ya? Wowsa.
I haven't done anything on Win95 with this, but if you have a Win95 box
handy, you might try it out and see if it counts a "No Files Found" error as
a success or not. I have used this method on Win2K, XP Pro and 2003 Server
with no issues.
You might check out xp_dirtree or xp_subdirs for paths. I'd think you'd
need some sort of custom solution if you want to return two separate codes -
one for the existence of a path, and one for the existence of a file.
"Robert Denkmayr" <RobertDenkmayr@.discussions.microsoft.com> wrote in
message news:5E0B835F-FCD7-4770-9C08-B84922D5F8C1@.microsoft.com...
> hi michael,
> thanks for your reply.
> you're right but your reply is my answer - see returncode on errors.
> additional a remark from <sp_MSget_file_existence>.
> /*
> ** The return code from xp_cmdshell is not a reliable way to check whether
> ** the file exists or not. It is always 0 on Win95 as long as xp_cmdshell
> succeeds.
> */
> another weak spot is that you need an other command for checking the
> existence of a path.
> dengo
>
> "Michael C#" wrote:
>|||no i'm not using win95.
for the first time the udf will be used by dts packages on w2k server where
dynamic filename assignment is necessary to avoid overwriting existing files
or using prior created paths. that's why i need a reliable solution.
at the moment i'll implement 'xp_cmdshell' with the appropriate command
either for a filename or a path.
because i'm not familiar with programming in c/c++ the most preferred
solution would be a dll for an extended stored procedure like the
'xpstar.dll' which contains the function for 'xp_fileexists'.
another step would be the sourcecode of 'xpstar.dll' so i could extract the
necessary code for a new dll with the new function.
"Michael C#" wrote:

> Ahhh you're using Win95 are ya? Wowsa.
> I haven't done anything on Win95 with this, but if you have a Win95 box
> handy, you might try it out and see if it counts a "No Files Found" error
as
> a success or not. I have used this method on Win2K, XP Pro and 2003 Serve
r
> with no issues.
> You might check out xp_dirtree or xp_subdirs for paths. I'd think you'd
> need some sort of custom solution if you want to return two separate codes
-
> one for the existence of a path, and one for the existence of a file.
>|||If you're interested in creating your own XP's, here's an article on the
subject: http://www.codeproject.com/database/extended_sp.asp.
You could also look at generating a filename and path using GetDate() and a
random #, and/or a counter value stored in a table which you could increment
each time a new file is created. Not sure of the specifics of your
application, but those are a couple ideas which might work in some
circumstances.
"Robert Denkmayr" <RobertDenkmayr@.discussions.microsoft.com> wrote in
message news:CCD5EF04-52E8-42BA-A9F3-472986C53A6A@.microsoft.com...
> no i'm not using win95.
> for the first time the udf will be used by dts packages on w2k server
> where
> dynamic filename assignment is necessary to avoid overwriting existing
> files
> or using prior created paths. that's why i need a reliable solution.
> at the moment i'll implement 'xp_cmdshell' with the appropriate command
> either for a filename or a path.
> because i'm not familiar with programming in c/c++ the most preferred
> solution would be a dll for an extended stored procedure like the
> 'xpstar.dll' which contains the function for 'xp_fileexists'.
> another step would be the sourcecode of 'xpstar.dll' so i could extract
> the
> necessary code for a new dll with the new function.
>
> "Michael C#" wrote:
>|||i had the same ideas as you can see in a sample of the first implementation
below:
'p2lgb_%y%m%d_%n.txt' ... data file
'p2lgb_%y%m%d_%n.err' ... error file
'\\dfs.dom\dfs\sem' ... interface path
'\\dfs.dom\dfs\archiv\sem\%y' ... archiv path
%y=year, %m=month, %d=day ... using getdate()
%n=unique number ... counter value stored in a table
the problem in this implementation is the unique number. i can't be sure
that the next
number isn't used manually by an user or it's already used in the archiv
directory => check for file existence.
at the new (second) implementation i should check both the interface and
archiv paths for the first unused number (starting at 1) => check for file
existence.
i'll examine the article about writing xp's tomorrow because i'm from
austria and it's already 11:15 pm.
thanks and good night
dengo
"Michael C#" wrote:

> If you're interested in creating your own XP's, here's an article on the
> subject: http://www.codeproject.com/database/extended_sp.asp.
> You could also look at generating a filename and path using GetDate() and
a
> random #, and/or a counter value stored in a table which you could increme
nt
> each time a new file is created. Not sure of the specifics of your
> application, but those are a couple ideas which might work in some
> circumstances.
>