Insert Simultaneously In 2 Tables

Sep 9, 2006

Dear All,

I am not an expert on T-SQL and I am trying out a small project to learn.

I
have encountered a problem, whereby I have 2 tables, 1 containing the
header (header_id, header_file, admin_menu_id and admin_submenu_id) and
then I have another table called header_details, where I am storing the
language details for this header, with the fields being
(header_details_id, fk_header_id, header_alt, header_caption and
fk_language_id)

Now I want to create a stored proc, first to
insert the header and then the header details. I also want that if the
header or header details already exist, I just do an update on these
tables.

I tried the following code but its not working:-

ALTER Procedure [dbo].[INSERT_Header]
(
@admin_menu_idint,
@admin_submenu_idint,
@header_filevarchar(150),
@header_altvarchar(150),
@header_captionvarchar(200),
@language_idint
@outIDint OUTPUT
)
AS
BEGIN

-- First do a select on the header table to see if this header already exists

DECLARE @count integer = 0

SELECT COUNT(*) as @count
FROM headers
WHERE[fk_admin_menu_id] = @admin_menu_id
AND[fk_admin_submenu_id] = @admin_submenu_id

--if it exists, then update this header
IF @count > 0
BEGIN
UPDATE [headers]
SET [header_file]= @header_file

WHERE [fk_admin_menu_id] = @admin_menu_id
[fk_admin_submenu_id] = @admin_submenu_id
ELSE
-- Insert header in header table --
BEGIN
INSERT INTO [headers]
([header_file]
,[fk_admin_menu_id]
,[fk_admin_submenu_id])
VALUES
(@header_file
,@admin_menu_id
,@admin_submenu_id)
-- Get the Inserted Header ID --
SET @outID = SCOPE_IDENTITY()
END

-- Now do a select on the header_details table to see if this header with this language already exists
DECLARE @count_details integer = 0

SELECT COUNT(*) as @count_details
FROM header_detail
WHERE[fk_admin_menu_id] = @admin_menu_id
AND[fk_admin_submenu_id] = @admin_submenu_id
AND[fk_language_id] = @language_id

--if it exists, then update this header
IF @count_details > 0
BEGIN
UPDATE [header_detail]
SET[header_alt]= @header_file
,[header_caption] = @header_caption

WHERE [fk_header_id] = @header_id
[fk_language_id] = @language_id
ELSE
-- Insert header in header table --
BEGIN
INSERT INTO [header_detail]
([fk_header_id]
,[header_alt]
,[header_caption]
,[fk_language_id])
VALUES
(@@out_ID
,@header_alt
,@header_caption
,@language_id)
END


END


Can you help me out please?

Thanks a lot for your help and time

Johann

View 2 Replies


ADVERTISEMENT

Updating/Deleting Multiple Tables Simultaneously

Mar 1, 2005

Hi,

I'm using ASP with a JScript variant and MSSQL Server 2000. I would like to write a script that basically erases all data except for a few things.

Is there a way to update multiple tables at once without having to write lines and lines of code? I tried UPDATE tbl1,tbl2 SET uid='asc', but to no avail. It gave me a syntax error. My thinking behind it is something like... UPDATE dbo.* SET uid='mferguson' and after that I can delete stuff like DELETE dbo.*... Any ideas?

I know the above is ASP, I've tried this thread in the ASP forum with no avail... they referred me to this forum.

View 1 Replies View Related

Integration Services :: Update Simultaneously Whenever Insert New Data In Both Database

Aug 10, 2015

Am using SSIS to integrate between two database. First one is insert data from SQL to Sybase. its working fine and insert simulatenously. Now need to update table from sybase to SQL with condition(where). How to do this task. Is there any possiblities to execute SSIS without using SQL agent,  update simultaneously whenever insert new data in both database.

View 8 Replies View Related

Cannot INSERT Data To 3 Tables Linked With Relationship (INSERT Statement Conflicted With The FOREIGN KEY Constraint Error)

Apr 9, 2007

Hello
 I have a problem with setting relations properly when inserting data using adonet. Already have searched for a solutions, still not finding a mistake...
