SQL Server 2012 :: Insert Clone Copy Of Records

May 24, 2015

I am having three table tblTest,tblTestQuestion,tblAnswers

Each test can have multiple question and each Question can have multiple answers.

Now I am already having records in database. I wants to create clone copy of existing test except testdetails in tblTest because the test will be unique, and then insert questions and answers into their respective tables.

I was trying to create SP but stuck.

Please find below tables structure

[code="
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblAnswer](

[Code].....

View 5 Replies


ADVERTISEMENT

SQL Server 2012 :: How To Quickly Update / Insert 3M Records In Large Table

Mar 28, 2015

Our system runs a SQL Server 2012 DB, it has a table (table_a) which has over 10M records. Our system have to receive data file from previous system daily which contains approximate 3M updated or new records for table_a. My job is to update table_a with the new data.

The initial solution is:

1 Create a table (table_b) which structur is as the same as table_a

2 Use BCP to import updated records into table_b

3 Remove outdated data in table_a:
delete from table_a inner join table_b on table_a.key_fileds = table_b.key_fields

4 Append updated or new data into table_a:
insert into table_a select * from table_b

As the test result, this solution is very inefficient. Step 3 costs several hours, e.g. How can I improve it?

View 9 Replies View Related

SQL Server 2012 :: Set Based Method To Insert Missing Records Into Table - Right Join Not Work

Apr 24, 2014

I have table A (EmployeeNumber, Grouping, Stages)
and
Table B (Grouping, Stages)

Table A could look like the following where the multiple employees could have multiple types and multiple stages.

EmployeeNumber, Type, Stages
100, 1, Stage1
100, 1, Stage2
100, 2, Stage1
100, 2, Stage2
200, 1, Stage1
200, 2, Stage2

Table B is a list of requirements that each employee must have. So every employee must have a type 1 and 2 and the associated stages listed below.

Type, Stage
1, Stage1
1, Stage2
2, Stage1
2, Stage2
2, Stage3
2, Stage4

So I know that each employee should have 2 Type 1's and 4 Type 2's. I hope that makes sense, I'm trying to change my data because ours is very proprietary.

I need to identify employees who do not have all their stages and list the stages they are missing. The final report should only have employees and the associated missing types and stages.

I do a count by employee to see how many types they have to identify the ones that don't have all the types and stages.

My count would look something like this:

EmployeeNumber Type Total
100, 1, 2
100, 2, 2
200, 1, 1
200 1, 2

So I know that employee 100 should have 2 more Type 2's and employee 200 should have 1 more Type 1 and 2 more Type 2's based on the required list.

The problem I'm having is taking that required list and joining to my list of employees with missing data and pulling from it the types and stages that are missing by employee. I thought I could get a list of the employees that are missing information and right join it to the required list where the missing records would be nulls. But, that doesn't work because some employees do have the required information and so I'm not getting any nulls returned.

View 9 Replies View Related

SQL 2012 :: How Many Records Can Insert Into A Temp Table

Mar 25, 2014

I use code below to insert data into a temp table.

How many records can insert into a temp table?

Select * into #temp from ORDER

View 3 Replies View Related

SQL 2012 :: Bulk Insert Records For Date Range And Day

Aug 21, 2014

I have two tables, customers and appointments.

I want to bulk insert records for a date range and a day of the week.

For example, John Smith has an appointment on every monday for the next three months. How do I accomplish this?

View 1 Replies View Related

SQL 2012 :: Snapshot Getting Corrupted After Insert Update Few Million Records Into A Table

Mar 12, 2015

We are facing a weird scenario in which the snapshot is getting corrupted after insertupdate few million records in to a table .

SQL Server 2012
windows server 2008 R2
service pack 1
64-bit OS

View 1 Replies View Related

SQL Server - 'cold' Database Clone, Was This Ok?

Jul 23, 2005

HiI was in the situation of cloning a SQL server database last night.Today, a dependent application was behaving a little erratically thoughmost things were fine after sorting out some ntfs permissions. I'verecovered this database from backup exec before from a hot-backup, thisis the first time I've attempted this procedure though.Could I check with the experts here as to whether what I did was OK?Been googling to see if it is really the right thing to do, haven'tcome up with anything definitive...Assume server SOURCE and DEST:install DEST to same specification, OS, SQL patch level as SOURCE. Samepaths where applicable.shut down SQL server on bothCopy all datafile folder (d:sqldata) which is the full databaseincluding MASTER etc all over to DEST.Shut SOURCE down.Rename DEST to SOURCE, disable SQL server starting, set networksettings to those of SOURCE and reboot.Wait for things to settle after reboot and name change, bring SQLdatabase up.Client application now connects, I can't see any problems, but therehave been some strange anomalies in satellite applications today. Allhave been bounced to see if it's just a change they needed to notice,to no avail.Was that an OK operation to have done, or is there something just aboutto bite me when I'm not looking?Be grateful for any advice, I spent today pulling a lot of hair out.Thanks in advance :)AW

