Showing posts with label excuse. Show all posts
Showing posts with label excuse. Show all posts

Wednesday, March 21, 2012

Replace existing table

Hi. I am new to SQL Server so please excuse me if my question is stupid or asked in the wrong place.

I am replicating a number of Visual FoxPro tables in SQL Server. The tables are updated daily. I have got several of them replicated fine through using BULK INSERT to load the existing data and INSERT/UPDATE/DELETE to replicate the daily updates.

However, one of the Visual FoxPro tables is re-created from scratch each day. I could do the same in SQL Server but I would like users to have uninterrupted access to it (i.e. I do not want a query to fail while I am deleting and then re-upsizing the table).

One method that occurs to me would be to upsize the table under a different temporary name and then BEGIN TRANSACTION, delete the old table, rename the new table to the old table and then COMMIT TRANSACTION. Would this work? And is there a better way of doing this?

Many thanks

Dom

I know the users have to go to lunch daily..., so announce a lunch break at 1 pm for all the people and do what to do; if your users don't want to leave do it after they go home.

Sure ,before take a full backup if you have time.

|||Thanks ggciubuc, but I'm afraid thats not an option. The update needs to be done as early as possible (but no earlier than 8am) so it cannot wait until the users have gone home, but it will not be at a consistent time of day because the start time depends on the time taken to complete a number of prior processes.|||

Make a Integration Services package , put it in a job that runs before 8 a.m (eg. 6 a.m); the package can contain:

1.a task that delete the SQL table

2. a task that re-create the SQL table

3. a task with bulk insert

with workflow you can prioritize the processes|||

Thanks Gigi - I have not come across Integration Services before, I will check it out.

However, as stated above, it cannot run earlier than 8am (typically it will run at some point around 10am but some days it may not be until 1pm or later) and I would like to avoid disrupting users if possible.

|||

I recommend to use your proposed solution (with minor change) for this task & (it may be done on the SSIS Package or DTS package), but your approach seems to be good enough to fit for your requirement.

1. Create a table on different temp name (not temp table -- #)

2. Do the manipulation on created table

3. On single transaction, Delete the existing row, insert from created table, drop the created table.

|||

Many thanks Manivannan, I'll give it a go. Deleting all of the the existing rows and then inserting the new records makes much more sense, I guess.

Could I even use a BULK INSERT to append the records (does BULK INSERT work inside a transaction?) and avoid creating the temporary table altogether?

|||

You can use the BULK INSERT on explicit(user) transaction. It can be roll backed also. J

Saturday, February 25, 2012

reordering in paralellism-multiprocessor machine

Excuse me if this is a double post!
Consider these queries:
1) select C,D,E,F from T where (A - B) >= 0
2) select C,D,E,F from T where B >= 0 and B <10
3) select * from T where (A - B) >= 0
4) select * from T where B >= 0 and B <10
Description of the table 'T':
256 columns
No identity column defined on T
columns Z,Y,X have nonclustered on PRIMARY
column C, being the primary key column , has the index: clustered, unique,
primary key located on PRIMARY
A is of type int and B is of type decimal.
No. of rows in the table: 100406
Process followed for replication: run these queries in a MULTI PROCESSOR
machine. See the execution plan.
Issue:
Queries 1, 3, 4 execute by the serial plan, whereas query 2 executes by
parallel plan. Still worse, the order in which the records are returned are
not the same each time query 2 is run. When tried with the hint option
(MAXDOP 1), the query 2 executes in serial mode, without re-arrangement. Need
an answer for the rearrangement of the rows resulting in case of query 2.This has been discussed ad-nauseum. The order of returned rows is never
guaranteed unless the query includes an order by clause.
"Saravana" <Saravana@.discussions.microsoft.com> wrote in message
news:6B76B67A-AD98-415D-8296-9619039A7377@.microsoft.com...
> Excuse me if this is a double post!
> Consider these queries:
> 1) select C,D,E,F from T where (A - B) >= 0
> 2) select C,D,E,F from T where B >= 0 and B <10
> 3) select * from T where (A - B) >= 0
> 4) select * from T where B >= 0 and B <10
> Description of the table 'T':
> 256 columns
> No identity column defined on T
> columns Z,Y,X have nonclustered on PRIMARY
> column C, being the primary key column , has the index: clustered, unique,
> primary key located on PRIMARY
> A is of type int and B is of type decimal.
> No. of rows in the table: 100406
> Process followed for replication: run these queries in a MULTI PROCESSOR
> machine. See the execution plan.
> Issue:
> Queries 1, 3, 4 execute by the serial plan, whereas query 2 executes
by
> parallel plan. Still worse, the order in which the records are returned
are
> not the same each time query 2 is run. When tried with the hint option
> (MAXDOP 1), the query 2 executes in serial mode, without re-arrangement.
Need
> an answer for the rearrangement of the rows resulting in case of query 2.
>|||Scott,
Isn't there any other way of stopping this reordering: tweaking of the
tables, or the columns..
In other words: what is the exact quantitative statistic that is considered
by the server for executing a query paralelly or serially.. i came to know
about execution costs, but i am not able to get any useful information from
the execution plans from the query anaylzer. What i am more concerned is that
query 2 is re-ordered whereas query 1 is ordered...
Thanks.
"Scott Morris" wrote:
> This has been discussed ad-nauseum. The order of returned rows is never
> guaranteed unless the query includes an order by clause.
>|||As I said - no order by clause, no guarantee. There is a thread in
.progamming with the subject "order by and identity" that was active
yesterday. You might find the discussion interesting as it deals with the
same basic issue. You can search the newsgroups for discussions / rants on
this FAQ.
"Saravana" <Saravana@.discussions.microsoft.com> wrote in message
news:0FD75B28-2543-4128-8F6F-E888F5110751@.microsoft.com...
> Scott,
> Isn't there any other way of stopping this reordering: tweaking of the
> tables, or the columns..
> In other words: what is the exact quantitative statistic that is
considered
> by the server for executing a query paralelly or serially.. i came to know
> about execution costs, but i am not able to get any useful information
from
> the execution plans from the query anaylzer. What i am more concerned is
that
> query 2 is re-ordered whereas query 1 is ordered...
> Thanks.
> "Scott Morris" wrote:
> > This has been discussed ad-nauseum. The order of returned rows is never
> > guaranteed unless the query includes an order by clause.
> >
>|||Scott is 100% correct. If you want a specific order to be guaranteed for
the returned data you MUST specify an order by clause, period, end of story.
--
Andrew J. Kelly SQL MVP
"Saravana" <Saravana@.discussions.microsoft.com> wrote in message
news:0FD75B28-2543-4128-8F6F-E888F5110751@.microsoft.com...
> Scott,
> Isn't there any other way of stopping this reordering: tweaking of the
> tables, or the columns..
> In other words: what is the exact quantitative statistic that is
> considered
> by the server for executing a query paralelly or serially.. i came to know
> about execution costs, but i am not able to get any useful information
> from
> the execution plans from the query anaylzer. What i am more concerned is
> that
> query 2 is re-ordered whereas query 1 is ordered...
> Thanks.
> "Scott Morris" wrote:
>> This has been discussed ad-nauseum. The order of returned rows is never
>> guaranteed unless the query includes an order by clause.
>

reordering in paralellism-multiprocessor machine