Here's the sql management studio diagram :

 and here goes the  code1 DataSet ds = new DataSet();
2
3 SqlDataAdapter myCommand1 = new SqlDataAdapter("select * from SurveyTemplate", myConnection);
4 SqlCommandBuilder cb = new SqlCommandBuilder(myCommand1);
5 myCommand1.FillSchema(ds, SchemaType.Source);
6 DataTable pTable = ds.Tables["Table"];
7 pTable.TableName = "SurveyTemplate";
8 myCommand1.InsertCommand = cb.GetInsertCommand();
9 myCommand1.InsertCommand.Connection = myConnection;
10
11 SqlDataAdapter myCommand2 = new SqlDataAdapter("select * from Question", myConnection);
12 cb = new SqlCommandBuilder(myCommand2);
13 myCommand2.FillSchema(ds, SchemaType.Source);
14 pTable = ds.Tables["Table"];
15 pTable.TableName = "Question";
16 myCommand2.InsertCommand = cb.GetInsertCommand();
17 myCommand2.InsertCommand.Connection = myConnection;
18
19 SqlDataAdapter myCommand3 = new SqlDataAdapter("select * from Possible_Answer", myConnection);
20 cb = new SqlCommandBuilder(myCommand3);
21 myCommand3.FillSchema(ds, SchemaType.Source);
22 pTable = ds.Tables["Table"];
23 pTable.TableName = "Possible_Answer";
24 myCommand3.InsertCommand = cb.GetInsertCommand();
25 myCommand3.InsertCommand.Connection = myConnection;
26
27 ds.Relations.Add(new DataRelation("FK_Question_SurveyTemplate", ds.Tables["SurveyTemplate"].Columns["id"], ds.Tables["Question"].Columns["surveyTemplateID"]));
28 ds.Relations.Add(new DataRelation("FK_Possible_Answer_Question", ds.Tables["Question"].Columns["id"], ds.Tables["Possible_Answer"].Columns["questionID"]));
29
30 DataRow dr = ds.Tables["SurveyTemplate"].NewRow();
31 dr["name"] = o[0];
32 dr["description"] = o[1];
33 dr["active"] = 1;
34 ds.Tables["SurveyTemplate"].Rows.Add(dr);
35
36 DataRow dr1 = ds.Tables["Question"].NewRow();
37 dr1["questionIndex"] = 1;
38 dr1["questionContent"] = "q1";
39 dr1.SetParentRow(dr);
40 ds.Tables["Question"].Rows.Add(dr1);
41
42 DataRow dr2 = ds.Tables["Possible_Answer"].NewRow();
43 dr2["answerIndex"] = 1;
44 dr2["answerContent"] = "a11";
45 dr2.SetParentRow(dr1);
46 ds.Tables["Possible_Answer"].Rows.Add(dr2);
47
48 dr1 = ds.Tables["Question"].NewRow();
49 dr1["questionIndex"] = 2;
50 dr1["questionContent"] = "q2";
51 dr1.SetParentRow(dr);
52 ds.Tables["Question"].Rows.Add(dr1);
53
54 dr2 = ds.Tables["Possible_Answer"].NewRow();
55 dr2["answerIndex"] = 1;
56 dr2["answerContent"] = "a21";
57 dr2.SetParentRow(dr1);
58 ds.Tables["Possible_Answer"].Rows.Add(dr2);
59
60 dr2 = ds.Tables["Possible_Answer"].NewRow();
61 dr2["answerIndex"] = 2;
62 dr2["answerContent"] = "a22";
63 dr2.SetParentRow(dr1);
64 ds.Tables["Possible_Answer"].Rows.Add(dr2);
65
66 myCommand1.Update(ds,"SurveyTemplate");
67 myCommand2.Update(ds, "Question");
68 myCommand3.Update(ds, "Possible_Answer");
69 ds.AcceptChanges();
70

and that causes (at line 67):"The INSERT statement conflicted with the FOREIGN KEY constraint
"FK_Question_SurveyTemplate". The conflict occurred in database
"ankietyzacja", table "dbo.SurveyTemplate", column
'id'.
The statement has been terminated.
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
at AnkietyzacjaWebService.Service1.createSurveyTemplate(Object[] o) in J:\PL\PAI\AnkietyzacjaWebService\AnkietyzacjaWebServicece\Service1.asmx.cs:line 397"


Could You please tell me what am I missing here ?
Thanks a lot.
 

View 5 Replies View Related

SQL 6.5 And SQL 7.0 Simultaneously Active On Same Host

Mar 26, 1999

Has anyone developed a workaround to have SQL 6.5 and SQL 7.0 simultaneously active on the same NT 4.0 Server host. The use of VSWITCH.EXE to switch between SQL 6.5 and SQL 7.0 in not an acceptable solution. There are several applications that are only supported under SQL 6.5 and will not be upgraded to SQL 7.0 for another 3 to 6 months.

There are other applications (ERP and data mart) that were developed specifically for SQL 7.0 to take advantage of its new DTS, OLAP, and query capabilities.

All these applications need full-time access to their respective databases.

The obvious solution is to host SQL 6.5 and SQL 7.0 on separate servers. The client has a "monster" database server which would be too expensive to duplicate. Using a "standard" PC to host SQL 6.5 would significantly compromise performance of those applications.

Any advice or suggestions would be appreciated.

Andrew Dominguez, IMS
ajd@cwix.com
909.625.4066 / 7826 fax

View 3 Replies View Related

Databases Updating Simultaneously

Aug 31, 2006

Hi,I have managed to create a second copy of my "live" database, forsoftware testing purposes.Inspecting the properties of the new database, everything seems inorder. The logical file name is the same, which I believe is fine, andthe physical database (and log file name) is different.However, despite the fact that there is no application currentlyaccessing the "testing" copy, both databases are seemingly beingupdated simultanously. I can tell this from the physical file sizes onthe server, which are identical, and growing at the same rate.Does anyone have any suggestions why this might be happening - and howI can stop it?Thanks in anticipation!Phil

View 1 Replies View Related

Using SQL 2005 And 2000 Simultaneously

Feb 29, 2008

Hi all,
I need SQL Server 2000 on the server, where SQL Server 2005 has been already installed. So I install SQL Server 2000 Instance as Named one. And everything is ok now when I connect locally from that server (SQL Server 2000 Instance is accessable both in SQL Server 2000 Enterprise Manager and SQL Server 2005 management Studio) and Default (SQL Server 2005 Instance) also works. But when I try to connect from SQL Server 2005 Management Studio (located on the other server) - only default instance is successfully connected, the named one - give an error:

TITLE: Connect to Server
------------------------------
Cannot connect to SERVERAMED_INSTANCE.
------------------------------
ADDITIONAL INFORMATION:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------

so I think smth wrong with using ports simultaneuosly.
For SQL Server 2005 Remote Connections are allowed both for TCP/IP and Named Pipes.
Default TCP Port: 1433

In SQL Server 2000 I didn't find where to allow remote connections.
After insallation in Server Network Utility - default TCP port - 0, in Client Network Utility - 1433.

I have already tried to replace 0 with 1433 - nothing changes,
and use 1434 both in Server and Client Network Utility - nothing changes.

I need a remote connect to SQL Server 2000 Instance.
I hope the answer exists. Thanks to any ideas.

View 14 Replies View Related

Run A Procedure And A Query Simultaneously

Dec 17, 2007

Hi,
I have requirement where I need to show the table sizes of each table in database. For this, I have written a procedure that finds the sizes and loads into a table.
In my report, I should be able to run the procedure and select the rows from the table that I loaded the data into.

Is this possible to run the SP and then run query to get rows when a user clicks view report?

View 5 Replies View Related

Insert Records From Foxpro Tables To SQL Server Tables

Apr 22, 2004

Hi,

Currently, I'm using the following steps to migrate millions of records from Foxpro tables to SQL Server tables:

1. Transfer Foxpro records to .dat files and then bcp to SQL Server tables in a dummy database. All the SQL tables have the same columns as the Foxpro tables.
2. Manipulate the data in the SQL tables of the dummy database and save the manipulated data into the SQL tables of the real database where the tables may have different structure from the corresponding Foxpro tables.

I only know the following ways to import Foxpro data into SQL Server:

#1. Transfer Foxpro records to .dat files and then bcp to SQL Server tables
#2. Transfer Foxpro records to .dat files and then Bulk Insert to SQL Server tables
#3. DTS Foxpro records directly to SQL Server tables

I'm thinking whether the following choices will be better than the current way:

1st choice: Change step 1 to use #2 instead of #1
2nd choice: Change step 1 to use #3 instead of #1
3rd choice: Use #3 plus manipulating in DTS to replace step 1 and step 2

Thank you for any suggestion.

View 2 Replies View Related

Change PrimaryK &ForeignK Value Simultaneously

Apr 4, 2008

Hi, can anyone help me with this? I need to write a proc to update all the tables in database with EmpNo where Employee is the master(Parent-table).

View 1 Replies View Related

Read Data From Two Files Simultaneously

Oct 17, 2007

Hello,

I have 2 tables EmployeeA(Eng) and EmployeeB(Spanish) kept in seperate mdb's. I want to add the records into Sql Server 2005 table called StateEmployee.

Procedure:
1. Loop through 2 folders..one containing table EmployeeA in mdb and other containing tbl EmployeeB in diff mdb's.
2. Pick a file from EmployeeA and EmployeeB, both at the same time.
3. Count the total no of rows in both files. If equal proceed.
4. Compare the 'employeeid' of one row of employeeA to the employeeid of EmployeeB.
5. If employee id matches, load both the rows in Sql server else file it to the error table.
6. Loop through all rows simultaneously till end of row.
7. Go to next mdb.

How do i go about this step by step. I am fairly new to SSIS.

View 1 Replies View Related

Running SQL 2000 And SQL 2005 Simultaneously

Sep 6, 2007

I have seen information on the web about running two versions of SQL at the same time on the same server but was wondering any tricks of the trade regarding it. The main recommendation that I have seen is to have SQL 2000 SP4 running first as the default instance (which is my current situation on a development server) and then install SQL 2005 as a named instance on it. Should the SQL 2005 installation place its files in a dedicated directory (ie, C:SQL2005) as opposed to the default directory that the installation would normally write to, thus not overwriting any SQL 2000 system files? Any other recommendations?

View 1 Replies View Related

SQL 2012 :: Restore 2 Database Simultaneously In Same Instance?

Apr 10, 2014

Is it possible to restore two databases simultaneously in same sql instance?

View 3 Replies View Related

Backup Transaction Logs And Replication Simultaneously

Jul 20, 2005

Is there any problem with implementating some kind of replication andbacking up transaction logs at the same time? SQL Server 2000 StandardEditionThe server is configured to back up log files regularly, with thepresenceof a(New) Disaster recovery server and with an inability forstandby(Standard Edition)I am planning to implement some kind ofreplication hopefully still backing up the transaction logs to enablea point in time recovery.Thanks in advance for your great ideasVincento

View 1 Replies View Related

SQL Server 2000 And 2005 Simultaneously Issues?

Dec 17, 2007

Hi!

Is it possible to have both servers installed and not having issues?
I am really new to this.
At my company we have both installed. At home I created a backup of a database in SQL Server 2005 but can not restore it here were we have both.

The message I got is: System.Data.SqlClient.SqlError: The backed-up database has on-disk structure version 611. The server supports version 539 and cannot restore or upgrade this database.

So I think it seems that even though I'm trying to restore it in 2005 this version still uses the old server or something.

I hope I made it clear enough.

Please help.
Thanks.

View 5 Replies View Related

Can Multiple Users Access The Same Report Simultaneously?

Aug 24, 2007

We are currently using Crystal reports but are considering using SQL RS. We need to know if there is a restriction on simultanoeus access to the same report by multiple users? What happens when multiple users try to access the same report simultaneously? If reports can be accessed simultaneously, do the requests queue up or are they processed concurrently?