View 3 Replies View Related

Sql Server Hot Backups (Clone/Fracture)

Aug 6, 2006

Not sure if there is anyway to do hots on sql server .From all I haveheard an EMC can do clones and fractures in order to implement a hotbackup or some kind of it in sql server.Seemingly the DBA has to do something toenable the fracture of the clone . Is anyone familiar with this ?Your input is highly appreciatedMB

View 1 Replies View Related

SQL 2012 :: Query To Make Single Records From Multiple Records Based On Different Fields Of Different Records?

Mar 20, 2014

writing the query for the following, I need to collapse the continuity. If the termdate for an ID is one day less than the effdate of the next id (for the same ID) i need to collapse the records. See below example .....how should i write the query which will give me the desired output. i.e., get min(effdate) and max(termdate) if termdate is one day less than the effdate of next record.

ID effdate termdate
556868 1999-01-01 1999-06-30
556868 1999-07-01 1999-10-31
556869 2002-10-01 2004-01-31
556872 1999-02-01 2000-08-31
556872 2000-11-01 2004-01-31
556872 2004-02-01 2004-02-29

output should be ......

ID effdate termdate
556868 1999-01-01 1999-10-31
556869 2002-10-01 2004-01-31
556872 1999-02-01 2000-08-31
556872 2000-11-01 2004-02-29

View 0 Replies View Related

SQL Server 2008 :: Job To Delete All Records Then Copy All From Another Table?

Apr 22, 2015

I am using a SQL Server Agent jobs that run each morning to update the records in a table to match what they should be for that day. I built them and tested it using a test table called "testtable1". It worked fine. But when I switched over to our production table, it fails saying the table has to be decaled. What would be the difference. The production table has a "@" in front of the name, is that causing issues?

USE [Live_build]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
BEGIN
DELETE
FROM @ZIPLIST
INSERT INTO @ZIPLIST
SELECT * FROM tblZip3DSWed;
END

View 4 Replies View Related

SQL Server 2008 :: Clone Hierarchy To Another Table

Apr 4, 2015

I have a table "t_prod_cat" which contains hierarchical data which is used in production to present data.

