Transact SQL :: Truncate And Insert Operation - Avoid No Rows In Table During Processing

Oct 22, 2015

I have a job which executes hourly.

Essentially:

Begin
Truncate table A
Insert into A
(Col1,
Col2,
Col3...
)
Select Value1,
Value2,
Value3...
From Table B
End

The insert operation query takes approximately 3.5 minutes to execute. What's occurring is the Table is immediately truncated, and there are no rows in the table for those 3.5 minutes.

How can I avoid having this gap - where there are no rows in the table for that period of time during the job execution ? The table could be locked, but that doesn't seem like the best solution.

View 8 Replies


ADVERTISEMENT

Transact SQL :: Insert Rows Into A Table For Missing Sequence Numbers

Jul 29, 2015

In a t-sql 2012 sql update script listed below, it only works for a few records since the value of TST.dbo.LockCombination.seq only contains the value of 1 in most cases. Basically for every join listed below, there should be 5 records where each record has a distinct seq value of 1, 2, 3, 4, and 5. Thus my goal is to determine how to add the missing rows to the TST.dbo.LockCombination where there are no rows for seq values of between 2 to 5. I would like to know how to insert the missing rows and then do the following update statement. Thus can you show me the sql on how to add the rows for at least one of the missing sequence numbers?

UPDATE LKC
SET LKC.combo = lockCombo2
FROM [LockerPopulation] A
JOIN TST.dbo.School SCH ON A.schoolnumber = SCH.type
JOIN TST.dbo.Locker LKR ON SCH.schoolID = LKR.schoolID AND A.lockerNumber = LKR.number

[Code] ....

View 10 Replies View Related

Transact SQL :: How To Bulk Insert Rows From Text File Into A Wide Table Which Has 1400 Columns

Feb 3, 2010

we can easily load a file into db tables. However, my main concern here is the number of columns in the file. A text file TEXT_1400.txt has 1400 columns. I am unable to load data to my db table using BCP or BULK INSERT commands, as maximum of 1024 columns are allowed per table in SQL Server 2008. 

We can still go ahead and create ‘Wide Table’ (a special table that holds up to 30,000 columns.  The maximum size of a wide table row is 8,019 bytes.). But when operating on wide table, BCP/BULK INSERT commands still fail. After few hours of scratching my head over BCP and BULK INSERT, I observed that while inserting BCP/BULK INSERT commands are unable to identify SPARSE columns and skip these columns, which disturbs column mapping and results in data conversion and trancation errors.
 
Is there any proper way to load this kind of files into the db table? 

View 6 Replies View Related

Transact SQL :: Avoid Same Table Multiple Times Rather Than Put Records In Single Table And Use It Throughout

Nov 19, 2015

There are 3 tables Property , PropertyExternalReference , PropertyAssesmentValuation which are common for 60 business rule

SELECT  
 PE.PropertyExternalReferenceValue  [BAReferenceNumber]
, PA.DescriptionCode
    [PSDCode]
, PV.ValuationEffectiveDate
    [EffectiveDate]
, PV.PropertyListAlterationDate
    [ListAlterationDate]

[code]....

Can we push the data for the above query in a physical table and create index to make the query fast rather than using the same set  tables multiple times 

View 11 Replies View Related

Transact SQL :: Inserting Records Into Table 2 From Table 1 To Avoid Duplicates

Nov 2, 2015

