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
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.
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.
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 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.
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
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
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.
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?
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
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.
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?
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
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.
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?
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
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.
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!
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?
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.
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.
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
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
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)
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>
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
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)
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.
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.
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.