CREATE TABLE [dbo].[t_prod_cat](
[cat_node_id] [bigint] IDENTITY(1,1) NOT NULL,
[advertiser_id] [bigint] NOT NULL,
[cat_hid] [hierarchyid] NULL,
[level] AS ([cat_hid].[GetLevel]()) PERSISTED,
CONSTRAINT [PK_t_prod_cat] PRIMARY KEY CLUSTERED
(
[cat_node_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

In order not to impact the production website during the time an advertiser is editing (the editing might take much time and also mainly because at any time during the editing, the advertiser could cancel all the changes he did), I was thinking of transferring all the data linked to that advertiser to another table and let the advertiser apply any modifications up to the moment he will commit the changes.

Therefore, I would like to "CLONE" the hierarchy related to a certain advertiser_id to another table "t_prod_cat_work"

CREATE TABLE [dbo].[t_prod_cat_work](
[temp_cat_node_id] [bigint] NOT NULL,
[temp_cat_hid] [hierarchyid] NOT NULL,
[advertiser_id] [bigint] NOT NULL
) ON [PRIMARY]

What can be the easiest way to clone all the hierarchical data (multi-levels) from 't_prod_cat' to 't_prod_cat_work' for a certain advertiser_id ?

View 2 Replies View Related

Copy Table And/or Records From SQL Server 2000 To 2005 Express

Apr 7, 2006

How can I copy a table from my sql server 2000 db to my sql server 2005 express edition?
I have a project in VS.NET 2005 and I have a db in App_Data folder. However, when I look into that folder, there is nothing visible. I now need to copy a table from my existing sql server 2000 to my db located in my project's App_Data folder.
Any help would be appreciated..
 
Regards,

View 1 Replies View Related

SQL Server 2008 :: Clone Stored Procedures From Database A To B

Apr 24, 2015

I have this requirement where some store procedures from a "seed" database need to be replicated to another database (on demand, so replication is not suppose to be use in this scenario).

I know it can be achieved by exporting the store procedures and then execute that at the B database but I want something a bit more automatic since it can be a large number of sprocs. I am trying something like this (still in dev):

SET NOCOUNT ON;
--
SELECT ROW_NUMBER() OVER(ORDER BY definition) seq, definition base
into #sprocs
FROM databaseA.[sys].[procedures] p
INNER JOIN databaseA.sys.sql_modules m ON p.object_id = m.object_id

[Code] ....

But I am sure there are way better ways to accomplish that...

View 4 Replies View Related

SQL 2012 :: Copy SSIDB From One Server To Another

Apr 21, 2015

For copying the SSISDB from one server A to another B I used the following steps:

Took backup of SSISDB on server A.

On Server B, created a new SSISDB catalog.

Restored the newly created SSIDB on B from backup of the DB from server A.

Is it correct process for SSISDB or not.

View 1 Replies View Related

SQL Server Admin 2014 :: Clone SSRS VM For Scale Out Deployment

Sep 4, 2015

Ive successfully cloned an SSRS VM Server within a scale out deployment to REPLACE a current physical machine. This wasn't too difficult.

The issue im having now is in creating a new SQL 2014 Environment with 3 SSRS nodes. Ive taken the time to build one up. Changed all my config files, installed all components etc & tweaks needed within my company...

I have now hit a brick wall though. Ive cloned this first server twice to give me 3 nodes. This is a new environment so the issue I have is that the rsreportserver.config files all now have the same InstallationID. I dont have any existing nodes to overwrite these files with. So when I attach the nodes to the database they will update the keys table with the same InstallationID as the first node and none will work.

Any way to force the SSRS setup to re-generate an installation ID - by repair maybe? Or is this something I can manually just make up?

View 0 Replies View Related

SQL Server 2008 :: Huge Volume Of Records To Copy To Excel File Through SSIS

Oct 22, 2015

I am copying data from database to an excel file through SSIS. database is MS SQL 2005 and BIDS is also 2005.However, the job doing this task fails every time.As per investigation, the result of the query is more than 100,000 rows and we know that excel has a limit of 65000 rows of data.Is there a way of setting the limit up? or something? a better approach maybe so that everything will be copied to the excel file successfully.

The PrimeOutput method on component "Source - Query" (1) returned error code 0xC02020C4. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure. End Error Error: 2015-10-22 04:34:58.05 Code: 0xC0047021

Source: Data Flow Task
Description: SSIS Error Code DTS_E_THREADFAILED.

Thread "SourceThread0" has exited with error code 0xC0047038. There may be error messages posted before this with more information on why the thread has exited. End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 4:30:00 AM Finished: 4:35:05 AM Elapsed: 304.844 seconds. The package execution failed. The step failed. "

View 1 Replies View Related

SQL Server 2008 :: How To Copy Several Records From One Server To Another

Sep 11, 2015

I've got to copy several records (almost a 100) in a table from one instance of SQL Server 2008 R2, to another instance of SQL Server 2008 R2, but on a different server. The table structure is identical. I've searched online and found examples of doing a bulk insert into a table from a .CSV file. However I don't know of a way of exporting records to a .CSV file using a SELECT statement.

I've heard of linked servers, but at least as far as I know linking the server would require administrative privileges that I don't have on either machine.

View 9 Replies View Related

SQL 2012 :: Copy Backup Files From One Server To Another?

Sep 23, 2014

I've an emergency requirement to copy Source server database backup files to destination Server through xcopy command. Backup job on source server runs daily, so once this job get completes all databases backups needs to be moved to destination server. But here the main concern is "the backup files on destination server shouldn't be overwritten, they should be placed separately as Source server job runs daily".

We've a command which overwrites backups on destination server. But we need to keep backups on destination at-least for 4 weeks (means : retention should be 4 Weeks).

View 5 Replies View Related

SQL Server 2012 :: Dynamically Copy The Table From One DB To Another?

Nov 27, 2014

Need to scheduled to copy table data from one database to another database daily @7:00 AM by creating the table with date and time stamp.

Example :

Test1DB ---> Table1

Test2DB -----> Table1_281120140700 in Day1 and Table2_291120140700 in Day2.....and so.

SELECT * INTO Test2db.dbo.new_table_name FROM Test1db.dbo.old_table_name in this format ??

script and scheduled to run daily @ 7:00AM?

View 1 Replies View Related

SQL Server 2012 :: How To Copy Nested Sub-tree From One Node To Another

May 12, 2015

I have a tree and I need to copy a nested sub-tree (an element with its children, which in turn may have their owns) from one place to another.

The system should allow to handle up to 8 levels. I do know how to move, but cannot figure out how to copy.

Below is a working example With Create Table, Select and Cut / Paste (implemented via Update).

I would like to know how to copy a nested tree with reference id 4451 from Parent_Id 1 to Parent_Id = 2

--***** Table Definition With Insert Into to provide some basic data ****

IF (OBJECT_ID ('myRefTable', 'U') IS NOT NULL)
DROP TABLE myRefTable;
GO
CREATE TABLE myRefTable
(
Reference_Id INT DEFAULT 0 NOT NULL CONSTRAINT myRefTable_PK PRIMARY KEY,

[Code] ....

How to Copy nested sub-tree 4451 with all its children to Parent_Id 2, without deleting from Parent_Id = 1 ?

View 7 Replies View Related

SQL 2012 :: How To Copy Data From One Table On Remote Server A To B

Aug 12, 2015

how to copy a content of a table from one remote server to another,. server A does not see server B (B doesn't see A) - I cannot even ping to one from another.I do have SQL Studio installed on server C, which IT team configured to allow access to both A and B.So what I did so far is to periodically:

1. connect from the studio on server C to server A
2. run the following script on server A: SELECT * FROM A.myTable FOR XML PATH('ROOT')
3. copy the result
4. connect from the studio on server C to server B
5. to write something like

DECLARE @xmlData XML;
SET @xmlData = pasting here my result from item 3 above

6. INSERT INTO
SELECT

ref.value .....
FROM @xmlData.nodes('/myElemnet/ROOT')
xmlData( ref );

so it works. now there is a requirement to schedule this update to run periodically and I need to implement it..

View 9 Replies View Related

SQL Server 2012 :: Copy Database From One Server To Another

Mar 25, 2014

I have two servers on different machines:

Production & Testing

I have a database called MyData on Production.

I can link the servers using sp_AddLinkedServer.

I want to make a copy of MyData from Production to Testing and rename it from MyData to MyData_Testing.

Currently, I figure I will have to make a backup - copy it from Production to Testing - restore it. Since I can link the servers, I can initiate the backup from Testing - copy - and restore from a script on Testing. The only part I am not sure of is how to copy the file via the script.

How to copy the file?

View 3 Replies View Related

SQL 2012 :: Copy All Objects From One Server To Another Server?

Aug 12, 2015

Using import task only can select and copy tables and views.

Since there are many objects at the same DB I don't need copy, is there any way let me select and copy some objects, such as functions, stored procedures?

View 1 Replies View Related

SQL Server 2012 :: 2 Records At A Time?

Nov 15, 2013

I am developing a form for a mortgage company. There can be any number of borrowers on a given loan, and the business has asked that this form return only 2 borrowers at a time for a loan. For example, if there are 3 borrowers for a loan, they want the first copy of the form to print the first 2 borrowers and then another copy of the form to print the 3rd. No matter how many copies are printed, they want the borrower information to be labeled as 'Borrower1' xyz and 'Borrower2' xyz. Also, there will be a LOT more fields returned on the real form, so the sample information below is very simplified test data.

Sample Data:
CREATE TABLE #t (LoanID VARCHAR(5), BorrowerName VARCHAR(20), BorrowerOrder INT);
GO
INSERT INTO #t VALUES
('::E', 'John Smith', 0)
, ('::E', 'Jane Smith', 1)
, ('::E', 'Rob Jackson', 2)
, ('AF_CF', 'Sloan Burton', 1)

[code]...

I don't want that 2nd record to return. This result is what makes me think of gaps and islands, but I don't know if the 2nd record is really an island since it's (1) not stored this way...it's returning this way because of the query and (2) it's not sequential data..I tried restricting this by putting this into a CTE and then returning only the odd numbered records like I have below. This runs pretty quickly when dealing with one loan. But...I am concerned that the CTE will be slow when we run batches of loans.

Attempt with CTE:
--With CTE
;WITH cte AS
(SELECT
Borrower1 = BorrowerName
, Borrower2 = LEAD(BorrowerName) OVER(ORDER BY BorrowerOrder)
, RowNumber = ROW_NUMBER() OVER(ORDER BY BorrowerOrder)

[code]...

Is there a better, cleaner way to do this? Or is the CTE the best way to go?

View 8 Replies View Related

Questions About Bulk Copy Insert Using 'Memory Based Bulk Copy Operations'

Feb 1, 2007

Hi~,

Before implementing memory based bulk copy insert with IRowsetFastLoad interface of SQL Server 2005 OLE DB provider, I want to know some considerations.

- performance : compared with T-SQL's "BULK INSERT ..." and bcp utility

- SQL Server's resource usage : when running memory based bulk copy, server resource's influence

- server side action(behavior) : when server is busy, delayed-update means IRowsetFastLoad::Commit(true) method can insert right after?

- row-count : The rowcount limitation can be inserted by IRowsetFastLoad::InsertRow() method before IRowsetFastLoad::Commit

- any other guide lines

View 1 Replies View Related

SQL Server 2012 :: Encrypted Records In All Columns

Nov 6, 2014

I have idea on SMK, DMK and symmetric and asymmetric keys. I have also idea on TDE. But Is there any way to encrypt all the records of all the columns of a table in a database? actually I need to encrypt the database. Someone .... thinks that when someone will write select query he will get the encrypted records. As per as I am concerned it is not possible. I can encrypt the specific column using symmetric or other keys...

Is there any software or any tool which will provide encrypted records of database?

View 1 Replies View Related

SQL Server 2012 :: Get Only Records Which Row-number Is 0 Or 1 In Module 20?

Mar 5, 2015

With this query i get only the records i need, but i would like to output in this way

1 - 20
21 - 30
31 - 40

of course in the real environment the ID are not consecutive, this is just one example of data.

declare @temp table (ID int)
declare @i int = 1
while(@i<1000) begin
insert into @temp values (@i)
set @i=@i+1
end
select ID from (
select ID, row_number() over (order by ID)
as rn
from @temp
) q where (rn % 20=0) OR (rn % 20=1)

View 3 Replies View Related

Data Flow Task To Delete Records And Then Insert Records In Transaction

Aug 6, 2007

HI,

I have been trying to solve the locking problem from past couple of days. Please help mee!!

Scenario:
--------------
I have a SSIS package in which 2 data flow tasks. 1st data flow task deletes records from a 5 tables and the 2nd data flow task should insert records into 1 of the five tables after the success of 1st data flow task. This scenario runs in Transacation.

The above scenrio in the 2nd data flow task hangs in runtime. It does not complete. with sp_who2 command i could see that there is an intent share lock(LK_M_IS) on the table and the status is SUSPENDED.

I dont know how to come out of this locking. Please help.

Thanks ,
Sunil

View 7 Replies View Related

SQL Server 2012 :: Series Of Records - Identifying Discrepancies

Mar 17, 2014

I have a series of records based on empid where I want to identify the empid that may have discrepancies listed. I have some empids that are listed more than once and have different DOB's. In the example I am trying to Create a DOB_ERROR column and either say yes if the DOB doesn't match the other records in the file with the same empid.

SELECT
Empid,
DOB,
CASE WHEN DOB = DOB THEN 'No' ELSE 'Yes' END AS DOB_ERROR,
City,
St,
Gender
FROM Emp
WHERE EMPID IN

('12335', '23456', '545432','231245')

View 3 Replies View Related

SQL Server 2012 :: Updating 25 Million Records In Batches

Nov 10, 2014

I have 2 tables with this schema

CREATE TABLE tableValues(
[LASTENCRYPTIONDT] [datetime] NULL,
[ENCRYPTIONID] [int] NULL,
[NAME] [varchar](50) NULL

[Code] ....

I want to update tableToUpdate in batches of 5000 per batch and set the lastenecryptionDT to null based on the the join to the tableValues using the column ENCRYPTIONID, and also output updated rows into another table. Incase I would need to do a rollback.

View 3 Replies View Related

SQL Server 2012 :: Convert Records From Rows Into Columns

Nov 13, 2014

I have 5 columns in my database. 1 column is coming like a dynamic.

I want to convert records from rows to columns. Currently I have a data like this.

Race AgeRange Amount

W 17-20 500
W 21-30 400
W 31-40 200
A 17-20 100
H 41-50 250
H 51-60 290

So age range is not fixed and it can be any and I have one separate relational table for age range where it's coming from. Now I want to convert it into columns like

Race 17-20 21-30 31-40 41-50 51-60

W 500 400 200 0 0
A 100 0 0 0 0
H 0 0 0 250 290

View 1 Replies View Related

SQL Server 2012 :: How To Fetch Records Which Throws Error

Feb 27, 2015

How to fetch records which throws error?

For example

I'm inserting records from a table to another table, having multiple columns

SampleQuery :

insert into tableB (col1,col2....col10)
select col1,col2....col10 from tableA

* while executing this query im getting error. (like varchar cant convert to numberic)
* Here I have no clue in which column it is
* also dont know which row causes it

View 3 Replies View Related

SQL Server 2012 :: Update Quantities Over Multiple Records?

Mar 25, 2015

I have two tables that can be created with sample data using the DDL at the bottom of this post. What I'm looking to do is update the QtyReceived column in tblPurchaseOrderLineDetail from the Qty column in tblReceivedItems. However, the tricky part that I can't figure out is splitting these quantities out over multiple lines. I should only be allowed to receive up to the QtyOrdered column in tblPurchaseOrderLineDetail.

For a specific example from the sample data we'll look at PurchaseOrderDetailID 28526. From the tblReceivedItems, there are three records with quantities of 48, 48, and 20. From the tblPurchaseOrderLineDetail there are three records of QtyOrdered of 55, 45, and 20. What I would like to happen is fulfill the records in the tblPurchaseOrderLineDetail sequentially (essentially in order of ExpectedDate). So, the QtyReceived would be 55, 45, and 16 for the corresponding records. If there is already a quantity in the QtyReceived column, but it's less than the QtyOrdered column, the quantity needs to be added to the column (not overwritten).

DDL To CREATE Sample Tables and Data:

CREATE TABLE [dbo].[tblReceivedItems](
[ID] [int] IDENTITY(1,1) NOT NULL,
[PurchaseOrderDetailID] [int] NULL,
[Qty] [int] NULL)
SET IDENTITY_INSERT [dbo].[tblReceivedItems] ON
INSERT [dbo].[tblReceivedItems] ([ID], [PurchaseOrderDetailID], [Qty]) VALUES (1, 28191, 48)

[code]....

View 5 Replies View Related







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