INSERT
INTO [Table2Distinct]        
([CLAIM_NUMBER]        
,[ACCIDENT_DATE]

[code]....

I used the above query and it still inserts all the duplicate records. What is wrong with my statement?

View 5 Replies View Related

T-SQL (SS2K8) :: Stored Procedure To Truncate And Insert Values In Table 1 And Update And Insert Values In Table 2

Apr 30, 2015

table2 is intially populated (basically this will serve as historical table for view); temptable and table2 will are similar except that table2 has two extra columns which are insertdt and updatedt

process:
1. get data from an existing view and insert in temptable
2. truncate/delete contents of table1
3. insert data in table1 by comparing temptable vs table2 (values that exists in temptable but not in table2 will be inserted)
4. insert data in table2 which are not yet present (comparing ID in t2 and temptable)
5. UPDATE table2 whose field/column VALUE is not equal with temptable. (meaning UNMATCHED VALUE)

* for #5 if a value from table2 (historical table) has changed compared to temptable (new result of view) this must be updated as well as the updateddt field value.

View 2 Replies View Related

Truncate A Huge Table Having 21 Millions Of Rows

Nov 19, 2015

SQL Server: 2008 R2

Question A :  I need to truncate a table, it has 21 millions of rows and it has a size of 14 GB.             

                                1-  How do I find out if this table is not being referenced by a FOREIGN KEY?
                                2-  Does it Participates in a indexed view?
                                3- Is being published by using transactional replication or merge replication?

Question B:  How do I safely truncate that table? 

View 8 Replies View Related

SQL 2012 :: How To Make Sure That All Rows Inserted Into Datamodel And Then Truncate Staging Table

May 8, 2014

In my ETL job I would like to truncate stg table but before truncating stging table, I want to make sure that all the records are inserted in the data model. The sample is as below

create table #stg (
CreateID int,
Name nvarchar(10)
)
insert into #stg
select 1, 'a' union all
select 2, 'b' union all

[Code] ....

How can I check among these tables and make sure that all values are loaded into the data model and the staging table can be truncated.

View 2 Replies View Related

Reusing A Generated Column To Avoid Over Processing

Oct 22, 2007

Hi,I'm constructing a query that will performs a lot o datetimecalculumns to generate columns.All that operations are dependent of a base calculum that is performedon the query and its result is stored in a columna returned.I wanna find a way of reusing this generated column, to avoidreprocessing that calculumn to perform the other operations, causethat query will be used in a critical application, and all saving isfew.Thanks a lot.

View 2 Replies View Related

SSIS DataFlow Truncate While Processing

May 19, 2008



Hi,

I was using SSIS for our ETL Process , one of the my DATA Flow have to truncate based on the data , suppose for example

i am have the following data

Filename : Employee
Columns
Empid , Employee

1 XXXXX
2 YYYY
3 ZZZZ


i am using flatfilesource for reading data . for example for a condition if empid='2' means i have to truncate the dataflow , it is possible or not ?

Please help me

Thanks in Advance
Raja Ragothaman





View 3 Replies View Related

Server: The Operation Has Been Cancelled. - When Processing Cube

Jan 3, 2007

When I highlight a few
partitions and start processing, the process occasionally stops with a
message that operation has been canceled, like this:

Response 3
Server: the operation has been cancelled.
Response 4

Server: the operation has been cancelled.

Response 5
Server: the operation has been cancelled.

..etc...

(no further error message details are provided)
SQL profiler shows that batch was completed (but rowcount shown in process progress log is too small).

Analysis
Services profiler shows no messages at that time at all. It just shows
messages when it started, and when I restarted the processing.

The Analysis trace appears to be stopped when processing stops with "Server: the operation has been cancelled."This
is an occasional error and sometime occurs within 15-20 minutes from
starting to process. It could fail on 1st partition in the process list
, or on some partition in the middle. Some partitions might run for a
few hours and not error out, but sometimes it fails quickly.I was not sure if this is an issue with the underlying fact data, so I broke up the last partition where it failed into 5 smaller partitions, they processed OK separately.I think restarting SQL Server and SSAS helps to process a few more partitions. Some that failed with this problem process OK after restart, but some fail again.
(apologies for re-posting, wanted to put under more specific thread title)

View 19 Replies View Related

Analysis :: Is There Any Rollback Operation Whenever Cube Processing Fail

Apr 24, 2014