Excuse me if this is a double post!
Consider these queries:
1) select C,D,E,F from T where (A - B) >= 0
2) select C,D,E,F from T where B >= 0 and B <10
3) select * from T where (A - B) >= 0
4) select * from T where B >= 0 and B <10
Description of the table 'T':
256 columns
No identity column defined on T
columns Z,Y,X have nonclustered on PRIMARY
column C, being the primary key column , has the index: clustered, unique,
primary key located on PRIMARY
A is of type int and B is of type decimal.
No. of rows in the table: 100406
Process followed for replication: run these queries in a MULTI PROCESSOR
machine. See the execution plan.
Issue:
Queries 1, 3, 4 execute by the serial plan, whereas query 2 executes by
parallel plan. Still worse, the order in which the records are returned are
not the same each time query 2 is run. When tried with the hint option
(MAXDOP 1), the query 2 executes in serial mode, without re-arrangement. Need
an answer for the rearrangement of the rows resulting in case of query 2.
This has been discussed ad-nauseum. The order of returned rows is never
guaranteed unless the query includes an order by clause.
"Saravana" <Saravana@.discussions.microsoft.com> wrote in message
news:6B76B67A-AD98-415D-8296-9619039A7377@.microsoft.com...
> Excuse me if this is a double post!
> Consider these queries:
> 1) select C,D,E,F from T where (A - B) >= 0
> 2) select C,D,E,F from T where B >= 0 and B <10
> 3) select * from T where (A - B) >= 0
> 4) select * from T where B >= 0 and B <10
> Description of the table 'T':
> 256 columns
> No identity column defined on T
> columns Z,Y,X have nonclustered on PRIMARY
> column C, being the primary key column , has the index: clustered, unique,
> primary key located on PRIMARY
> A is of type int and B is of type decimal.
> No. of rows in the table: 100406
> Process followed for replication: run these queries in a MULTI PROCESSOR
> machine. See the execution plan.
> Issue:
> Queries 1, 3, 4 execute by the serial plan, whereas query 2 executes
by
> parallel plan. Still worse, the order in which the records are returned
are
> not the same each time query 2 is run. When tried with the hint option
> (MAXDOP 1), the query 2 executes in serial mode, without re-arrangement.
Need
> an answer for the rearrangement of the rows resulting in case of query 2.
>
|||Scott,
Isn't there any other way of stopping this reordering: tweaking of the
tables, or the columns..
In other words: what is the exact quantitative statistic that is considered
by the server for executing a query paralelly or serially.. i came to know
about execution costs, but i am not able to get any useful information from
the execution plans from the query anaylzer. What i am more concerned is that
query 2 is re-ordered whereas query 1 is ordered...
Thanks.
"Scott Morris" wrote:

> This has been discussed ad-nauseum. The order of returned rows is never
> guaranteed unless the query includes an order by clause.
>
|||As I said - no order by clause, no guarantee. There is a thread in
..progamming with the subject "order by and identity" that was active
yesterday. You might find the discussion interesting as it deals with the
same basic issue. You can search the newsgroups for discussions / rants on
this FAQ.
"Saravana" <Saravana@.discussions.microsoft.com> wrote in message
news:0FD75B28-2543-4128-8F6F-E888F5110751@.microsoft.com...
> Scott,
> Isn't there any other way of stopping this reordering: tweaking of the
> tables, or the columns..
> In other words: what is the exact quantitative statistic that is
considered
> by the server for executing a query paralelly or serially.. i came to know
> about execution costs, but i am not able to get any useful information
from
> the execution plans from the query anaylzer. What i am more concerned is
that
> query 2 is re-ordered whereas query 1 is ordered...
> Thanks.
> "Scott Morris" wrote:
>
|||Scott is 100% correct. If you want a specific order to be guaranteed for
the returned data you MUST specify an order by clause, period, end of story.
Andrew J. Kelly SQL MVP
"Saravana" <Saravana@.discussions.microsoft.com> wrote in message
news:0FD75B28-2543-4128-8F6F-E888F5110751@.microsoft.com...
> Scott,
> Isn't there any other way of stopping this reordering: tweaking of the
> tables, or the columns..
> In other words: what is the exact quantitative statistic that is
> considered
> by the server for executing a query paralelly or serially.. i came to know
> about execution costs, but i am not able to get any useful information
> from
> the execution plans from the query anaylzer. What i am more concerned is
> that
> query 2 is re-ordered whereas query 1 is ordered...
> Thanks.
> "Scott Morris" wrote:
>