SQL Server/T-SQL - Update Multiple Tables At A Time ?
May 21, 2010
I have two tables, Customer and CustomerPhone.
Single record in Customer can have multiple CustomerPhone records. As you see in the image below, Phone and Fax resides in CustomerPhone table whereas the rest of the fields resides in Customer table. If user want to edits a customer record, obviously i will have to update the record in Customer table and at least two records from CustomerPhone (Phone and Fax).
I could write two update statements, one Update customerPhone and the second update Customer table. Is there a better solution?
View 2 Replies
Similar Messages:
Feb 21, 2011
I'm trying to insert into more than one table at the same time. My code below is not working.
[Code]....
I'm wondering if I do the following:
[Code]....
View 11 Replies
Mar 28, 2010
I have 10 tables in MSSQL I want to select some info from this tables and show on a webpage (formview maybe(based on user selection)). Also, Id like user to be able to EDIT this info, and it should go back to database.
The problem is that: the realtionships are pretty comprehensive. In sql management studio I saw awesome view creation, where u can drag and drop tables and select just the field u need, and it automatically do all joins for you.
View would work perfect for me, but i need to update database back. Maybe I can use linq classes?
I mean, its easy, but it takes a lot of time to do it by hand programatically. Is there some dragandgrop-like feature in visual studio?
what is the easiest way to bind multiple tables in one place with crud operations available?
sql datasource supports only 1 table at a time.
I Found on the web that we can use stored procedure? Do I need two stored procedures? for select and update? how we are going to bind update procedure with textobxes where user is going to edit info? Do you have some samples?
View 1 Replies
Apr 4, 2012
I have a requirement like need multiple update panel in web page and also i want to load only one (targeted one) update panel content when I click button on another update panel.
View 1 Replies
Nov 29, 2010
I have a asp:DetailsView control with the first column are the field headers and the second column is the record details for a given user.
The DetailsView is bound from 4 tables, I need to be able to edit/amend any field. Is there another way I can achieve this from the DetailsView? Would I need to create templates for each table entry then Update SET on each template, would that do it?
View 8 Replies
Mar 3, 2011
I have 2 tables
One:Table Name Rider With columns RiderID,LName,City
Two:Table Name Car With columns CarID,RiderID,Color
What I would like to be able to do is to allow the users to do an UPDATE on both tables.
Like if you crreated a SQLDataSource using just one table as it's source. You can use that SQLDataSource for a gridview.
Then in the gridview you can display all the data from the table but you can also EDIT all the data in the table through the gridview.
But if I create a SQLDataSource using 2 table joining them together with an INNER JOIN with a Primary Key in one table and a Foriegn Key in the other table. I can still use this SQLDataSource with a GridView to display the data but I can't EDIT the data through the gridview for the 2 tables.
Is there anyway to do this using a SQLDataSource and GridView?
OR is there another way to accomplish this?
View 3 Replies
Sep 23, 2010
I need to insert/update data to 3 or more tables on a single button click.What is best method for achieving this?I am using mysql as my DB.
View 2 Replies
Aug 13, 2010
How to insert values in four tables at a time......
These tables are having primary key and foreign keys...
View 3 Replies
May 21, 2010
I have to update the users based on input value..
here is my code..
<fieldset>
<legend>StudnetInfo</legend>
here i have two textboxes and two dropdown list boxes.. this is the fiedlset user is going to enter their information..
</fieldset>
on the same page i have couple of other Fieldset with there studentInfo with twotextboxes and two dropdownlistboxes smililarly above Fieldset..this data dynamically generated from database for each users.
so all here my intension is insted of updating each and every Fieldset i made one generic fieldset to update all other Fieldsets information
on the Generic view I have this BeginForm
<% using (Html.BeginForm("Update", "home", FormMethod.Post,
new { @id="studentid"}))
{ %>
my JsonResult is
public JsonResult Update(StudentBE e)
{
try
{
var UStatus = Generic.UpdateStudent(e.student,"","");
return Json(UStatus.ToString());
}
catch (Exception ex)
{
return Json(ex.ToString());
}
finally
{
}
}
using this I can update only one user perfectly but I need to loo update all users based on generic Filedset values?
View 1 Replies
Jul 24, 2010
I am accessing rows in an SQL database table based upon the contents of the Primary key and another column. But, I cannot insert new rows in the table when the content of the new Primary key column already exists in another row. Can I define the table with a multiple column Primary key so that a unique value can be based upon the content of both columns?
View 3 Replies
Jan 30, 2011
I have four tables namely tblStudent, tblParent, tblEmployee and tblUnwantedVisitor.
tblUnwantedVisitor should get the primary key from the three tables, which is the visitor ID, tblStudent visitor ID starts from 10000, tblEmployee from 20000 and tblEmployee from 30000.
I used foreign key from one to one table only, so I don't know if my approach for the database is wrong or foreign key for multiple tables, which is somehow unlikely, is necessary.
View 14 Replies
Oct 1, 2010
SELECT u.Email FROM UserProfiles p, aspnet_Membership u WHERE p.RulesCheckBox = 'True' AND u.UserId = p.UserId This gives me a list of registered member email addresses that have selected the RulesCheckBox in their profile, so I can email them with an email script. There is a relationship between the Membership table and the UserProfile table, so it finds the email addresses from the Membership table where that user has the RulesCheckBox checked in their profile (in UserProfiles table). I'm wanting to add some additional names to this list, from a different table. The purpose is so I can manually add email addresses to the additional table, so the additional email addresses will also receive the same email, even though they aren't registered members of the site. So how can I adjust that SELECT statement so this one is combined with it somehow?:
SELECT Email FROM ExtraEmails WHERE Rules = 'true'
View 4 Replies
Sep 17, 2010
I have excel file with columns EmpName,Date1,Date2,...Date7 .I want to insert EmpName into Employee table after inserting i will get EmpNo(Identity column) with that i need to insert Date1,Date2...Date7 into TimeSheet table.
My Excel structure is like this
EmpName 8/1/2010 8/2/2010 8/3/2010 8/4/2010 8/5/2010 8/6/2010 8/7/2010
Naresh 17:00-2:00 17:00-2:00 14:00-12:00 7:00-12:00 7:00-12:00 .. Off
Similarly 500 employees data
I want to insert name i.e into Emp table after inserting i will get EMpNo i.e identity column with that i should insert Date1(8/1/2010) i.e excel header to date7 into Timesheet table Date column and corresponding time into TimeIn and TimeOut.I will split the time.I just want write Stored procedure for this task.
My database tables are like this
Emp-EmpNo,EmpName,CompaignId
Timesheet-TimeID,EMpNo,Date,TimeIn,TimeOut,TotalHours
Date in Timesheet should be like this
TimeId EmpNo Date TimeIn TimeOut T otalHours
1 100 8/1/2010 17:00 2:00 9hrs
2 100 8/2/2010 17:00 2:00 9 hrs
7
I just want this logic on how to insert Date1 to date 7 as 7 rows into Timesheet table and EMpName into EMployee table.while accesing each row i need to insert Date 1 to date7 as 7 rows into Timesheet table.
View 2 Replies
Sep 14, 2010
We have a database with a lot of information about Persons. I won't post the entire database structure because it is too big, but it looks something like this:
Person
ID
Name
Street
City
State
Country
Language
LangCode
Language
Interest
ID
LastChangedBy
LastChangedOn
LocalizedInterest
InterestID
LangCode
Description
PersonInterest
PersonID
InterestID
Now, this is just a small example. In our database, we have about 8-9 localized tables (like Interest) a Person can be linked to. A Person can have multiple Interests, a Person can have multiple Jobs, a Person can have multiple Educations, a Person can have multiple Experiences, I have to build a search function. Let's say you enter "tom" as the search term. This should give a list of all Persons with "tom" in their Name, Street, City, State, Country, in one of their Interests, in one of their Jobs, in one of their Educations, in one of their Experiences or in one of the other linked tables.
If you enter multiple words to search for (eg. "tom php"), it should give a list of all Persons with "tom" in their Name, Street, City, State, Country, in one of their Interests, in one of their Jobs, in one of their Educations, in one of their Experiences or in one of the other linked tables AND "php" in their Name, Street, City, State, Country, in one of their Interests, in one of their Jobs, in one of their Educations, in one of their Experiences or in one of the other linked tables. At the moment there are about 4,500 records in the Person table and if I do an outer join of Person with all the tables I have to search, there are about 1,300,000 records and 40-50 fields to search in.
How should I approach this problem so that performance will be acceptable? The client expects "something like Google" in terms of speed and ease of use. We're using MS SQL Server 2000 and ASP.NET 2.0. The search functionality has to be added to an existing application and changing the technology or database structure is not an option.
View 1 Replies
Sep 8, 2010
Was wondering if someone can help me out with this multi update problem
I have a webform that populates a single table but due to certain dropdown data conditions it could also potentially populate 3 other tables
The tables information populates a gridview with amounts from accounts etc..
e.g.
Table 1
Site DataType account update
34 SS 12.50 N
Table 2
Site account
34 12.50
Say the above entry has the updated column changed to Y via the webform the amount 12.50 should disappear from the gridview. I was
a bit shortsighted and added the additional tables afterward. The information on the gridview pulls from the additional tables and since
the first table and the additional tables are not linked the data still stays the same in the gridview
I do have an Id column on both tables but unfortunately I added the rest of the tables after the first one so the Id's do not really match.
View 6 Replies
Jul 21, 2010
I have 3 tables
Restaurants
IDNameAddress
Location
ID (Foreign Key)LocationID
Food
ID (Foreign Key)FoodID
Here's what I want to do, I have two variables @FID(food ID) and @LID(LocationID). I want something like
select * from restaurant where ID in (( select ID from location where locationID = @LID) AND (select ID from Food where FoodID = @FID))
The bold part is where I'm having problems. I want it to check both the Location and Food table for a match.
I'm having a hard time putting it into words :p I hope you get what I mean
View 2 Replies
Aug 25, 2010
I would like to update new records that get inserted in DataSet to Sql Server Database. Below is a working example of how to do this if you use "DataAdapter.Fill(ds)".
But i don't want to fill data, becouse i don't need data, i only need shema (I will use this dataset to insert new data to Sql), so i would like to use "DataAdapter.FillSchema(ds)"
[Code]....
View 4 Replies
Dec 23, 2010
Just looking through database design and wondering what would be the better option. I have customers, who all have orders, pickings, deliveries and invoices. Now an invoice can't exist without a delivery, a delivery can't exist without a picking and a picking can't exist without an order. So I could set the tables up in a linear fashion. e.g.
Customer -> Orders -> Picking -> Delivery -> Invoice
then in Orders, there would be an ID field, with a customerID field and in Picking, there would be an ID field, with an orderID field and in Delivery, there would be an ID field, with pickingID and in Invoice, there would be an deliveryID field. Linking them altogether, again, in a 'linear' fashion.
The problem is if I want to get, say, all the invoices for a specific customer, my query would be something like
[Code]....
My other option would be to have in a customerID column in each of the tables meaning a much easier query
[Code]....
View 3 Replies
Sep 6, 2010
Originally "LoadDate" column (see below scripts) was there both in tables DIM_Table_1 and DIM_Table_2
According to change in requirement, LoadDate in both the tables to be chnged to LOAD_DATE. It has to be done through script
EXEC sp_rename 'dbo.DIM_Table_1.LoadDate',
'LOAD_DATE', 'COLUMN' -- Successfully executed
EXEC sp_rename 'dbo.DIM_Table_2.LoadDate',
'LOAD_DATE', 'COLUMN' -- Error: See below
Error: The new name 'LOAD_DATE' is already in use as a COLUMN name and would cause a duplicate that is not permitted.
View 2 Replies
Jul 27, 2010
I'm a novice in .NET programming. I was trying to figure a way to make a MULTI TABLE search via a stored procedure for my website. I've written a SP to select records from one table, which isn't working for some unknown reasons:
[Code]....
Whatever I search for, the datagrid is displaying all records from my table.
View 5 Replies
Dec 1, 2010
Is there a way to select data from multiple tables other than the UNION ALL statement. Addtionally I need to select data from a different database.
My current statement is as follows (there are alot more fields but I have shortened it ):
SELECT server.dbo.SRFILE.SR_GROUP, server.dbo.SRFILE.SROWNERSHIP, server.dbo.SRFILE.SRCONMAE, BSFLBWF_1.Incidentx,
BSFLBWF_1.Severityx FROM server.dbo.SRFILE INNER JOIN
BSFLBWF AS BSFLBWF_1 ON BSFLBWF_1.Incidentx = server.dbo.SRFILE.SRONUMBER
WHERE (BSFLBWF_1.Closex IS NULL).........
View 4 Replies
Jul 27, 2010
I am accessing rows in an SQL database table based upon the contents of 2 Primary key columns. But, I cannot insert new rows in the table when the content in one of the new Primary key columns already exists in another row. I get an error message that says: "Violation of PRIMARY KEY constraint 'PK_ReferendumVoters'. Cannot insert duplicate key in object 'dbo.ReferendumVoters'. The statement has been terminated."
The reason why this error is occurring is because I first stored "Referendum 1" in one column along with "me" in the second column of a new row for a "ReferendumVoters" table. Then, I attempted to insert a new row with the same "Referendum 1" string in the first column along with a different name in the second column. But, it will not let me do this even though I created a new index that defines the two columns as unique. Is there any way that will enable me to do this?
View 5 Replies
Nov 15, 2010
One of my peer wrote a query based on multiple tables using joins. One of the table is in a different database The query was taking much time
1. Create an SP
2. Create a temp table and copy all records from the external db
3. Avoid using Left Join as much as possible and use Inner Join
4. Create and use indexes
5. Remove tables/columns that are not necessary
In this scenario, I would like to suggest to use Covering Index, but how can it be created for multiple tables and a temp table?
View 3 Replies
Nov 29, 2010
I basically have a series of tables from one database that have an identical structure thus making retrieval of all records fairly easy (I just use a UNION ALL statement). However I need a list of values from another table within a different database that contains information regarding the group of the data.
I so far have the following:
SELECT Table1.* FROM Table1 UNION ALL SELECT Table2.* FROM Table2 UNION ALL SELECT Table3.* FROM Table3 UNION SELECT Database.dbo.SRFILE.SR_GROUP FROM Database.dbo.SRFILE INNER JOIN Database.dbo.SRFILE.SRONUMBER = Table1.Incidentx
I keep receiving a unable to parse message however all I need to retreive is the SR_GROUP value but just don't know the correct syntax. Is it actually possible to do this as the structure of SRFILE is not the same as Table1/2/3.
View 3 Replies
Jan 4, 2011
I have an C# ASP application I am writing that needs to have the capability to import a generated excel or a comma delineated sheet each day. A clerk will have this job each morning so it doesn't need to be automated. My problem in trying to understand the solution to this is that the 1 sheet contains loan information, including customer information all in the same sheet. I would like to send certain columns to update information in the loan table and send other information to update the customer table. I need it to create relationships when new loans appear in the spreadsheet.
View 1 Replies