I Have one cube, First time its Processed successfully and browsed fine. Now i was change in the cube Calculations/somewhere, now again process the process failed. I am unable to browse my cube. Is there any option to Rollback this processed cube and Browse with existing cube?What is require is, If cube process is fail, i want to browse the cube with existing cube after modify the cube also(if fails).

View 9 Replies View Related

Transact SQL :: Table Trigger To Delete All Rows Before Inserting Rows

Jul 24, 2015

I have a SQL script to insert data into a table as below:

INSERT into [SRV1INS2].BB.dbo.Agents2
select * from [SRV2INS14].DD.dbo.Agents

I just want to set a Trigger on Agents2 Table, which could delete all rows in the table , before carry out any Insert operation using above statement.I had below Table Trigger on [SRV1INS2].BB.dbo.Agents2 Table as below: But it did not perform what I intend to do.

USE [BB]
GO
/****** Object:  Trigger    Script Date: 24/07/2015 3:41:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON

[code]....

View 3 Replies View Related

A Previous Restore Operation Was Interrupted And Did Not Complete Processing On File

Sep 6, 2007



Hi

I am new to Forum. So not sure if i am posting my problem uner the right topic.

We have a sql server 2005 enterprise edition 4 way cluster on windows 2003 advance server.

I am logshipping these database to a different server at a different location.
My logshipping went fine until one the cluster server failed and the server instance failed over to another node.
The backup that happened around that time got copied over to the secondary by the copy job.
The log file that got copied to the secondary server tried restoring and i think it failed int he middle of restoring it.
(You would think that the sql would knoe if the backup is in complete and will move on to the next file. Not sure what happened there.)
There is no indication of the *.TUF file in the directory where i have the log files.

I tried restoring it manually and i got the following error

Msg 4319, Level 16, State 3, Line 1

A previous restore operation was interrupted and did not complete processing on file 'sessionlog1'. Either restore the backup set that was interrupted or restart the restore sequence.

Msg 3013, Level 16, State 1, Line 1

RESTORE LOG is terminating abnormally.


I looked in the msdb..log_shipping_secondary_databases and looked for the last file that it restored and tried restoring it again with the following restore command by removing and adding some of the keywords that you see after the "WITH" clause.
MSFT do not recommand to use continne_after_error unless its absolutley necessary. I stilll get the above error.


restore log sessiondata

from disk = 'I:sql13qasmlogssessiondatasessiondata_20070901124516.trn'

with restart, CONTINUE_AFTER_ERROR, norecovery

When i add the restart int he with clause,


The restart-checkpoint file 'J:Microsoft SQL ServerMSSQL.5MSSQLBackupsessiondata.CKP' was not found. The RESTORE command will continue from the beginning as if RESTART had not been specified.

Msg 4319, Level 16, State 1, Line 1

A previous restore operation was interrupted and did not complete processing on file 'sessionlog1'. Either restore the backup set that was interrupted or restart the restore sequence.

Msg 3013, Level 16, State 1, Line 1

RESTORE LOG is terminating abnormally.

I checked it the backup directory and i can't locate the .CKP file.

Does anyone ever come accross this issue?

Is there anyother way i could recover this DB in a standby or norecovery mode.

Any kind of help to resolve this issue (beside copy the full backup and redo the whole log-shipping process again) would be appreciated. sicne my primary and secondary server are totally ina different location, i need to ship a tape, if i need a full backup. This is the 3rd time its happening on that cluster. its frustrating to ship a tape everytime this happens.








View 4 Replies View Related

Transact SQL :: Bulk Insert 0 Rows Affected

May 15, 2015

I have a file which has some wind data that i am trying to import into a sql data base through bulk insert. if the script works as it supposed i should see 144 rows impacted but i see 0 rows affected. 

BULK INSERT TOWER.RAWINTERFACE_1058 FROM 'C:Temp900020150427583.txt' 
WITH(CHECK_CONSTRAINTS,CODEPAGE='RAW',DATAFILETYPE='char',FIELDTERMINATOR=' ',ROWTERMINATOR='
',FIRSTROW=172)

The code works if the file is large but if its small 0 rows are affected. and also if i remove the header rows then the file works again. want to understand what is going on here. i am including the screen shot of the file in notepad++. I have tried changing the row terminator to ' ' , ' ' and also tried to change the codepage but nothing seems to work. No error file is being generated either, if i give a error file option. 

View 7 Replies View Related

I Have Created A Table Table With Name As Varchar And Id As Int. Now I Have Started Inserting The Rows Like, Insert Into Table Values ('arun',20).

Jan 31, 2008

I have created a table Table with name as Varchar and id as int. Now i have started inserting the rows like, insert into Table values ('arun',20).Yes i have inserted a row in the table. Now i have got the values " arun's ", 50.                 insert into Table values('arun's',20)  My sqlserver is giving me an error instead of inserting the row. How will you solve this problem? 
 

View 3 Replies View Related

Transact SQL :: How To Get First Table All Rows In Left Join If Condition Is Applied On Second Table

Aug 15, 2015

I am using stored procedure to load gridview but problem is that i am not getting all rows from first table[ Subject] on applying conditions on second table[ Faculty_Subject table] ,as you can see below if i apply condition :-

Faculty_Subject.Class_Id=@Class_Id

Then i don't get all subjects from subject table, how this can be achieved.

Sql Code:-
GO
ALTER Proc [dbo].[SP_Get_Subjects_Faculty_Details]
@Class_Id int
AS BEGIN

[code] ....

View 9 Replies View Related

Transact SQL :: Update Table From Another Table For Multiple Rows

Jun 10, 2015

Matrix table has ID column and data below.

ID        Flag     TestDate         Value     Comment                                                                  
111          2       12/15/2014     7.5             null
222         2            Null                10          received

Matrix_Current table could have 1 or multiple rows as below.

ID        Flag               TestDate           Value         Comment
111         2                  01/26/2015        7.9                                                                      
111         2                  02/23/2015        7.9                                                      
111         2                  04/07/2015        6.8
222        1                   null                   8               test comment 1
222        3                   null                   9               test comment 2

When I run below update

 UPDATE  AM
 SET  M.Flag = MC.Flag, M.TestDate = MC.TestDate,
M.Value = MC.Value, M.comment = MC.Comment
 FROM dbo.Matrix M inner join dbo.Matrix_Current MC on M.ID = MC.ID

Matrix table has value below:

ID        Flag     TestDate         Value     Comment                                                                  
111          2       01/26/2015      7.9             
222         1            Null               8            test comment 1

I want to update Matrix table from all row from Matrix_Current, final table would like below:

ID        Flag     TestDate        Value     Comment                                                                  
111          2        04/07/2015      6.8             
222         3            Null                9         test comment 2

View 3 Replies View Related

Transact SQL :: Insert A Record Into Second table Where There Is Not A Match In First Table

Jun 25, 2015

I have a table in different databases with the same name.  My goal is to compare the two tables, and insert a record into the second table where there is not a match in the first table.  So far, my query looks like the following:

SELECT [metal] FROM [ProductionDatabase].[dbo].[Metalurgy]
EXCEPT
SELECT [metal] FROM [TestDatabase].[dbo].[Metalurgy]

This gives me a list of records from [Production].[dbo].[Metalurgy] which do not reside in [TestDatabase].[dbo].[Metalurgy].  Now, I need to use that list to insert missing records into [TestDatabase].[dbo].[Metalurgy].  How can I modify the above code to INSERT the missing records?

View 4 Replies View Related

Count All Table Rows Then Insert Into Test Table Using SSIS Packages

Jul 15, 2013

I have database test007DB and I need count all table rows then insert into test99 table using ssis packages .

test99: tableName countRows
t1 20
t2 30
t3 25

View 2 Replies View Related

Transact SQL :: Total Count Of Table Rows

Sep 15, 2015

I have a question regarding the total count of the table rows

Select count (name) from test. Lets say I have got 200 count. And Select count (lastname) from test1.I have got 200.And this counts I should store it in "There are nn name items awaiting your attention and nn pending lastname's awaiting your approval".

So now I have to store the count in 'nn'.

View 5 Replies View Related

Transact SQL :: Remove Blank Rows From Table?

Apr 17, 2012

I have a table for example like following

DECLARE @tmpTable table
(
name varchar(10),
address1 varchar(10),
phnno varchar(10),
mobno varchar(10)
)
INSERT INTO @tmpTable(name,address1,phnno,mobno)

[Code] ....

I want to remove all empty rows like row 1,2 and 3 in the above example.

I can't check all columns null values as there are many columns in my actual table.

View 6 Replies View Related

Transact SQL :: Getting Random Rows From Table / Two From Each Group

Sep 2, 2015

I am using Sql Server 2008 R2.I have a existing query that basically says

Select Top 50 Subscriber_ID,  Member_Name, Group_ID
from my_table
order by rand(checksum(newid()))

However the client now wants to have at least two from each group_id. There are 17 different groups.  When I run this as is I get about six of the 17 groups in the results.  How can I change this to get at least two results from each group_id?

View 6 Replies View Related

Transact SQL :: How To Swap Values Of Two Rows In A Table

Sep 10, 2015

I am a newbie to Sql server and i am having a task where my current table with always two rows existing and ID column as primary key looks like below:

ID  PlateNo Type Image Name

27 455 User img1.jpg
32 542 Alternative img2.jpg

And i want a sql query to modify my table so that the data should be like as shown below:

ID  PlateNo Type Image Name

27 542 Alternative img2.jpg
32 455 User img1.jpg

View 8 Replies View Related

Transact SQL :: Delete Duplicate Rows From Table?

Jul 21, 2015

I have a table with more than 1000 records. The columns look like this

Import id   |   Reference   |  Date  |  Username  | Filename

Some of the rows are duplicates except for the fact that they have different values for the first column alone (import id)

11111      test   21-07-2015   xxxxxx   yyyyyy
22222      test   21-07-2015   xxxxxx   yyyyyy

Is it possible to delete these kind of duplicate rows by ignoring the import id ?

View 9 Replies View Related

Transact SQL :: Copy ALL Rows From DB Table Out To Txt File

Jul 29, 2015

Copy out all data from a DB table into/across delimited text file(s) ensuring that each text file size is no more than 3MB.Have created a SSIS solution where it achieves this requirement ..well sort of achieves the requirement ... Here it what the current solution (sparing the minute details) does in a nutshell & Problems with it:

1) Created a function (Script below) which finds the
maximum row size in bytes in a given DB table & uses it to calculate
how many rows can be copied out into a text file without exceeding 3MB size limit.

For instance: A DB table selected had 788 rows in total and this function for this particular table returned a value of 181 rows { select [dbo].[udf_GetRowPartitionNumber](‘<TableName>’)as #ofRowstoPartitionTableby --181}  meaning in order to not exceed the requirement of 3MB per text file, we had to copy all the data from DB table across (create) 5 text files {Select
CEILING(788

[code]....

View 4 Replies View Related

Transact SQL :: If Not Exists Some ID In One Table Then Insert ID And Description In Another Table

Jul 14, 2015

I need to find out if a Transaction ID exists in Table A that does not exist in Table B.  If that is the case, then I need to insert into Table B all of the Transaction IDs and Descriptions that are not already in. Seems to me this would involve If Not Exists and then an insert into Table B.  This would work easily if there were only one row.  What is the best way to handle it if there are a bunch of rows?  Should there be some type of looping?

View 12 Replies View Related

Transact SQL :: Insert Data From Temp Table To Other Table

Oct 5, 2015

I want to insert the data from temp table to other table. Only condition is, it needs to sorted based on tool number and tool date. For example if we have ten records for tool number 1000, it should be order by tool number and then based on tool_dt. Both tables doesn't have any primary keys. Please find below my code. I removed all the unnecessary columns for simple understanding. INSERT INTO tool_summary  (tool_nbr, tool_dt) select tool_nbr, tool_dt from #tool order by tool_nbr, tool_dt...But this query is not working as expected. Data is getting shuffled.

Actual Data
Expected Result

1000
1-Aug
1000
1-Feb
1000
1-Jul
1000

[code]....

View 3 Replies View Related

Transact SQL :: Avoid Duplicates From Join

Jun 8, 2015

I am doing some audit and i  have below query, how can i get rid of duplicates from the below query any T SQL to get rid of duplicates...

I am using SP_Who2 and sql server  Audit for auditing all data happening on sql server databases  and dumping them to tables  Audit_DBAudit  abd Audit_sp_who2  and from then i am trying to get data which is not repeating/duplicate ...
 
SELECT
A.ProgramName
,a.HostName,[Server_principal_name],[Server_instance_name],[Database_name],[Object_name],F.Statement
FROM Audit_DBAudit as F 
 Join [Audit_sp_who2] AS a
on LTRIM(RTRIM(F.server_principal_name))=LTRIM(RTRIM(A.Login))

View 11 Replies View Related

Transact SQL :: Iterate Through Table Rows And Do Conditional Update

Aug 11, 2015

I have a table with the following fields:

ID (int, identity)
Name (nvarchar(255))
Block (nvarchar(50))
Street (nvarchar(255))
Floor (nvarchar(50))
Unit (nvarchar(50))
Address1 (nvarchar(255))
Address2 (nvarchar(255))

I want to iterate through the table and populate Address1 as [Block] [Street] #[Floor]-[Unit].If the 'Floor' field contain a number < 10 (e.g., '8'), I want to add a '0' before it (e.g., '08'). Same for Unit.How would I do this using cursors (or other recommended method)?

View 4 Replies View Related

Transact SQL :: Detecting Modified Rows Before Writing To A Table?

Apr 17, 2015

I've a table with more columns and 1 identifier. I need to write this table when a modified row is detecting respect to the columns not to the identifier.

So I've created a temporary table to put the potential rows to write on the real table, but I want to detect the modified rows. I've thought to use the checksum function, but I don't know how to use it and if it could be useful in this scenario.

Moreover, in the temporary table I've collected daily the rows to write: the first day a row could have a value respect to his columns, the next day a different value and the next one the same value respect to the first day.

View 26 Replies View Related

Transact SQL :: How To Convert Table Columns Into Rows In 2005

Aug 27, 2015

i have following table columns and i want to convert these all columns into row

SELECT [CASHINHAND]
,[CASHATBANK]
,[DEPOSITS]
,[ACCRECEVABLE]
,[SUNDRYDEBTORS]
,[LOANANDADVANCES]

[Code] ....

required output looks like

CASHINHAND 118950
CASHATBANK  200
DEPOSITS 3000
ACCRECEIVABLE
25000

View 3 Replies View Related

How To Insert Rows To Table B Based On Values In Table A.

Mar 7, 2008



I need Insert rows in the OrderDetails Table based on values in the Orders Table

In the Orders table i have a columns called OrderID and ISale.
In the OrdersDetails i have columns called OrderID and SaleType


For each value in the OrderID Column of the Orders Table, anytime the ISale Column in the Orders table = 1, and the SalesType column in the OrderDetails table is empty, I want to add two rows in the OrderDetails table. One row with the value K and another row with the value KD.
That is a row will be added and the value in the SalesType column will be K, also a second row will be added and the value in the SalesType column will be KD



Also for each value in the OrderID Column of the Orders Table, anytime the ISale Column in the Orders table = 0, and the SalesType column in the OrderDetails table is empty, I want to add two rows in the OrderDetails table. One row with the value Q and another row with the value QD
That is a row will be added and the value in the SalesType column will be Q, also a second row will be added and the value in the SalesType column will be QD.


I need a SQL Script to accomplish this. thanks

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved