Ok, so I have a primary table that contains the count of a linked table. Since I can let the identity update itself, I should be able to insert the same values into the linked child table.
I need to put the same record in the child table 1000 (that's an arbitrary number, this will be programatically determined by the user) times.
I understand that I can do this:
INSERT INTO SomeTable (Cols) VALUES (vals)
GO 1000
However, I can't make this work when doing an ADO.NET ExecuteCmd. It doesn't like the Go 1000 part of it.
Does anyone have an idea how I can do this VERY QUICKLY without having to execute a separate insert for every item (or batch them)?
The number could be as high as 250,000 in the child table.
How to write a query that can insert over 1000,0000 dummy records in the fastest way? My current query is
 DECLARE @d DateTIme = GETDATE()  DECLARE @c INT = 1 WHILE @c <= 5 BEGIN INSERT INTO MyTable VALUES (NEWID(),'PREFIX' + RIGHT('0000000000'+ (CAST(@c AS VARCHAR)), 10), DATEADD(MINUTE,@c,@d), FLOOR(RAND()*3), FLOOR(RAND()*2), 'INFO')   SET @c = @c + 1 END
Hi,I have successfully set and used a linked server to query ADSI.Since this question also concerns MSSQLServer, I've cross posted it --I hope this is not a breach of etiquette.I have successly created a view based on the linked server.Unfortunately, it only shows 1000 records, and there does not seem tobe any way to set the Page Size.I found the following:http://support.microsoft.com/defaul...kb;en-us;243281Which seems to imply that the default can be set by changing registrykey: "HKEY_CURRENT_USERSoftwarePoliciesMicrosoftWind owsDirectoryUI"I have set this key, and also set it for the user account under whichMSSQLServer runs. The value persists after a reboot. The Domain Grouppolicy sets the default to 15000.This behaviour is not restricted to the linked server. If I use thescript found here:http://hacks.oreilly.com/pub/h/1121 I can access morethan 1000 records, but only if I set the "Page Size" property. If Icomment it out to let the default hold, it is 1000.It must be settable SOMEWHERE or the whole linked server thing is ofvery limited use.At present, the best solution I've been able to come up with is to usethe above script modified to run as a DTS package. Yuck.TIA,BM
I have an PL/SQL procedure @ Oracle database which extracts 10000 rows from a table and Now I have load all the 1000 rows into SQL 2005 tables.
I have extracted the data from oracle into DataAdapter/dataset , Now I want to load all the rows to SQL 2005 tables. Please help how I can load..
If I use insert statement everytime , it makes server busy and takes much time for 10000 inserts to complete(even using Procedure goes heavy since for every insert have to call this).
Is there any possibility that i can pass the REF Cursor / Dataset/dataAdapter into SQL stored so that inserts will have happen all together ??
create proc dbo.usp_CatchAddressException @tableName varchar(500) as -- alter proc dbo.usp_CatchAddressException @tableName varchar(500) as
begin set nocount on declare @sql varchar(700)
-- truncate table tempException set @sql = 'insert hava_dcde.dbo.STREET_EXCEPTION (id_town, id_voter, pre_value, nbr_exception, date_stamp) select a.id_town, a.id_voter, substring(a.ad_str1, 1, len(a.ad_str1) - charindex('' '', reverse(a.ad_str1))), ''20'', getdate() from HAVA_DCDE.dbo.' + quoteName(@tableName)+ ' a where substring(a.ad_str1, 1, len(a.ad_str1) - charindex('' '', reverse(a.ad_str1))+1) not in (select nm_street from HAVA_DCDE.dbo.state_streets ss)' -- and a.id_town = + @tableName -- print(@sql)
exec(@sql) set nocount off end ---------------------------------------------------
when i run this SP 2 times, it will insert the values 2 times. what should i do if i don't want to insert the same values 2 times? I'm confussed, Should i use update? any input will be appreciated.
I have a client who needs to copy an existing sale. The problem isthe Sale is made up of three tables: Sale, SaleEquipment, SaleParts.Each sale can have multiple pieces of equipment with correspondingparts, or parts without equipment. My problem in copying is when I goto copy the parts, how do I get the NEW sale equipment ids updatedcorrectly on their corresponding parts?I can provide more information if necessary.Thank you!!Maria
Hi I have a table with a user column and other columns. User column id the primary key.
I want to create a copy of the record where the user="user1" and insert that copy in the same table in a new created record. But I want the new record to have a value of "user2" in the user column instead of "user1" since it's a primary key
I'm using the following code to add some data to a table: Dim rand As Random = New Random Dim num As Int32 = rand.Next(10000000) Dim strConn as string = "......." Dim sql as string = "INSERT INTO tblitemid (itemid, userid, datetime, supplier, comment, commenttype, uniqueid) VALUES ('" & label1.Text & "', '" & user.identity.name & "', '"& System.DateTime.Now & "','3763' ,'" & textbox1.text & "' , 'C' ,'" & num & "')" Dim conn as New SQLConnection(strConn) Dim Cmd as New SQLCommand(sql, conn) Try conn.Open() Catch SQLExp as SQLException Response.Write ("An SQL Server Error Occurred: " & e.toString()) Finally cmd.ExecuteNonQuery conn.Close() End Try
As far as I can tell the code works fine. But for some odd reason I click the button, the code execute and the page closes as it should, but the data is never inserted into the database. I cant really seem to pick up on any paterns for why this would be happening. As a rough guess I'd say it doesnt insert the data 1 out of every 5 times or so it seems. Anyone every have any experience with this? Any comments would be helpful, cuz I'm at a loss. If youd like to see more code let me know.... Thanks, Scott
I have a table with 4869068 rows and when some one tries to insert the records into this table the database times out....Does any one know what could be the reason and from where do I start debugging. I have no problem with the disk space?
I am supporting a financial application on mssql 6.5,sp4.
Other than at month-end when activiy is high, we have at some unexpected heavy insert activlty as well as deletes at unexpected times. Other than periodically watching 'current activity' or running sp_who2, we aren't sure when this happens and by whom if we don't see it.
Does any one know how I can monitor this unexpected activity?
IS there I can run periodically to trap which spid and/or user who is running such activity?
I have two tables in my database. I want to insert date and no.of hours worked on that day for a particular project. So in a week if end user enters 7 dates and hrs for each day...... i have to insert those values into the table against one project only. Can any one please help me out how to run insert query for 7 times (in a week) with different parameters
I am trying to create package something like that..
1- New Customer table as OleDB source component 2- Lookup component - checks customer id with Dimension_Customer table 3- And if same customer exist : I have to update couple fields on Dimension_Customer table 4- if it does not exist then I have insert those records to Dimension_Customer table
I am able to move error output from lookup to Dimension_Customer table using oledb destination but How can I update the existing ones? I have tried to use oledb command but somehow it didnt work my sql was like this : update Dimension_Customer set per_X='Y', per_Y= &Opt(it should come from lookup)
Ok this is a simple question but i cant seem to find out how since i had the access of a query builder for web matrix.I have the following:A Table called Customer, with Cust_Name, Cust_phoneI have modified my CreateUserWizard to accomodate mroe text boxes which would finally store to vales for Cust_Name, Cust_phone.Question is how can i perform an INSERT query? or rather i noticed that the query builder doesnt allow me to, instead the query builder is towards inserting new records thur GridView and FormView.I've designed a query to handle wildcards i.e @Cust_Nameso i'm thinking if i can have a working insert statment i can do something liketbCust_name.txt = @Cust_Namethen finally perform the insert queryAny ideas? thanks
Hello I’m using express edition to create my trail test application. Below is the code that I have and I’m trying to insert data to the database table named “Coin�.
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnview.Click
Dim s As String = txtCname.Text
'Dim myConnection As New SqlConnection(myConnString)
Hi I have a table in sql server with a numeric field as Primary Key. When i insert a new record i need that primary key increments automatic (like access auto increment) because i want avoid the possibility of duplicate Primary Keys. Is that possible? Thank you
hi all,i have a question that how to get id afer insert a new record.i just read from the following article, but still can't get the meaning:http://forums.asp.net/1008337/ShowPost.aspx and my code Dim sql_3 As String sql_3 = "insert into paper_type (name, enable,creation_date,lastupdate,user_id) values " sql_3 += "('" & name & "','" & enable & "', getdate() ,getdate ," & user_id & ")" Call OpenRs(sql_3) ' I want to get the id immediately, but how?? (i am using sql server) can somebody help me to solve the problem??thanks a lot
I'm trying to make a website that people can upload file to the server, then the webpage will automatically insert the username and the file name into the database. I have thought about this for couple days but still got nothing. can some one help me? can some one post a very simple aspx file that can insert a record to the sql database with C#? Not the code that generated by ASP.net 2.0! I want to see how to access the database manually. Thank you.
I am trying to do an update to a database with the code below, the code will work in generating a single record (if i exclude the IF statement) but i need it to create multiple new records based on the IF statement (or something similar) i have in the code. It needs to create updates for every record that has a parentguid that matches the one specified in the code. the idea is, the hierachy structure in the tables are:
i want it so that when i input a new part it updates to all the locations. The locations all have the same parentguid (the one specified in the code) With regards to the stored procedure it executes, this stored procedure creates the entry. I don't really want to change the stored procedure because other functions reference and use it.
I am new to msSQL and ASP, I need some help writing an SQL statement that will first check to see if a combination or record exists, if none found thant it will add it. I am working a section of a site that adds favorites to the database. Each user can have more that one favorite hence it has to check for that unique combination of the fields, UserID and FavID
My Code: Dim objConnection, objRecordset, strSQL Dim strFavID, strUserID strFavID = request.Form("favid") strUserID = request.Form("userid")
Set objConnection = Server.CreateObject("ADODB.Connection") Set objRecordset = Server.CreateObject("ADODB.Recordset") objConnection.Open Application("ConnectionString")
strSQL = "INSERT INTO FAV (UserID,FavID) (SELECT DISTINCT " & strUserID & " AS UserID " & _ strFavID & " AS FavID" & " FROM FAV)" & _ " WHERE " & strUserID & " & " & strFavID & " NOT IN (SELECT UserID, FavID FROM FAV)" response.Write(strSQL) 'response.End()
If strFavID <> "" Then On Error Resume Next objConnection.Execute(strSQL)
objConnection.Close Set objConnection = Nothing End If
This code is giving me a syntax error, how do I write the correct statement. I am using MS Access 2k
/*if key values exist don't insert new record*/ SELECT
/*if exists don't insert*/ CASE WHEN ISNULL(gradeId, -1) = -1 THEN INSERT INTO tblScores (gtStudentId, assignmentId, score) VALUES (@nStudent, @nAssignment, 0) END
FROM tblScores WHERE gtStudentId = @nStudent AND assignmentId = @nAssignment
tblScores has two fields comprising its primary key (gtStudentId, assignmentId) and the gradeId field is a required filed in this table.
I'm getting syntax errors when I click check syntax (near keywords insert from and end).
one other note: this CASE END is nested inside a BEGIN END loop, is this the problem? Is the 'End" of the 'Case' closing the 'End' of the 'Begin'?
SOS I am working with SQL 2000 located on a Networksolutions server and I have a Test record I inserted manually, but I am unable to insert a new record and get this error "can't insert new record to database". No doubt this is a no brainer, but I can't solve it. Many Thanks Who ever you are.
hi. we have 1 production database and a 2nd backup database. one of our users accidentally deleted a case and we would like to get it back. our production database is updated nightly so none of the case's information would've changed.
how can i insert the data from the backup database to the production database? i need to copy one row. thanks for your help!
Is is possible to insert a record through a view. If so, how?
USE Northwind
GO
CREATE TABLE tbForms ( FormID INT IDENTITY (1,1) NOT NULL, Form varchar (100) NOT NULL )
GO
ALTER TABLE tbForms ADD CONSTRAINT tbForms_pk PRIMARY KEY (FormID) GO
CREATE TABLE tbDoubleTeeForms ( fkFormID INT NOT NULL, Form varchar(100) NOT NULL, Width FLOAT, Height FLOAT, Flange FLOAT, Leg FLOAT, LegCount INT )
GO
ALTER TABLE tbDoubleTeeForms ADD CONSTRAINT tbDoubleTeeForms_pk PRIMARY KEY (fkFormID) GO
ALTER TABLE tbDoubleTeeForms ADD CONSTRAINT tbDoubleTeeForms_fk FOREIGN KEY (fkFormID) REFERENCES tbForms (FormID) GO
CREATE TABLE tbFlatPanelForms ( fkFormID INT NOT NULL, Form varchar(100) NOT NULL, Width FLOAT, HEIGHT FLOAT )
GO
ALTER TABLE tbFlatPanelForms ADD CONSTRAINT tbFlatPanelForms_pk PRIMARY KEY (fkFormID) GO
ALTER TABLE tbFlatPanelForms ADD CONSTRAINT tbFlatPanelForms_fk FOREIGN KEY (fkFormID) REFERENCES tbForms (FormID) GO
CREATE VIEW MyProducts AS SELECT fkFormID, Form FROM tbDoubleTeeForms UNION ALL SELECT fkFormID, FOrm FROM tbFlatPanelForms
GO
-- How can I insert a new record, the pk of the forms table is identity. -- Can this be done? INSERT INTO MyProducts (Form) VALUES ('My First Entry') GO
Using trigger want to update a field being inserted from another record in the same table.
the record being inserted I want to pull the bkjrcode from another record where the account = 1040 that also has the same ord# and inv# as the record being inserted.
Here is what I've tried with no luck.
create trigger [updategbkmut] on [dbo].[gbkmut] after insert as
update g1 set g1.bkjrcode = g2.bkjrcode from gbkmut g1 inner join inserted i on i.ord_no = g1.ord_no and i.inv_no = g1.inv_no inner join gbkmut g2 on i.ord_no = g2.ord_no and i.inv_no = g2.inv_no where i.freefield3 = 'Rebate' and g1.account = '1040'
George writes "SQL server 2005 Express, Windows XP Pro SP2
I want to create a stored procedure that will insert a record in a child table (tblcontproj)propulating two columns with columns from the parent (InterestListoriginal)and two columns with user selected values. I created an insert select statement that looks like ..
" INSERT INTO tblcontproj(proj_rpt_id, proj_name) SELECT proj_rpt_id, project_name FROM InterestListoriginal WHERE (proj_rpt_id = @proj_rpt_id)"
This works great! Now can I add two columns to the INTO clause for projcontshortname and projconttye and use a VALUE clause that sets tblcontproj.projcontshortname and tblcontproj.projconttype to @projcontshortname and @projconttype which are user selected values from a downdownlist.
i have a table name is HH tableit has two columns 'hhno' and hhname'HH tabelehhno hhname100 suresh101 baba103 rami want to insert a one record(102 , chandra) in HH table between(101,baba) and( 103 ,ram).how can i insert them please help ,me thanks
Hi everyone:Using Sql Server SQL 8I'm trying to INSERT records into a "can software package" batchtable. I have a work-table that mimics the batch table. Aftermanipulating the records in the work-file I want to INSERT them intothe batch table.The problem is the batch table in the can software has a trigger onthe batch table which is going to force me to INSERT one record at atime. I've always been able to do an INSERT with no problem.The batch table has pretty basic columns:BatchIDBatchDateSeqNumberThese three fields are the key and then just some miscellaneouscolumns. Any easy way to loop thru my work-file to insert theserecords. Never done a loop in SQL so an example would be reallyreally appreciated. I have a sequence number so I was hoping to do aWhile loop but I really don't know enough about creating a loop tomake that call. Thanks in advance for any help.