|
Hi
how can Implementation
disributed database (in one computer(at sql 2008)/two server)؟?
Thanks
m.shamshirgaran@stu.semnaniau.ac.ir
|
|
|
|
|
2 things, do NOT put your email in a forum message, edit it out ASAP. If someone needs to get to you directly they can use the email option at the bottom of the posting.
Define what you mean by <code>distributed</code> you can install 2 instances of SQL server on the same machine this could simulate a distributed environment but you need to be more explicit.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have this SQL Server 2012 trivial stored procedure:
CREATE PROCEDURE usp_SelectCompany
AS
BEGIN
SET NOCOUNT ON
SELECT * FROM Company
END
and in a SSMS window, I execute this commands below to discover my SP is much slower than directly executing SELECT * from Company , even after the SP is run once to compile it.
SELECT * INTO #Company FROM Company WHERE 1=0
INSERT #Company EXEC usp_SelectCompany
PRINT 'Start Time: ' + cast(sysdatetime() as varchar)
INSERT #Company EXEC usp_SelectCompany
PRINT 'SP Time: ' + cast(sysdatetime() as varchar)
INSERT #Company SELECT * FROM Company
PRINT 'Select Time: ' + cast(sysdatetime() as varchar)
Here is the output:
(0 row(s) affected)
(127733 row(s) affected)
Start Time: 2013-05-22 11:56:57.7208741
(127733 row(s) affected)
SP Time: 2013-05-22 11:57:03.2067327
(127733 row(s) affected)
Select Time: 2013-05-22 11:57:04.0015524
I note that the SP executes in 5.4858586 seconds, and the direct "select" statement only takes 0.7948197 seconds, or about 7 times slower.
Can anyone explain this behavior?
|
|
|
|
|
Saxet wrote: Can anyone explain this behavior?
I can't, but a wild guess would be the optimizer (select and insert vs. insert and exec some proc).
What's the timing when you move the insert-statement inside the sproc?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It's better (1.0295934 seconds), but still slower than the select in the SSMS window.
Start Time: 2013-05-22 12:51:03.6580584
End Time: 2013-05-22 12:51:04.6876518
|
|
|
|
|
Saxet wrote: It's better (1.0295934 seconds), but still slower than the select in the SSMS window. The server has to do some things that can be skipped when being fed the statement directly, like looking up the access-rights to the sproc. So yes, compared to a simple query, it'd be a (small) bit slower.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm not entirely surprised, but the difference is probably not accurate. What you might try is simply using ExecuteReader from code on each and see how long it takes to do -- without reading the data.
I also wonder whether it's a local database or remote.
|
|
|
|
|
ExecuteReader performs about the same with either a select statement or a stored procedure. It appears to me that there is some penalty (lack of optimization?) when inserting the output from a stored procedure to a table that isn't present when inserting the output of a select statement.
SSMS produces a different "Actual Execution Plan" for the two, but I'm not skilled enough to understand what the differences mean. The execution plan breaks up the stored procedure into two queries, where the select statement is just one.
|
|
|
|
|
Right. About what I'd expect.
|
|
|
|
|
SQL Server can cache execution plans and results.
|
|
|
|
|
Hi,
I am using VS 2012 Free Edition (et al)
I am contemplating using this for the next version of 25 year old successfull software. We need to update various tables in a single transaction. This transaction needs to proceed in a step in which either All succeed, or None succeed. (resulting in a roll-back if any step failed) The database must deal with a high likelyhood that several terminals will at the same time try to write to the same entry in the same table. I handled this in MFC, with my own DB by giving each contentious item a serial-number, The first check for a modify-save would be if the serial number was still the same. if not, the item would be refused, and the transaction rolled back.
How does SQL handle this.
N.B.
The word 'Serial Number' seems to link to some add somewhere. Nothing to do with me! Just, Don't click it on my behalf.
Thankfully that link has disappeared since. TAKE NOTE IF IT HAPPENS TO YOU. The term 'Serial Number' turned into a link to some mobile phone sellers. Its gone now.
Bram van Kampen
|
|
|
|
|
Maybe I don't fully understand the problem, but SQL Server will handle "transactions" the same way. You declare the start of a transaction "Begin Transaction", do your stuff, then either "Commit" or "Rollback" the activity.
SQL server can automatically generate "serial" numbers for you. Look into the column data-type known as "Identity Column".
Did that answer your question?
|
|
|
|
|
Thanks,
I've since learned about the existence of 'Begin-End Transaction' Can you give me a link to a page explaining what it does and how it works?
Regards,#
Bram van Kampen
|
|
|
|
|
|
I have created a stored procedure which lists all customers that have 7 days left on their membership.
----------
create proc spGetMemReminder
as
select users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105)
-------
I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
|
|
|
|
|
|
Just use an insert:
CREATE PROCEDURE spGetMemReminder
AS
INSERT INTO YourTableNameHere (FullName, ExpiryDate)
SELECT users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where expiryDate = CAST(DATEADD(day, 7, getdate()) AS DATE
if expiryDate is a date column it is better to do date compare than to convert both sides.
|
|
|
|
|
|
Use an insert statement, that is not why I am posting a reply.
There are many ways to compare dates, comparing string (varchar) is probably the worst possible method. Do some research into the datetime object, you could have used datediff or dateadd neither of which require a convert.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hai.... You can do it by table varible.
create proc
spGetMemReminder
as
select users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105)
end
GO
CREATE PROCEDURE InsertMember
AS
BEGIN
SET NOCOUNT ON
DECLARE @TABLE TABLE(fullname nvarchar(10), expiryDate datetime)
insert into @TABLE
exec spGetMemReminder
insert into yourothertable
select * from @TABLE
SET NOCOUNT OFF
END
|
|
|
|
|
I think 'Insert into' query will help you
|
|
|
|
|
Hi All,
I have an SSIS package, which is trying to import data from a flat file in to a destination table in SQL. But the problem is not all columns in the destination table should come from flat file, there are few columns that should be filled from some other SQL Server source table.
Can we import data from a flat file and a table simultaneously into one table, is so how can we do that?
Please help me, its urgent. I am also searching but any help like code snippet, link or even a free advice is great.
Thanks in advance.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Change your strategy to ELT, import your data into a staging table that is an exact match for the source, all varchar columns!
The use a stored proc to transform the data into your final table. This method NEVER fails in the load process because of missing columns or date formats or a number has a $ sign.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Have a five.
Be excellent to each other. And... PARTY ON, DUDES!
Abraham Lincoln
|
|
|
|