Any help on this issue is greatly appreciated.

View 7 Replies View Related

Updating And Deleting Parent And Child Table Simultaneously

Jul 20, 2005

I have two table both say A and B.If i insert a record in A that record should be inserted in B.If i delete a record in A that record should be deleted from B.Is that possible.If yes please tell me.Thankyou in advance,vishnu

View 3 Replies View Related

Restoring Multiple Backup Files Simultaneously To New Server

Mar 5, 2007

Alright, here's the deal. I'm testing some backup/restore strategies, and hitting a (slight) sticking point.

We've got collections of database and log backups created by the usual maintenance plans on a 2000 Enterprise machine. I'm trying to run through a restore onto a new 2005 machine (Developer Edition on my test workstation) using the collection of .bak and .trn files copied from the 2000 server. When I try to restore to a new database on 2005 via SSMS, and select all the .bak and .trn files for the restore, I get the ol' "The volume on device '[trimmed]' is not part of a multiple family media set. BACKUP WITH FORMAT can be used to form a new media set." error.

I'm assuming this just means that SQL Server can't verify that these log backups are in fact part of a functional "set", even if they aren't part of a traditional backup media set. Is there any way to tell SSMS, "It's okay man, just restore the database from these files, in this order - trust me," or is the only solution restoring every individual log file one at a time? (Which seems to work fine, though is a tremendous pain with any more than a few log backups.) Seems like there ought to be a good one-shot method to restore a bunch of backups to a different server, and I'm just not finding it.

View 4 Replies View Related

Run Simultaneously Msde 2000 Instance And One Of 2005 Express, Possible?

Dec 2, 2006

Hi,
I got on my developer computer one instance of msde 2000. I want to test sql server express 2005, can I install it without "scrap" my other instance of 2000?

Strange question maybee, but it's what I wanna do!

Thanks all!

View 3 Replies View Related

Lookup Concurrency Issue In Packages Running Simultaneously In Parallel

Mar 27, 2007

I have a system of SSIS packages in which several packages perform the same lookup on the same table. E.g., i have PackageA, PackageB and PackageC all doing a lookup on TableA. All of these packages are spawned by the same PackageD and run frequently. In some cases, there is an issue with concurrency on these lookups. I get the following exception :

"
The ProcessInput method on component "LKP Lookup SecurityID" (6658) failed with error code 0xC004702C. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.

"



The hex code of this exception corresponds to the following description : "DTS_E_BUFFERNOTLOCKED. This buffer is not locked and cannot be manipulated." That's as much as i could find on this.



My suspision is that the SSIS engine somehow figures that the lookup in these distinct packages is the same one and builds a shared version of the lookup table in memory. Then there is some sort of a multi-threading issue in accessing this shared memory which leads to the exception above.



Has anyone experienced this? Can someone shed some light on this?



Thanks a lot



-Alex

View 15 Replies View Related

Wrong Evaluation Of A Variable With Expression In Case It Is Used Simultaneously By Several Tasks

Aug 22, 2007



Hi guys,

I have experienced problem while trying to use variable with expression based on several other variables in tasks running parallel.

The details are as following:

There is a SSIS package with simple Control flow: one Script Task which actually do nothing and two Execute Process Tasks, they run after Script Task in parallel. Then there are three simple (EvaluateAsExpression = False) string variables ServerName, Folder and JobNumber with values ServerName = €œ\test€?, Folder = €œtest€? and JobNumber = €œ12345€?. And there is one variable FullPath with expression @[User:: ServerName] + "\" + @[User::Folder] + "_" + @[User::JobNumber]. All the variables are of the Package scope. Then in Execute Process Tasks I have similar expressions based on FullPath variable: Execute Process Task 1 has expression @[User::FullPath] + "\date.bat" and Execute Process Task 2 has @[User::FullPath] + "\time.bat" one. As you understand these expressions define what exactly task should execute.

Then I€™m going to execute package from command line so appropriate XML configuration file has been created. The file contains following values for variables described above: ServerName = €œ\LiveServer€?, Folder = €œJob€? and JobNumber = €œ33091€?.

After series of consequent executions I have got following log file:

€¦ Execute Process Task 1€¦ Executing the process €œ\LiveServerJob_33091date.bat€?

€¦ Execute Process Task 2€¦ Executing the process €œ\Test est_12345 ime.bat€?



€¦ Execute Process Task 1€¦ Executing the process €œ\Test est_12345date.bat€?

€¦ Execute Process Task 2€¦ Executing the process €œ\LiveServerJob_33091 ime.bat€?



€¦ Execute Process Task 1€¦ Executing the process €œ\LiveServerJob_33091date.bat€?

€¦ Execute Process Task 2€¦ Executing the process €œ\Test est_12345 ime.bat€?



€¦ Execute Process Task 1€¦ Executing the process €œ\LiveServerJob_33091date.bat€?

€¦ Execute Process Task 2€¦ Executing the process €œ\LiveServerJob_33091 ime.bat€?



€¦



As you can see one of Execute Process Tasks usually receive correct value of the expression (based on values of variables from the configuration file) while another - incorrect one (based on €œdefault€? values of variables set directly in package). Sometimes wrong value appears in Task 1, next time in Task 2. Situations when both expressions in tasks evaluated correctly are very rare.

Then if you add some more Execute Process Tasks with similar expressions in the package (for ex. simply by copying existing tasks) you€™ll get a good chance to catch error like this:



OnError,,,Execute Process Task 1,,,8/17/2007 2:07:12 PM,8/17/2007 2:07:12 PM,-1073450774,0x,Reading the variable "User::FullPath" failed with error code 0xC0047084.



OnError,,,Execute Process Task 1,,,8/17/2007 2:07:12 PM,8/17/2007 2:07:12 PM,-1073647613,0x,The expression "@[User::FullPath] + "\time.bat"" on property "Executable" cannot be evaluated. Modify the expression to be valid.



Seems variable with expression FullPath is locked during evaluation by one of the parallel tasks in such a way that another task can€™t read it value correctly. Can someone help me with the issue? Maybe there are some options I missed which could prevent such behavior of application? Please let me know how I can make the package work correctly.

View 5 Replies View Related

How Do You Insert Into Two Tables From One Insert? Or Even How Would You Using Two Inserts?

Mar 18, 2007

I currently insert into one table with:                 SqlCommand comm = new SqlCommand("INSERT INTO UsersTable (UserName, Password, Email) VALUES (@person, @pass, @email)", sqlConnection);                comm.Parameters.AddWithValue("@person", usrnmeLbl.Text);                comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text);                comm.Parameters.AddWithValue("@email", hemailLbl.Text);but I realized that there's another table related to this table and I need to have something go in it so that the users data will be recorded at the same pace. So I tried:                 SqlCommand comm = new SqlCommand("INSERT INTO UsersTable, FatherHistTable (UserName, Password, Email), (Father) VALUES (@person, @pass, @email), (@father)", sqlConnection);                comm.Parameters.AddWithValue("@person", usrnmeLbl.Text);                comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text);                comm.Parameters.AddWithValue("@email", hemailLbl.Text);                comm.Parameters.AddWithValue("@father", fthrsNmeLbl.Text);Not working, so I am thinking I must do two inserts:                  SqlCommand comm = new SqlCommand("INSERT INTO
UsersTable (UserName, Password, Email) VALUES (@person, @pass,
@email)", sqlConnection);
                comm.Parameters.AddWithValue("@person", usrnmeLbl.Text);
                comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text);
                comm.Parameters.AddWithValue("@email", hemailLbl.Text);                 SqlCommand comm2 = new SqlCommand("INSERT INTO
FatherHistTable (Father) VALUES (@father)", sqlConnection);
                comm2.Parameters.AddWithValue("@father", fthrsNmeLbl.Text); Is that the only way to go about it then? Thanks in advance for any explanations. 

View 26 Replies View Related

Insert 2 Tables

Dec 19, 2006

Please i need to insert two tables at a time. One is Delivaries and the other is DelivaryDetails. This is the Structure:
DelivariesDelivaryId...........Int Primary Key IdentityDelivaryNo.........nvarcharDelivaryDate......datetime
DelivaryDetailsDelivaryId............Int Primary Key Foreign KeyProductId............Int Foreign KeyQty....................Int
I have created a StoredProcedure named InsertDelivaries
CREATE PROCEDURE InsertDelivaries@DelivaryId int output,@DelivaryNo nvarchar(20),@DelivaryDate datetime
AS
insert into Delivaries values(@DelivaryNo,@DelivaryDate)
but this does not insert the records as expected. Please help

View 5 Replies View Related

Insert Between Two Tables

Apr 10, 2007

hello..
I think this is common question, but i still dont get answer from all past topic and thread.
My problems is:
I have two tables,
1) company_info (com_ID(Primary key with increment int), name, add, contact_no)
2) company_detail(com_ID(Primarykey without increment), product, quantity)
 I want capture the data com_ID from 1st table and at the same time I want to insert into 2nd tables. How the way??
currently I do in table adapter in data set.
I also looking how to use store procedures? my knowledge about store proceduree is zero and really need articles or tutorial from any website. anylink?
One more things, I also which part i should do the relationship, in dataset or at database diagram?
I really lack in this database knowledge
Thank you
 

View 3 Replies View Related

Insert Into Tables

Dec 18, 2007

hello my friends
 i have a database with 5 tables : 1-Company 2-Activity 3-Product 4-Project 5-Telephone
each table have a one to many relation with Company Table ! i mean a Company can has many Activities,Products,Projects,Telephones i want to insert in tables at a same time insert into Company table ! i know that i should first insert into company Table and get CompanyID that need to insert in other tables. i hear that i can do this with define a VIEW of joining these tables and use trigger!i dont know how !?
 I'll appreciate you to help me :O)

View 4 Replies View Related

INSERT INTO Two Tables At Once?

Feb 22, 2008

I am using Framework 3.5 with VS2008 writing VB code to put and get data in a SQL 2005 Server database. 
How to fill out a form, and on one submit button click, send some information into one database table and different information into a different table?
Those tables of mine have a common key, but one is about where and when and what work needs to be done and the other is about authorization, departments and funds.
I’d just think that I should be able to do that in one InsertCommand="INSERT INTO …� statement and not have to code a whole new <asp:SqlDataSource ID="SqldsDOIT" runat="server" interface for the second table … which is the work-around that I can do … it just seems ignorant to me, when we are told to keep like-things in separate tables (normalization).
In other words, the following fails to run ... if I only INSERT INTO Job( or only INSERT INTO Signatory( ... it's all good.A little help please.  I've scanned through the forums, but not found exactly this addressed. <asp:SqlDataSource ID="SqldsDOIT" runat="server"     ConnectionString="<%$ ConnectionStrings:DOITWorkOrderConnectionString %>"     SelectCommand="SELECT FROM [Job] JOIN [Signatory] ON Job.Jobnumber = Signatory.Jobnumber"    InsertCommand="INSERT INTO Job(Datereq, ..., Jobcomm) VALUES(@Datereq, ..., @Jobcomm)    INTO Signatory(BillProgram, ..., Sigemail) Values(@BillProgram, ..., @Sigemail)">    <InsertParameters>
 

View 4 Replies View Related

Insert Two Tables In One

Sep 5, 2001

I want to insert records from two tables into one table as the record is concatenated from both the tables and then put it into the one table.

How can we do that so that i can take the records from the one table..?

CREATE PROCEDURE SP_P31
AS


select 'CA'+'|'+COMPANY+'|'+COMPANYNAME+'|'+CUSTOMERNUMBE R+'|'+COMPANYPHONE
+'|'+COMPANYFAX+'|'+FEDTAXID+'|'+DUNSNUMBER+'|'+S1 099+'|'+DUNSSUFFIX+'|'+convert(char,ADDRESSSEQ)
+'|'+COUNTRY+'|'+ADDRESSTYPE+'|'+ADDRESS1+'|'+ADDR ESS2+'|'+ADDRESS3+'|'+ADDRESS4
+'|'+CITY+'|'+STATE+'|'+ZIP+'|'+FAXNUMBER hello1 into temp32
from v4

select 'CT'+'|'+COMPANY+'|'+CONTACTNAME+'|'+CONTACTTYPE+' |'+CONVERT(CHAR(10),CONTACTADDRESS)
+'|'+PHONE+'|'+FAX+'|'+TITLE hello INTO temp32
from v3

View 3 Replies View Related

INSERT Into 2 Tables

Mar 8, 1999

Does SQL allow you to insert data into 2 related tables simultaneously?

I have a form where the user enters in Name, Age, SocialSecurity,
Address. The Address table is a separate table than the Individual
table. How do I insert into both ??? Both tables are tied with a unique Individual_ID which is system generated.
I am using a stored procedure

Thanks alot!!
Joyce

View 1 Replies View Related

Insert To Two Tables

Oct 19, 2007

I posted this question previously but am now getting another error and fixing it (months ago). I am trying insert The ID2 column (pk) from table 2 into ID2 column (fk) of table 1. What the T-SQL is trying to do is check to see if the record in table 2 already exists in then just pass the value to the insert query for table 1. If the record does not exist then insert data into table 2first then perform the table 1 insert.

This SP works fine if the user does not exist in table 2. However, if the user does exist in table2 then instead of passing the ID, a null value is passed.

Can anyone tell me why the first query does not work? If there is an easier way of doing this then I am all ears.

Thank you


DECLARE @IdentityHolder int

BEGIN TRANSACTION
IF EXISTS (SELECT ID2 FROM [tbl2] WHERE ID2 = @ID2)
BEGIN
(SELECT ID2 FROM [tbl2] WHERE ID2 = @ID2)
END
ELSE
BEGIN
INSERT INTO [tbl2] ([ID2], [FN], [LN], emailAdd])
VALUES ( @ID2, @fName, @lName, @emailAdd)
END
COMMIT

SET @IdentityHolder = (ID2)
INSERT INTO [tbl1]([ID2], [event])
VALUES (@ID2, @event)

View 14 Replies View Related

Insert Into 2 Tables

Dec 12, 2007

Hi i have a stored prodedure which inserts into a local table then inserts into a remote table this works fine, what i need to do is.

INSERT ONTO TABLE A

THEN GET THE MAX(ID) OF THE RECORD INSERTED

THEN INSERT THAT MAX(ID) INTO TABLE B

i have created a parameter called @WebID but how do i give it the value of the MAX(ID) before i insert into tableB

Many thanks

View 2 Replies View Related

Insert Value From Another Tables

May 18, 2008

Good evening every body.

I have 3 tables ( customer, product and order).
Customer table contain customer_id as a primary key
Product table contain product_id as a primary key
Order table contain both customer_id and product_id

I want to insert the values from customer and product to order.

Any help?

View 7 Replies View Related

Getting Value In Tables And Insert To Other Tables

Feb 7, 2008

I want to compare two tables. if the data is existed to the other table i will insert it to other table if not exist it will load also to diffrent table.
Example: if my table was Tbl_StudentID and Tbl_FacultyID i want to insert in tbl_Grade if the data in Tbl_StudentID is exist or present in Tbl_FacultyID . And if the Tbl_StudentId is not exist in Tbl_FacultyID the data will move to Tbl_SupervisorID.

Please Help..

View 3 Replies View Related

Insert Into Two Tables Sqldatasource

Jun 30, 2006

Coming from an asp world, I am totally lost on this one.
I have two tables.
tblUsers and tblUserInfo
I have a gridview that gives me the list of users and when selected, it gives me the detailsview of the the record.  However, When I need to add a new user, I am trying to add that user into tblUsers (which happens with no problems), and then add a record, using the same user number (UserID) has the key or ID for the tblUserInfo.
So basicly, when I create a new user in tblUsers I want to create a record in tblUserInfo with the same userid.
In ASP, this takes me minutes... I have been trying to figure this out for weeks.
vs2005, sql express.
Thanks.

View 1 Replies View Related







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