Showing posts with label inserts. Show all posts
Showing posts with label inserts. Show all posts

Wednesday, March 28, 2012

InsertCommand.ExecuteNonQuery() and violation of primaryKey

Hey,

I have a page that inserts into a customers table in the DataBase a new customer account using this function:

PublicFunction InsertCustomers(ByRef sessionid,ByVal email,ByVal pass,OptionalByVal fname ="",OptionalByVal lname ="",OptionalByVal company ="",OptionalByVal pobox ="",OptionalByVal add1 ="",OptionalByVal add2 ="",OptionalByVal city ="",OptionalByVal state ="",OptionalByVal postalcode ="",OptionalByVal country = 0,OptionalByVal tel ="")Dim resultAsNew DataSetDim tempidAsIntegerDim connAsNew SqlConnection(ConfigurationSettings.AppSettings("Conn"))Dim AdcustAsNew SqlDataAdapter

Adcust.InsertCommand =

New SqlCommand

Adcust.SelectCommand =

New SqlCommand

Adcust.InsertCommand.Connection = conn

Adcust.SelectCommand.Connection = conn

sessionExists(email, sessionid, 1)

conn.Open()

If fname =""Then

Adcust.InsertCommand.CommandText =

"Insert Into neelwafu.customers(email,password,sessionid) Values('" & email &"','" & pass &"','" & sessionid &"')"ElseDim strsqlAsString

strsql =

"Insert Into neelwafu.customers"

strsql = strsql &

"(sessionid,email,password,fname,lname,company,pobox,address,address2,city,state,postalcode,countrycode,tel) values("

strsql = strsql &

"'" & sessionid &"','" & email &"','" & pass &"','" & fname &"','" & lname &"','" & company &"','" & pobox &"','" & add1 &"','" & add2 &"','" & city &"','" & state &"','" & postalcode &"', " & country &",'" & tel &"')"

Adcust.InsertCommand.CommandText = strsql

EndIf

Adcust.InsertCommand.ExecuteNonQuery()

Adcust.SelectCommand.CommandText =

"Select Max(id) from neelwafu.Customers"

tempid =

CInt(Adcust.SelectCommand.ExecuteScalar())

conn.Close()

Return tempidEndFunction

------------------------------------------------------------

Now, I am getting an error:

Violation of PRIMARY KEY constraint 'PK_customers_1'. Cannot insert duplicate key in object 'customers'. The statement has been terminated.

------------------------------------------------------------

The customers table has as a primary key the 'email'....

so plz can I know why am I getting this error ??

Thank you in advance

Hiba

Hi,

it basically says you are trying to insert a new record with email X and email X is already present in the data base. And since the email is a primary key (unique id of a single record) it is not acceptable to have two records with the same mail.

You could check whether the email is not already present by a simple sql query.

Cheers,

Yani

|||

Hey,

The problem is I am not inserting a row with the same primary key !

When I use the sql 2005 to insert a new row like the following :

Insert Into customers(email,password,sessionid) Values('hiba@.hotmail.com'

, '0000' , 10)

It is executed normally but when that i want to insert the row from the web page using theInsertCustomers function, I got an error on theAdcust.InsertCommand.ExecuteNonQuery()!

Any idea ?

Thank you

Hiba

|||

Well,

if this is the case there is something wrong with your sql statement.

I would suggest to add a debug logging before executing the query:

Debug.WriteLine(strsql);

Start debugging the application, and when you get the error see in the Output window of your Visual Studio the exact sql query that fails.

If you cannot find the problem this way, paste your logged query here, so we could have a look at it.

Cheers,

Yani

|||

Hey,

The problem was solved :), there was a mistake in the order of passing the parameters the function insertcustomers where the sessionid was the first parameter where supposedly the email (PK) should be placed so every time i am inserting the same sessionid that's y i was getting that error :S

Anyways thank you :)

Hiba

sql

InsertCommand using data from a second SqlDataSource - ASP.NET 2.0

I have a process that inserts a new record using the InsertCommand of aSqlDataSource. As part of the process, I need to insert data the is available in a different SqlDataSource. I was trying this with the Insert Parameter:

<asp:FormParameterName="Change_Title"FormField="Change_Title"/>

where Change_Title is available on screen. Doesn't work. Is this possible?

HI

Can you see if this post helps or gives you some idea of how to achieve it.

http://forums.asp.net/p/1124558/1766373.aspx#1766373

The post though gives a way to avoid the need for two SQLDatasources but use one to handle both level updates.

Hope this helps.

VJ

insert/update trigger

Tbl1 inserts 1 record(with some fields populated) in tbl2. then I need get values from tbl3 to populate the rest of the fields in tbl2(update the record).
tbl1 = tblallBag_data
tbl2 = tblBag_data
tbl3 = tblShipping_sched

I created a trigger in tbl1 to insert a record into tbl2 and it works fine.

CREATE TRIGGER trgtblBag_Data ON dbo.tbltblallBag_data
FOR INSERT
AS

INSERT INTO tblBag_data (work_ord_num, work_ord_line_num, bag_num, bag_scanned_by, bag_date_scanned, bag_quantity)
SELECT work_ord_num, work_ord_line_num, bag_num, bag_scanned_by, bag_date_scanned, bag_quantity
FROM inserted

How can I update tbl2?
Should I create another trigger to update tbl2?
Should I join the two tbls(tbl2 & tbl3) to find
@.work_ord_num = work_ord_num , @.work_ord_line_num = work_ord_line_num

Thanks for your help!tbl2 and tbl3 should be joined with inserted.

Insert/ Update/ Delete slowness.

SQL2K sp4

Howdy all. I opened a 200 mb. file in Query Analyzer that is full of Inserts/ Updates/ and Deletes. I tried just to parse it, and killed it after 18 hours. There is no blocking. All of the appropriate indexes exist. I even removed them and retried JIC. The box is plenty powerful for this task. Does anyone have any ideas?
I've tried several times with no luck. At the top of the file is SET IMPLICIT_TRANSACTIONS ON and then every 10,000 statements is COMMIT WORK. I've tried adjusting the number of commits to a lower number with no luck. This works fine on smaller files (3 - 20 mb).Can you give a sample of the statements this script is running?

Monday, March 26, 2012

insert with exec sql server 2005

Hi,
This is a query that inserts the xmlcontents of a file into the table.

insert into
tbTrades
(
xmlContents
)
Exec ('SELECT Cast(BulkColumn as Nvarchar(max)) FROM OPENROWSET(BULK ''' + @.FilePath + ''', SINGLE_CLOB) as D')

Now I would like to add an extra field in the insert. something like:

declare @.FileName varchar(200)

set @.FileName = 'c:\1234.xml'

insert into
tbTrades
(
FileName,
xmlContents
)
@.FileName,
Exec ('SELECT Cast(BulkColumn as Nvarchar(max)) FROM OPENROWSET(BULK ''' + @.FilePath + ''', SINGLE_CLOB) as D')

This gives an error:
Incorrect syntax near '@.FileName'.

p.s. I am happy with the first query, just would like to get the second one to work too.
Thanks

how about:

Code Snippet

insert into

tbTrades

(

FileName,

xmlContents

)

Exec ('SELECT ''' + @.FileName + ''', Cast(BulkColumn as Nvarchar(max)) FROM OPENROWSET(BULK ''' + @.FilePath + ''', SINGLE_CLOB) as D')

Wednesday, March 21, 2012

Insert transaction batch size

I have insert statements that inserts 1.7 million rows from one server to
another. Half way through the insert, the connection gets lost. I am thinking
that because of the batch size the connection gets cut-off. How can I
implement a commit in T-SQL after say every 500 rows inserted ?
Thanks.
DXC,
You will have to manage this yourself in a stored procedure or sql batch.
Have you considered DTS - you can set the commit batch size there.
-- Bill
"DXC" <DXC@.discussions.microsoft.com> wrote in message
news:B8409B51-1A56-4CB5-946B-234102EDFA27@.microsoft.com...
>I have insert statements that inserts 1.7 million rows from one server to
> another. Half way through the insert, the connection gets lost. I am
> thinking
> that because of the batch size the connection gets cut-off. How can I
> implement a commit in T-SQL after say every 500 rows inserted ?
> Thanks.

Insert transaction batch size

I have insert statements that inserts 1.7 million rows from one server to
another. Half way through the insert, the connection gets lost. I am thinkin
g
that because of the batch size the connection gets cut-off. How can I
implement a commit in T-SQL after say every 500 rows inserted ?
Thanks.DXC,
You will have to manage this yourself in a stored procedure or sql batch.
Have you considered DTS - you can set the commit batch size there.
-- Bill
"DXC" <DXC@.discussions.microsoft.com> wrote in message
news:B8409B51-1A56-4CB5-946B-234102EDFA27@.microsoft.com...
>I have insert statements that inserts 1.7 million rows from one server to
> another. Half way through the insert, the connection gets lost. I am
> thinking
> that because of the batch size the connection gets cut-off. How can I
> implement a commit in T-SQL after say every 500 rows inserted ?
> Thanks.

Monday, March 19, 2012

Insert taking a long time.

Hey guys,
I am inserting into a table, which is probabaly around 800meg in size
(the database is around 870meg) and inserts are taking between 6-8
seconds (as shown in profiler). Profiler states that it is doing ~216000
reads for this task.
I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz
Xeon Processors (4 logical processors), and very fast ram.
Can anyone suggest why this may be taking so long, and also any ideas on
why its doing over 200,000 reads per insert.
Thanks in advance,
Les Can you post the full ddl for the table, plus any others that are related to
this one via any constraints? Any triggers on the table?
Likelihood is that there is a triigger causing one or more table scans or
refernces constraints somewhere that are not supported by appropriate
indexes.
Mike John
"Les Hughes" <lesHATESSPAM@.datarev.com.au> wrote in message
news:u6013fteFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Hey guys,
> I am inserting into a table, which is probabaly around 800meg in size (the
> database is around 870meg) and inserts are taking between 6-8 seconds (as
> shown in profiler). Profiler states that it is doing ~216000 reads for
> this task.
> I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz Xeon
> Processors (4 logical processors), and very fast ram.
> Can anyone suggest why this may be taking so long, and also any ideas on
> why its doing over 200,000 reads per insert.
> Thanks in advance,
> Les |||Les
Try DROP INDEXes that defined o the table just before INSERTING and
re-create them after .
"Les Hughes" <lesHATESSPAM@.datarev.com.au> wrote in message
news:u6013fteFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Hey guys,
> I am inserting into a table, which is probabaly around 800meg in size
> (the database is around 870meg) and inserts are taking between 6-8
> seconds (as shown in profiler). Profiler states that it is doing ~216000
> reads for this task.
> I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz
> Xeon Processors (4 logical processors), and very fast ram.
> Can anyone suggest why this may be taking so long, and also any ideas on
> why its doing over 200,000 reads per insert.
> Thanks in advance,
> Les

Insert taking a long time.

Hey guys,
I am inserting into a table, which is probabaly around 800meg in size
(the database is around 870meg) and inserts are taking between 6-8
seconds (as shown in profiler). Profiler states that it is doing ~216000
reads for this task.
I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz
Xeon Processors (4 logical processors), and very fast ram.
Can anyone suggest why this may be taking so long, and also any ideas on
why its doing over 200,000 reads per insert.
Thanks in advance,
Les
Can you post the full ddl for the table, plus any others that are related to
this one via any constraints? Any triggers on the table?
Likelihood is that there is a triigger causing one or more table scans or
refernces constraints somewhere that are not supported by appropriate
indexes.
Mike John
"Les Hughes" <lesHATESSPAM@.datarev.com.au> wrote in message
news:u6013fteFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Hey guys,
> I am inserting into a table, which is probabaly around 800meg in size (the
> database is around 870meg) and inserts are taking between 6-8 seconds (as
> shown in profiler). Profiler states that it is doing ~216000 reads for
> this task.
> I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz Xeon
> Processors (4 logical processors), and very fast ram.
> Can anyone suggest why this may be taking so long, and also any ideas on
> why its doing over 200,000 reads per insert.
> Thanks in advance,
> Les
|||Les
Try DROP INDEXes that defined o the table just before INSERTING and
re-create them after .
"Les Hughes" <lesHATESSPAM@.datarev.com.au> wrote in message
news:u6013fteFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Hey guys,
> I am inserting into a table, which is probabaly around 800meg in size
> (the database is around 870meg) and inserts are taking between 6-8
> seconds (as shown in profiler). Profiler states that it is doing ~216000
> reads for this task.
> I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz
> Xeon Processors (4 logical processors), and very fast ram.
> Can anyone suggest why this may be taking so long, and also any ideas on
> why its doing over 200,000 reads per insert.
> Thanks in advance,
> Les

Insert taking a long time.

Hey guys,
I am inserting into a table, which is probabaly around 800meg in size
(the database is around 870meg) and inserts are taking between 6-8
seconds (as shown in profiler). Profiler states that it is doing ~216000
reads for this task.
I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz
Xeon Processors (4 logical processors), and very fast ram.
Can anyone suggest why this may be taking so long, and also any ideas on
why its doing over 200,000 reads per insert.
Thanks in advance,
Les :)Can you post the full ddl for the table, plus any others that are related to
this one via any constraints? Any triggers on the table?
Likelihood is that there is a triigger causing one or more table scans or
refernces constraints somewhere that are not supported by appropriate
indexes.
Mike John
"Les Hughes" <lesHATESSPAM@.datarev.com.au> wrote in message
news:u6013fteFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Hey guys,
> I am inserting into a table, which is probabaly around 800meg in size (the
> database is around 870meg) and inserts are taking between 6-8 seconds (as
> shown in profiler). Profiler states that it is doing ~216000 reads for
> this task.
> I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz Xeon
> Processors (4 logical processors), and very fast ram.
> Can anyone suggest why this may be taking so long, and also any ideas on
> why its doing over 200,000 reads per insert.
> Thanks in advance,
> Les :)|||Les
Try DROP INDEXes that defined o the table just before INSERTING and
re-create them after .
"Les Hughes" <lesHATESSPAM@.datarev.com.au> wrote in message
news:u6013fteFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Hey guys,
> I am inserting into a table, which is probabaly around 800meg in size
> (the database is around 870meg) and inserts are taking between 6-8
> seconds (as shown in profiler). Profiler states that it is doing ~216000
> reads for this task.
> I am running SQL Server 2000, Standard, on a machine with 2 x 2.4ghz
> Xeon Processors (4 logical processors), and very fast ram.
> Can anyone suggest why this may be taking so long, and also any ideas on
> why its doing over 200,000 reads per insert.
> Thanks in advance,
> Les :)

Insert Stored Procedure Help

OK I have a stored procedure that inserts information into a database table. Here is what I have so far:

I think I have the proper syntax for inserting everything, but I am having problems with two colums. I have Active column which has the bit data type and a Notify column which is also a bit datatype. If I run the procedure as it stands it will insert all the information correctly, but I have to manually go in to change the bit columns. I tried using the set command, but it will give me a xyntax error implicating the "=" in the Active = 1 How can I set these in the stored procedure?

1SET ANSI_NULLSON2GO3SET QUOTED_IDENTIFIERON4GO5-- =============================================6-- Author:xxxxxxxx7-- Create date: 10/31/078-- Description:Insert information into Registration table9-- =============================================10ALTER PROCEDURE [dbo].[InsertRegistration]1112@.Name nvarchar(50),13@.StreetAddressnchar(20),14@.Citynchar(10),15@.Statenchar(10),16@.ZipCodetinyint,17@.PhoneNumbernchar(20),18@.DateOfBirthsmalldatetime,19@.EmailAddressnchar(20),20@.Gendernchar(10),21@.Notifybit2223AS24BEGIN25-- SET NOCOUNT ON added to prevent extra result sets from26-- interfering with SELECT statements.27SET NOCOUNT ON;2829INSERT INTO Registration3031(Name, StreetAddress, City, State, ZipCode, PhoneNumber, DateOfBirth, EmailAddress, Gender, Notify)3233VALUES3435(@.Name, @.StreetAddress, @.City, @.State, @.ZipCode, @.PhoneNumber, @.DateOfBirth, @.EmailAddress, @.Gender, @.Notify)3637--SET38--Active = 13940END41GO

Can u post the data with execute method


Thank u

Baba

|||

You cannot set "Active" = 1 in t-sql.

That is because "Active" is not a valid variable name. It should be @.Active and, of course, you would have to declare it before doing so.

That said, I suspect you are trying to set the Active column value to 1 in the record you are inserting.

If so, you need to add (assuming Active is the column name) Active to the list of column names in the insert statement.

In the corresponding slot in the list of values in the insert statement, place a 1.

|||

It didn't correct the problem, but let me make sure I am on the right track (different table here):

1set ANSI_NULLSON2set QUOTED_IDENTIFIERON3GO4-- =============================================5-- Author:xxxxx
6-- Create date: 10/21/077-- Description:Insert Users8-- =============================================9ALTER PROCEDURE [dbo].[InsertUser]101112@.FirstNamenvarchar(50),13@.LastNamenvarchar(50),14@.MiddleNamenvarchar(50),15@.Activebit16AS17BEGIN18SET NOCOUNT ON;1920INSERT INTO Users21(FirstName, LastName, MiddleName, Active)22VALUES23(@.FirstName, @.LastName, @.MiddleName, 1)24--SET25--Active =126END

I get this message when you try to insert a user:

Procedure or function 'InsertUser' expects parameter '@.Active', which was not supplied.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: Procedure or function 'InsertUser' expects parameter '@.Active', which was not supplied.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[SqlException (0x80131904): Procedure or function 'InsertUser' expects parameter '@.Active', which was not supplied.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +921162 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800038 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +947 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +149 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +404 System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +447 System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +72 System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +390 System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +602 System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +109 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +132 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

Am I on the right track?|||

Tharnid:

12 @.FirstNamenvarchar(50),
13 @.LastNamenvarchar(50),
14 @.MiddleNamenvarchar(50),
15 @.Activebit

Tharnid:

Procedure or function 'InsertUser' expects parameter '@.Active', which was not supplied.

You declared an input parameter @.Active, according to your SQL statement this should be 1 by default, so you should not declare it at all!

12 @.FirstNamenvarchar(50),
13 @.LastNamenvarchar(50),
14 @.MiddleNamenvarchar(50)
15

|||

try:

ALTER PROCEDURE [dbo].[InsertUser]
10
11
12@.FirstNamenvarchar(50),
13@.LastNamenvarchar(50),
14@.MiddleNamenvarchar(50),
15@.Activebit = 1
16AS
BEGIN
...
END 

|||

Procedure or function 'InsertUser' expects parameter '@.Active', which was not supplied.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: Procedure or function 'InsertUser' expects parameter '@.Active', which was not supplied.

Simply is telling you that you are not supplying the code with the value for the Active Parameter which in your case is an INPUT parameter and not an OUTPUT parameter. If you need it to be OUTPUT, I believe you have to indicate that in your procedure.

|||

Yes, you can give @.Active a default value as Spark is suggesting, but why would you do that? In the SQL statement active is hardcoded to be 1. So if you do supply a value (0 or 1) for it, the procedure will ignore it!

And yes, you can make it an output parameter as Dollarjunkie wrote, but then the return statement should be

SET @.active = 1

But why would you want an output parameter that will always return 1?

In this case, to skip the parameter is the logical solution, although the other 2 approaches will also work...

|||

I appreciate the respone :-) I will try them as soon as I can, indicate who gave the correct answer, and check answered

Monday, March 12, 2012

Insert Statement logic

I have a problem trying to work out the insert logic for an insert statement
which inserts the rows from one table (Parcel1) into another table (Parcel2)
.
Bare with me for this as I know this mightn't people might say why are you
doing this but its just an example i've drew up. Basically my problem is
that the first time I run an insert statement everything works fine. When I
run the insert statement the second time though the same rows are inserted
into the second table.
What i want to add to my insert statement is something which says if the
fields oneParcel1 and oneParcel2 for a particular row have the same values i
n
the twoparcel1 and twoparcel2 fields as a row which already exists in the
Parcel2 table then don't insert the records. So If a row in Parcel1 has a
row which has car and truck in the table parcel2 regardless of the other
fields value don't insert it.
CREATE TABLE [dbo].[Parcel1] (
[RecNo] [int] NULL ,
[oneParcel1] [bigint] NULL ,
[oneParcel2] [bigint] NULL ,
[Date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Parcel2] (
[RecNO] [bigint] NULL ,
[twoParcel1] [bigint] NULL ,
[twoParcel2] [bigint] NULL ,
[Date] [datetime] NULL
) ON [PRIMARY]
insert into Parcel1 values(1, 'car', 'bus', '15/06/1982')
insert into Parcel1 values(2, 'bus', 'train', '15/06/1982')
insert into Parcel1 values(3, 'truck', 'car', '15/06/1982')
insert into Parcel1 values(4, 'car', 'truck', '15/06/1982')
insert into Parcel1 values(5, 'truck', 'plane', '15/06/1982')
Table: Parcel1
RecNo oneParcel1 oneParcel2 Date
1 car bus 15/06/1982
2 bus train 15/06/1982
3 truck car 15/06/1982
4 car truck 15/06/1982
5 truck boat 15/06/1982
After 1st insert. I want this. and if I run the insert statement again I
don't want these rows to be inserted again
Table: Parcel2
RecNo twoParcel1 twoParcel2 Date
1 car bus 15/06/1982
2 bus train 15/06/1982
3 truck car 15/06/1982
4 car truck 15/06/1982
5 truck boat 15/06/1982Stephen
Have you even checked your DDL before posting it?
CREATE TABLE [dbo].[Parcel1] (
[RecNo] [int] NULL ,
[oneParcel1] varchar(15) NULL ,
[oneParcel2] varchar(15) NULL ,
[Date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Parcel2] (
[RecNO] [bigint] NULL ,
[twoParcel1] varchar(15) NULL ,
[twoParcel2] varchar(15) NULL ,
[Date] [datetime] NULL
) ON [PRIMARY]
insert into Parcel1 values(1, 'car', 'bus', '19820615')
insert into Parcel1 values(2, 'bus', 'train', '19820615')
insert into Parcel1 values(3, 'truck', 'car', '19820615')
insert into Parcel1 values(4, 'car', 'truck', '19820615')
insert into Parcel1 values(5, 'truck', 'plane', '19820615')
INSERT INTO Parcel2 SELECT * FROM Parcel1 WHERE NOT EXISTS
(
SELECT * FROM Parcel2 P WHERE P.RecNo=Parcel1.RecNo
)
"Stephen" <Stephen@.discussions.microsoft.com> wrote in message
news:E956A4AA-4D55-4056-AA86-4391054E53BE@.microsoft.com...
>I have a problem trying to work out the insert logic for an insert
>statement
> which inserts the rows from one table (Parcel1) into another table
> (Parcel2).
>
> Bare with me for this as I know this mightn't people might say why are you
> doing this but its just an example i've drew up. Basically my problem is
> that the first time I run an insert statement everything works fine. When
> I
> run the insert statement the second time though the same rows are inserted
> into the second table.
> What i want to add to my insert statement is something which says if the
> fields oneParcel1 and oneParcel2 for a particular row have the same values
> in
> the twoparcel1 and twoparcel2 fields as a row which already exists in the
> Parcel2 table then don't insert the records. So If a row in Parcel1 has a
> row which has car and truck in the table parcel2 regardless of the other
> fields value don't insert it.
> CREATE TABLE [dbo].[Parcel1] (
> [RecNo] [int] NULL ,
> [oneParcel1] [bigint] NULL ,
> [oneParcel2] [bigint] NULL ,
> [Date] [datetime] NULL
> ) ON [PRIMARY]
> GO
> CREATE TABLE [dbo].[Parcel2] (
> [RecNO] [bigint] NULL ,
> [twoParcel1] [bigint] NULL ,
> [twoParcel2] [bigint] NULL ,
> [Date] [datetime] NULL
> ) ON [PRIMARY]
> insert into Parcel1 values(1, 'car', 'bus', '15/06/1982')
> insert into Parcel1 values(2, 'bus', 'train', '15/06/1982')
> insert into Parcel1 values(3, 'truck', 'car', '15/06/1982')
> insert into Parcel1 values(4, 'car', 'truck', '15/06/1982')
> insert into Parcel1 values(5, 'truck', 'plane', '15/06/1982')
> Table: Parcel1
> RecNo oneParcel1 oneParcel2 Date
> 1 car bus 15/06/1982
> 2 bus train 15/06/1982
> 3 truck car 15/06/1982
> 4 car truck 15/06/1982
> 5 truck boat 15/06/1982
> After 1st insert. I want this. and if I run the insert statement again I
> don't want these rows to be inserted again
> Table: Parcel2
> RecNo twoParcel1 twoParcel2 Date
> 1 car bus 15/06/1982
> 2 bus train 15/06/1982
> 3 truck car 15/06/1982
> 4 car truck 15/06/1982
> 5 truck boat 15/06/1982
>|||2 ways
1. Check for the existence of a duplicate before inserting
2. Keep a unique index with IGNORE DUPLICATE option set for Parcel2 table
Rakesh
"Stephen" wrote:

> I have a problem trying to work out the insert logic for an insert stateme
nt
> which inserts the rows from one table (Parcel1) into another table (Parcel
2).
>
> Bare with me for this as I know this mightn't people might say why are you
> doing this but its just an example i've drew up. Basically my problem is
> that the first time I run an insert statement everything works fine. When
I
> run the insert statement the second time though the same rows are inserted
> into the second table.
> What i want to add to my insert statement is something which says if the
> fields oneParcel1 and oneParcel2 for a particular row have the same values
in
> the twoparcel1 and twoparcel2 fields as a row which already exists in the
> Parcel2 table then don't insert the records. So If a row in Parcel1 has a
> row which has car and truck in the table parcel2 regardless of the other
> fields value don't insert it.
> CREATE TABLE [dbo].[Parcel1] (
> [RecNo] [int] NULL ,
> [oneParcel1] [bigint] NULL ,
> [oneParcel2] [bigint] NULL ,
> [Date] [datetime] NULL
> ) ON [PRIMARY]
> GO
> CREATE TABLE [dbo].[Parcel2] (
> [RecNO] [bigint] NULL ,
> [twoParcel1] [bigint] NULL ,
> [twoParcel2] [bigint] NULL ,
> [Date] [datetime] NULL
> ) ON [PRIMARY]
> insert into Parcel1 values(1, 'car', 'bus', '15/06/1982')
> insert into Parcel1 values(2, 'bus', 'train', '15/06/1982')
> insert into Parcel1 values(3, 'truck', 'car', '15/06/1982')
> insert into Parcel1 values(4, 'car', 'truck', '15/06/1982')
> insert into Parcel1 values(5, 'truck', 'plane', '15/06/1982')
> Table: Parcel1
> RecNo oneParcel1 oneParcel2 Date
> 1 car bus 15/06/1982
> 2 bus train 15/06/1982
> 3 truck car 15/06/1982
> 4 car truck 15/06/1982
> 5 truck boat 15/06/1982
> After 1st insert. I want this. and if I run the insert statement again I
> don't want these rows to be inserted again
> Table: Parcel2
> RecNo twoParcel1 twoParcel2 Date
> 1 car bus 15/06/1982
> 2 bus train 15/06/1982
> 3 truck car 15/06/1982
> 4 car truck 15/06/1982
> 5 truck boat 15/06/1982
>|||Try:
INSERT INTO Parcel2 (recno, twoparcel1, twoparcel2, [date])
SELECT recno, oneparcel1, oneparcel2, [date]
FROM Parcel1 AS P1
WHERE NOT EXISTS
(SELECT *
FROM Parcel2 AS P2
WHERE P2.twoparcel1 = P1.oneparcel1
AND P2.twoparcel2 = P1.oneparcel2) ;
Some other things need more attention. First, you don't have a key in
either table! All the columns are nullable, which means both tables
lack any integrity. "Date" is a reserved word and much too vague for a
column name. "RecNo" is not a good identifier in a relational database.
Conventional wisdom has it that tables have rows, not records. Rows are
not numbered and surrogate keys are not "record numbers". BIGINT
appears to be a mistake anyway but are you really expecting more than 2
billion rows in these tables?
Thanks for including the DDL but do remember that keys, constraints and
accurate datatypes are important if you want accurate answers.
Hope this helps.
David Portas
SQL Server MVP
--|||Small addition to what i said
2 ways
1. Check for the existence of a duplicate before inserting
2. Keep a unique index on columns twoParcel1, twoParcel2 with IGNORE
DUPLICATE option set for Parcel2 table. This will let u do the insert
statements as u hv been doing and ignoring any duplicate values without
giving an error.
"Rakesh" wrote:
> 2 ways
> 1. Check for the existence of a duplicate before inserting
> 2. Keep a unique index with IGNORE DUPLICATE option set for Parcel2 table
> Rakesh
> "Stephen" wrote:
>|||> 2. Keep a unique index on columns twoParcel1, twoParcel2 with IGNORE
> DUPLICATE option set for Parcel2 table. This will let u do the insert
> statements as u hv been doing and ignoring any duplicate values without
> giving an error.
Be very, very careful with the IGNORE_DUP_KEY option. I would consider
it suitable for a staging database in special circumstances only - not
for a live database with actual users, queries and updates running on
it.
The reason is that IGNORE_DUP_KEY confounds set-based inserts because
by giving a non-deterministic result in the presence of duplicates. In
short you cannot know or control which rows(s) get inserted and which
get discarded. Of course, if all your developers are aware that this
option has been set then in principle they can safely code around it -
but if they are going to do that anyway then why use it? Just add the
existence check to the INSERT statements instead.
David Portas
SQL Server MVP
--|||Sorry never checked it correct your guess was correct to what it should have
been.
I know this is going to sound awkward but I know who to do it that way but
i'm trying to ignore the RecNO and work out how to only insert records where
Parcel1.oneParcel1 = Parcel2.twoParcel1 AND
Parcel1.oneParcel2 = Parcel2.twoParcel2
I know this probably doesn't make sense and its hard to explain but i want
the sql to not allow records to be inserted when the above conditions are
both true. In other words forgetting about the recno and date if a row in th
e
Parcel 1 table has the values
RecNo oneParcel1 oneParcel2 Date
1 car bus 15/06/1982
and the same row is present in the Parcel 2 table like this
RecNo twoParcel1 twoParcel2 Date
1 car bus 15/06/1982
When a row like this comes along in the Parcel 1 table I don't want it
inserted because the car and buss secenario has already been inserted.
RecNo oneParcel1 oneParcel2 Date
6 car bus 01/11/1983
"Uri Dimant" wrote:

> Stephen
> Have you even checked your DDL before posting it?
> CREATE TABLE [dbo].[Parcel1] (
> [RecNo] [int] NULL ,
> [oneParcel1] varchar(15) NULL ,
> [oneParcel2] varchar(15) NULL ,
> [Date] [datetime] NULL
> ) ON [PRIMARY]
> GO
> CREATE TABLE [dbo].[Parcel2] (
> [RecNO] [bigint] NULL ,
> [twoParcel1] varchar(15) NULL ,
> [twoParcel2] varchar(15) NULL ,
> [Date] [datetime] NULL
> ) ON [PRIMARY]
> insert into Parcel1 values(1, 'car', 'bus', '19820615')
> insert into Parcel1 values(2, 'bus', 'train', '19820615')
> insert into Parcel1 values(3, 'truck', 'car', '19820615')
> insert into Parcel1 values(4, 'car', 'truck', '19820615')
> insert into Parcel1 values(5, 'truck', 'plane', '19820615')
>
> INSERT INTO Parcel2 SELECT * FROM Parcel1 WHERE NOT EXISTS
> (
> SELECT * FROM Parcel2 P WHERE P.RecNo=Parcel1.RecNo
> )
>
>
> "Stephen" <Stephen@.discussions.microsoft.com> wrote in message
> news:E956A4AA-4D55-4056-AA86-4391054E53BE@.microsoft.com...
>
>

Insert Statement Help

hi all

i am writing a trigger that inserts from one table to the next. i have an issue with the table being inserted into have 2 more columns than the one being inserted from. Here is the trigger just in case

CREATE TRIGGER [Insert40801] ON [dbo].[tPA10801]
FOR INSERT

AS

insert into tPA40801
select
intTimesheetKey,
chrTimesheetNumber,
TranID,
intEmployeeKey,
intEmployeeDivKey,
BatchKey,
dtePeriodStartDate,
dtePeriodEndDate,
chrStatus1,
numTotalHrsWorked,
numTotalHrsBilled,
numTotalCosts,
numTotalCharges,
numTotalRecover,
chrSignedID,
dteSignedDate,
chrApprovalID,
dteApprovalDate,
intJobKey,
intPhaseKey,
intTaskKey,
dteDate,
siCstClsificatnDDL,
UpdateCounter,
CompanyID


from tpa10801

now tpa40801 has two extra columns that tpa10801 doesnt. how would i please the sql gods and get the insert statement running? thanks alot

tiborYou're missing a few of the items that are suggested in the FAQ Entry (http://www.dbforums.com/showthread.php?t=1212452#post4527530) that would probably get you the answer you need on your next try. Specifically, it would help me a lot to know what the table structures are now, so I'd know which columns were missing.

-PatP|||actually i was able to overcome that issue but just deleting the columns from tPA40801. but now i have an issue with the batchkey column. the program that this is all for is recognizing that it is a batchkey and does not allow the program to save while this is trying to insert. so i just need to be able to insert everything there except the batchkey column. hope that helps

INSERT Statement Error

I have a web app w/a form that takes user data and inserts into a customers
table. Now if I try to insert a record w/identical 'customerName', this is
the error:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'FK_transactions_customers'. The conflict occurred in database 'CHZ', table
'customers', column 'CID'.
Now the constraint 'FK_transactions_customers' uses CID.Customers as my
Primary key and Trans.CID as the foreign key. I can't seem to figure out wh
y
the error is thrown when using an existing 'customerName'.
Here's the ddl:
CREATE TABLE [customers] (
[CID] [int] IDENTITY (1, 1) NOT NULL ,
[customerName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[customerID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[address] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[city] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[state] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[zip] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[phone] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CDB] [bit] NULL ,
CONSTRAINT [PK_customers] PRIMARY KEY NONCLUSTERED
(
[CID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
TIA for help.Post the DDL for Trans, as well as the offending INSERT statement.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:FB917852-FA0D-4EE8-B6DD-15A142D3B934@.microsoft.com...
I have a web app w/a form that takes user data and inserts into a customers
table. Now if I try to insert a record w/identical 'customerName', this is
the error:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'FK_transactions_customers'. The conflict occurred in database 'CHZ', table
'customers', column 'CID'.
Now the constraint 'FK_transactions_customers' uses CID.Customers as my
Primary key and Trans.CID as the foreign key. I can't seem to figure out
why
the error is thrown when using an existing 'customerName'.
Here's the ddl:
CREATE TABLE [customers] (
[CID] [int] IDENTITY (1, 1) NOT NULL ,
[customerName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[customerID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[address] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[city] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[state] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[zip] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[phone] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CDB] [bit] NULL ,
CONSTRAINT [PK_customers] PRIMARY KEY NONCLUSTERED
(
[CID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
TIA for help.|||You are trying to insert a customer which isn=B4t present in the
transaction table. Check this.
HTH, jens Suessmeyer.|||"Jens" wrote:

> You are trying to insert a customer which isn′t present in the
> transaction table. Check this.
> HTH, jens Suessmeyer.
>
Shouldn't be a problem, unless the foreign key constraint is backwards
(customers references transactions instead of transactions references
customers).

Insert Statement

Hi Everyone

I am having difficulties with my first hand coded insert statement. The record inserts BUT the first item VALUE is selected for all the drop down lists ( 3 of them are optional) I have Prerenders on the page to insert a null value at the top of the list. For the dropdown that is mandatory it only enter first item. Thats without specifying type. As soon as I specify type I get - Input string not in correct format - doesn't actually tell me which one!!!!!! All char types match the database.

Here is my insert:

Sub Add_Click(sender as object, e as EventArgs)

Dim conBooks As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand

conBooks = New SqlConnection( System.Configuration.ConfigurationSettings.AppSettings("conFantasy") )
strInsert = "INSERT INTO dbo.Books (ISBN, BookTitle, AuthorID, AuthorType, author2, author3, Series, VolNo, Synopsis, PubYear, PubDate) VALUES (@.ISBN, @.BookTitle, @.AuthorID, @.AuthorType, @.author2, @.author3, @.Series, @.VolNo, @.Synopsis, @.PubYear, @.PubDate )"

cmdInsert = New SqlCommand( strInsert, conBooks )

' Add Parameters
cmdInsert.Parameters.Add( "@.ISBN", SqlDbType.nvarchar).Value = txtISBN.Text
cmdInsert.Parameters.Add( "@.BookTitle", SqlDbType.nvarchar).Value = title.Text
cmdInsert.Parameters.Add( "@.AuthorID", SqlDbType.int).Value = AuthorID.SelectedItem.Value
cmdInsert.Parameters.Add( "@.AuthorType", SqlDbType.char).Value = AuthorType.SelectedItem.Value
cmdInsert.Parameters.Add( "@.author2", SqlDbType.int).Value = author2.SelectedItem.Value
cmdInsert.Parameters.Add( "@.author3", SqlDbType.int).Value = Author3.SelectedItem.Value
cmdInsert.Parameters.Add( "@.Series", SqlDbType.nvarchar).Value = Series.SelectedItem.Value
cmdInsert.Parameters.Add( "@.VolNo", SqlDbType.int).Value = volumeno.Text
cmdInsert.Parameters.Add( "@.Synopsis", SqlDbType.ntext).Value = txtSynopsis.Text
cmdInsert.Parameters.Add( "@.PubYear", SqlDbType.bigint).Value = pubyear.Text
cmdInsert.Parameters.Add( "@.PubDate", SqlDbType.nvarchar).Value = PubDate.Text

conBooks.Open()
cmdInsert.ExecuteNonQuery()
conBooks.Close()

Response.Redirect("/admin/default.aspx")
End Sub

You are passing strings to all as the value. Try, for instance:

cmdInsert.Parameters.Add( "@.AuthorID", SqlDbType.int).Value = int.parse(AuthorID.SelectedItem.Value)
|||hmmm

that particular statement gives me this error:

Overload resolution failed because no accessible 'Int' accepts this number of arguments.

??

Could it be because the optional fields have NULL instead of an int?|||I have updated the code as follows. There are no errors when I do an insert, however, for the optional fields there are zero's bring inserted instead of NULL?

Sub Add_Click(sender as object, e as EventArgs)

Dim conBooks As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand

conBooks = New SqlConnection( System.Configuration.ConfigurationSettings.AppSettings("conFantasy") )
strInsert = "INSERT INTO dbo.Books (ISBN, BookTitle, AuthorID, AuthorType, author2, author3, Series, VolNo, Synopsis, PubYear, PubDate) VALUES (@.ISBN, @.BookTitle, @.AuthorID, @.AuthorType, @.author2, @.author3, @.Series, @.VolNo, @.Synopsis, @.PubYear, @.PubDate )"

cmdInsert = New SqlCommand( strInsert, conBooks )

' Add Parameters
dim myParam1 as sqlParameter
myParam1 = cmdInsert.Parameters.Add("@.ISBN", SqlDbType.nvarchar)
myParam1.Value = txtISBN.Text

dim myParam2 as sqlParameter
myParam2 = cmdInsert.Parameters.Add("@.BookTitle", SqlDbType.nvarchar)
myParam2.Value = title.Text

dim myParam3 as sqlParameter
myParam3 = cmdInsert.Parameters.Add("@.AuthorID", SqlDbType.Int)
myParam3.Value = AuthorID.SelectedItem.Value

dim myParam4 as sqlParameter
myParam4 = cmdInsert.Parameters.Add("@.AuthorType", SqlDbType.char)
myParam4.Value = AuthorType.SelectedItem.Value

dim myParam5 as sqlParameter
myParam5 = cmdInsert.Parameters.Add("@.author2", author2.SelectedItem.Value)

dim myParam6 as sqlParameter
myParam6 = cmdInsert.Parameters.Add("@.author3", Author3.SelectedItem.Value)

dim myParam7 as sqlParameter
myParam7 = cmdInsert.Parameters.Add("@.Series", SqlDbType.nvarchar)
myParam7.Value = Series.SelectedItem.Value

dim myParam8 as sqlParameter
myParam8 = cmdInsert.Parameters.Add("@.VolNo", volumeno.Text)

dim myParam9 as sqlParameter
myParam9 = cmdInsert.Parameters.Add("@.Synopsis", SqlDbType.ntext)
myParam9.Value = txtSynopsis.Text

dim myParam10 as sqlParameter
myParam10 = cmdInsert.Parameters.Add("@.PubYear", SqlDbType.Int)
myParam10.Value = pubyear.Text

dim myParam11 as sqlParameter
myParam11 = cmdInsert.Parameters.Add("@.PubDate", SqlDbType.nvarchar)
myParam11.Value = PubDate.Text

conBooks.Open()
cmdInsert.ExecuteNonQuery()
conBooks.Close()

Response.Redirect("/admin/default.aspx")
End Sub|||Last message. I got it all working, however, I would love to have some comments on the cosing. If anything could be simplified or written better etc.

My insert statement:

Sub Add_Click(sender as object, e as EventArgs)

Dim conBooks As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand

conBooks = New SqlConnection( System.Configuration.ConfigurationSettings.AppSettings("conFantasy") )
strInsert = "INSERT INTO dbo.Books (ISBN, BookTitle, AuthorID, AuthorType, author2, author3, Series, VolNo, Synopsis, PubYear, PubDate) VALUES (@.ISBN, @.BookTitle, @.AuthorID, @.AuthorType, @.author2, @.author3, @.Series, @.VolNo, @.Synopsis, @.PubYear, @.PubDate )"

cmdInsert = New SqlCommand( strInsert, conBooks )

' Add Parameters
dim myParam1 as sqlParameter
myParam1 = cmdInsert.Parameters.Add("@.ISBN", SqlDbType.nvarchar)
myParam1.Value = txtISBN.Text

dim myParam2 as sqlParameter
myParam2 = cmdInsert.Parameters.Add("@.BookTitle", SqlDbType.nvarchar)
myParam2.Value = title.Text

dim myParam3 as sqlParameter
myParam3 = cmdInsert.Parameters.Add("@.AuthorID", SqlDbType.Int)
myParam3.Value = AuthorID.SelectedItem.Value

dim myParam4 as sqlParameter
myParam4 = cmdInsert.Parameters.Add("@.AuthorType", SqlDbType.char)
myParam4.Value = AuthorType.SelectedItem.Value

dim myParam5 as sqlParameter
If author2.SelectedItem.Value <> ""
myParam5 = cmdInsert.Parameters.Add("@.author2", Author2.SelectedItem.Value)
Else
myParam5 = cmdInsert.Parameters.Add("@.author2", DBNull.Value)
End If

dim myParam6 as sqlParameter
If Author3.SelectedItem.Value <> ""
myParam6 = cmdInsert.Parameters.Add("@.author3", Author3.SelectedItem.Value)
Else
myParam6 = cmdInsert.Parameters.Add("@.author3", DBNull.Value)
End If

dim myParam7 as sqlParameter
myParam7 = cmdInsert.Parameters.Add("@.Series", SqlDbType.nvarchar)
myParam7.Value = Series.SelectedItem.Value

dim myParam8 as sqlParameter
If volumeno.Text <> ""
myParam8 = cmdInsert.Parameters.Add("@.VolNo", volumeno.Text)
Else
myParam8 = cmdInsert.Parameters.Add("@.VolNo", DBNull.Value)
End If

dim myParam9 as sqlParameter
myParam9 = cmdInsert.Parameters.Add("@.Synopsis", SqlDbType.ntext)
myParam9.Value = txtSynopsis.Text

dim myParam10 as sqlParameter
myParam10 = cmdInsert.Parameters.Add("@.PubYear", SqlDbType.Int)
myParam10.Value = pubyear.Text

dim myParam11 as sqlParameter
myParam11 = cmdInsert.Parameters.Add("@.PubDate", SqlDbType.nvarchar)
myParam11.Value = PubDate.Text

conBooks.Open()
cmdInsert.ExecuteNonQuery()
conBooks.Close()

Response.Redirect("/admin/default.aspx")
End Sub

My Page_Load

Sub Page_Load(Src As Object, E As EventArgs)
If Not IsPostBack Then
Dim dsAuthors As New System.Data.DataSet
Dim dvwAuthors As Dataview
Dim conAuthors As New SqlConnection( System.Configuration.ConfigurationSettings.AppSettings("conFantasy") )
Dim dadAuthor As New SqlDataAdapter( "SELECT * FROM dbo.qryAuthors", conAuthors )

dadAuthor.Fill( dsAuthors, "Authors" )
dvwAuthors = dsAuthors.Tables( "Authors" ).DefaultView()

AuthorID.DataSource = dvwAuthors
AuthorID.DataTextfield = "Fullname"
AuthorID.DataValueField = "AuthorID"
AuthorID.DataBind()

Author2.DataSource = dvwAuthors
Author2.DataTextfield = "Fullname"
Author2.DataValueField = "AuthorID"
Author2.DataBind()

Author3.DataSource = dvwAuthors
Author3.DataTextfield = "Fullname"
Author3.DataValueField = "AuthorID"
Author3.DataBind()

Dim dsSeries As New System.Data.DataSet
Dim dvwSeries As Dataview
Dim conSeries As New SqlConnection( System.Configuration.ConfigurationSettings.AppSettings("conFantasy") )
Dim dadSeries As New SqlDataAdapter( "SELECT SeriesID, Series FROM dbo.tblSeries ORDER BY Series ASC", conSeries )

dadSeries.Fill( dsSeries, "Series" )
dvwSeries = dsSeries.Tables( "Series" ).DefaultView()

Series.DataSource = dvwSeries
Series.DataTextfield = "Series"
Series.DataValueField = "Series"
Series.DataBind()

Series.Items.Insert(0, New System.Web.UI.WebControls.ListItem("None","None"))
Author2.Items.Insert(0, New System.Web.UI.WebControls.ListItem("None", ""))
Author3.Items.Insert(0, New System.Web.UI.WebControls.ListItem("None", ""))
End If
End Sub

Regards

Nimmie

Insert Statement

Hi Friends,
In my SP i have 3 insert statements that inserts record into 3 different
tables. If any of the inserts fail, I want to roll back any other inserts
that is executed. how to do this. please give me an example.
example:
insert into abc values('ert','ert')
insert into xyz values('rtert','rtyrty')
if the insert operation fails for the table xyz then the insert for abc
should not be commited.
thnks
vanithaput your sql statement in a transaction
begin transaction
insert 1....
insert 2....
insert 3.......
commit transaction
<hr>
MCP #2324787
"Vanitha" wrote:

> Hi Friends,
> In my SP i have 3 insert statements that inserts record into 3 different
> tables. If any of the inserts fail, I want to roll back any other inserts
> that is executed. how to do this. please give me an example.
> example:
> insert into abc values('ert','ert')
> insert into xyz values('rtert','rtyrty')
> if the insert operation fails for the table xyz then the insert for abc
> should not be commited.
> thnks
> vanitha|||CREATE PROCC dbo.ProcedureName
(paramlist)
AS
BEGIN
BEGIN TRAN [tranname]
INSERT INTO First table ...
IF @.@.ERROR > 0
BEGIN
ROLLBACK TRAN [tranname]
RETURN [Errorcode]
END
INSERT INTO second table ...
IF @.@.ERROR > 0
BEGIN
ROLLBACK TRAN [tranname]
RETURN [Errorcode]
END
INSERT INTO third table ...
IF @.@.ERROR > 0
BEGIN
ROLLBACK TRAN [tranname]
RETURN [Errorcode]
END
COMMIT TRAN [tranname]
END
GO
Roji. P. Thomas
Net Asset Management
http://toponewithties.blogspot.com
"Vanitha" <Vanitha@.discussions.microsoft.com> wrote in message
news:08B477A8-5335-45EB-BAC2-B76B2B2A5563@.microsoft.com...
> Hi Friends,
> In my SP i have 3 insert statements that inserts record into 3 different
> tables. If any of the inserts fail, I want to roll back any other inserts
> that is executed. how to do this. please give me an example.
> example:
> insert into abc values('ert','ert')
> insert into xyz values('rtert','rtyrty')
> if the insert operation fails for the table xyz then the insert for abc
> should not be commited.
> thnks
> vanitha|||This involves error handling as well as transaction handling. It is a large
topic, so some
background reading will sort this out for you. The best reference to this to
pic, IMO, is the error
handling articles at:
http://www.sommarskog.se/
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Vanitha" <Vanitha@.discussions.microsoft.com> wrote in message
news:08B477A8-5335-45EB-BAC2-B76B2B2A5563@.microsoft.com...
> Hi Friends,
> In my SP i have 3 insert statements that inserts record into 3 different
> tables. If any of the inserts fail, I want to roll back any other inserts
> that is executed. how to do this. please give me an example.
> example:
> insert into abc values('ert','ert')
> insert into xyz values('rtert','rtyrty')
> if the insert operation fails for the table xyz then the insert for abc
> should not be commited.
> thnks
> vanitha|||Just adding BEGIN TRAN and COMMIT TRAN will not cut it. The first might be O
K, the second fail and
the third OK. So the first and the third are performed but not the second. Y
ou need error handling
as well (or SET XACT_ABORT ON, but almost no-one in the SQL Server community
uses this setting).
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jose G. de Jesus Jr MCP, MCDBA" <Email me> wrote in message
news:80DA1215-F68E-4FA3-BE39-3B08BD39473A@.microsoft.com...
> put your sql statement in a transaction
>
> begin transaction
> insert 1....
> insert 2....
> insert 3.......
> commit transaction
>
> --
>
> <hr>
> MCP #2324787
>
> "Vanitha" wrote:
>|||Thanks
"Tibor Karaszi" wrote:

> This involves error handling as well as transaction handling. It is a larg
e topic, so some
> background reading will sort this out for you. The best reference to this
topic, IMO, is the error
> handling articles at:
> http://www.sommarskog.se/
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Vanitha" <Vanitha@.discussions.microsoft.com> wrote in message
> news:08B477A8-5335-45EB-BAC2-B76B2B2A5563@.microsoft.com...
>

Friday, March 9, 2012

Insert running slow

Are inserts really slow in 2005 or am I doing something stupid?
Here's the table:
CREATE TABLE [dbo].[Tickets](
[ticket] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[data] [varchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[added] [datetime] NOT NULL CONSTRAINT [DF_Tickets_added] DEFAULT
(getdate()),
[lastUpdated] [datetime] NOT NULL,
CONSTRAINT [PK_Tickets] PRIMARY KEY CLUSTERED
(
[ticket] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
I wrote this stored procedure:
ALTER PROCEDURE [dbo].[CreateTicket]
@.ticket varchar(20) OUTPUT,
@.data varchar(2000)
AS
DECLARE @.key varchar(20)
DECLARE @.len int
DECLARE @.added bit
DECLARE @.cypher varchar(52)
SET NOCOUNT ON;
SET @.added=0
SET @.cypher='abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789'
WHILE @.added=0
BEGIN
SELECT @.key='', @.len=20
WHILE @.len>0
BEGIN
-- The following line is the SLOW one!!!
SET @.key = @.key + SUBSTRING(@.cypher, CAST(FLOOR(RAND()*52) AS int)+1,1)
SET @.len = @.len -1
END
IF NOT EXISTS(SELECT 1 FROM Tickets WHERE ticket=@.key)
BEGIN
INSERT INTO Tickets (ticket, data,lastupdated) VALUES(@.key, @.data,GETDATE())
SET @.ticket = @.key
SET @.added = 1
END
END
And then used this to test it's speed:
DECLARE @.ticket varchar(20)
DECLARE @.sec datetime
DECLARE @.cnt int
TRUNCATE TABLE Tickets
SET @.cnt = 0
SET @.sec = DATEADD(second, 1, GETDATE())
WHILE GETDATE()<@.sec
BEGIN
EXEC CreateTicket @.ticket, 'this is a test'
SET @.cnt=@.cnt + 1
END
PRINT @.cnt
When I run this on SQL 2000, I get roughly 3000 records a second. When I
run it against 2005 I get roughly 160 records per second! The statement tha
t
is taking all the time in 2005 is the insert statement!
On 2005 if I comment it out I can execute 8,600ish loops per second. If it
isn't commented out I run 160ish.
On 2000 if I comment it out I can execute 5,900 loops per second, If it
isn't commented out I run 3,000ish.
Is inserting really that expensive or am I missing some knob I forgot to tur
n?Never mind. It appears there's something wrong with the server I was testin
g
on. Testing on another server I got 5,600ish inserts per second. What's
really weird though is the box that's performing slowing is a faster box tha
n
either of the other two with faster disks. Guess it's time to reinstall :)|||Before reinstalling, I would check perfmon and profiler and see what is
actually taking so long. It might be something easy to fix (or it might be
that reinstalling would cause the same performance problems.) A reinstall
might be in order, but unless that is really easy to do for you, it is
probably just something in how something is set up.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Larry Charlton" <LarryCharlton@.discussions.microsoft.com> wrote in message
news:A378F5F2-63BC-4FE0-AD6D-DFBB2952BB06@.microsoft.com...
> Never mind. It appears there's something wrong with the server I was
> testing
> on. Testing on another server I got 5,600ish inserts per second. What's
> really weird though is the box that's performing slowing is a faster box
> than
> either of the other two with faster disks. Guess it's time to reinstall
> :)
>

Wednesday, March 7, 2012

Insert Record Logic Needed

Im trying to write some sql which inserts these rows into another table
called move. Unfortunately i am struggling trying to get the insert statemen
t
not to insert record 5 because the ToURN has been used before in a previous
record(1). Does anyone know how I would write the sql to do this.
RecNO MergeFromURN MergeToURN MergeDateMerged
1 100 200 15/06/1982
2 200 300 15/06/1982
3 300 400 15/06/1982
4 500 600 15/06/1982
5 700 100 15/06/1982
6 100 100 15/06/1982
7 NULL 100 15/06/1982
8 700 0 15/06/1982
So far I have the following sql but need to go that step further to stop
record 5 being inserted because 100 already has been inserted as a from urn
in record 1.
INSERT INTO MOVE (MOVEFROMURN, MOVETOURN, MOVEDATEMERGED)
SELECT MergeFromURN, MergeToURN, MIN(MergeDateMerged)
from myTable
where MergeFromURN is not null and MergeToURN is not null
and MergeFromURN <> 0 and MergeToURN <> 0 and
MergeFromURN <> MergeToURN and
(MergeFromURN not in (select MoveFromURN from Move) and MergeToURN not in
(select MoveToURN from Move))
GROUP BY MergeFromURN, MergeToURN
Order by MergeFromURN
while @.@.ROWCOUNT > 0
begin
update A set MoveToURN = B.MoveToURN
from Move A
inner join Move B on A.MoveToURN=B.MoveFromURN
end
Can anyone help me with this.Are you aware of the fact that at least once several people hav tried to hel
p
you?
Maybe you should read their responses...
http://msdn.microsoft.com/newsgroup...92-6b6386cb16a1
ML

Friday, February 24, 2012

Insert performance/nvarchar

hello,
i wrote a performance test for sequential inserts with ado.net on a P4 2GHz
512 Meg Ram machine
and got the following scores:
insert 10000 ints 1:30 mins
insert 10000 reals 1:20 mins
inserting 10000 nvarchars
first 10000: 1:30
second 10000: 4:11
third 10000: 6:50
fourth 10000: 9:30
fifth 10000: 12:12
sixth 10000: 15:00
seventh 10000 18:20
so the times gets worse and worse.
i would expect, that the convergate but they don't
Is this normal?
If yes we will have problems, because we expect a couple of millions entries
in this
table where this strings are stored.
all tables for the performance test have the same stucture and indices
except of
the datatype which is tested, which is
id
value
Can you give me a hint how to speed this?
thanks mike
Do you have your databases auto-growing during these tests, or did you set
the files to a large enough size before the tests to ensure that they
wouldn't grow?
Do you have the columns indexed? Are the inserts causing page splits?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
news:E8610339-B39C-4A69-BD95-7EA882D0D228@.microsoft.com...
> hello,
> i wrote a performance test for sequential inserts with ado.net on a P4
2GHz
> 512 Meg Ram machine
> and got the following scores:
> insert 10000 ints 1:30 mins
> insert 10000 reals 1:20 mins
> inserting 10000 nvarchars
> first 10000: 1:30
> second 10000: 4:11
> third 10000: 6:50
> fourth 10000: 9:30
> fifth 10000: 12:12
> sixth 10000: 15:00
> seventh 10000 18:20
> so the times gets worse and worse.
> i would expect, that the convergate but they don't
> Is this normal?
> If yes we will have problems, because we expect a couple of millions
entries
> in this
> table where this strings are stored.
> all tables for the performance test have the same stucture and indices
> except of
> the datatype which is tested, which is
> id
> value
> Can you give me a hint how to speed this?
> thanks mike
|||Hello Adam,
yes its auto-growing
yes columns are indexed
most inserts are NOT causing page splits
thanks mike
"Adam Machanic" wrote:

> Do you have your databases auto-growing during these tests, or did you set
> the files to a large enough size before the tests to ensure that they
> wouldn't grow?
> Do you have the columns indexed? Are the inserts causing page splits?
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:E8610339-B39C-4A69-BD95-7EA882D0D228@.microsoft.com...
> 2GHz
> entries
>
>
|||You'll get more consistent results if you grow the file first...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
news:857ED961-21D6-4B62-B2DF-07B3FB24F3FA@.microsoft.com...[vbcol=seagreen]
> Hello Adam,
> yes its auto-growing
> yes columns are indexed
> most inserts are NOT causing page splits
> thanks mike
>
> "Adam Machanic" wrote:
set[vbcol=seagreen]
|||hello adam,
nope,
i dropped the old database, created a new one with fixed size
600 meg (for data and tranlog).
The behaviour is still the same.
The insert times are growing endless.
greetings mike
"Adam Machanic" wrote:

> You'll get more consistent results if you grow the file first...
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:857ED961-21D6-4B62-B2DF-07B3FB24F3FA@.microsoft.com...
> set
>
>
|||Can you post the table definitions, including constraints and indexes?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...[vbcol=seagreen]
> hello adam,
> nope,
> i dropped the old database, created a new one with fixed size
> 600 meg (for data and tranlog).
> The behaviour is still the same.
> The insert times are growing endless.
> greetings mike
>
> "Adam Machanic" wrote:
you[vbcol=seagreen]
they[vbcol=seagreen]
splits?[vbcol=seagreen]
message[vbcol=seagreen]
a P4[vbcol=seagreen]
millions[vbcol=seagreen]
indices[vbcol=seagreen]
|||Hello Adam,
here comes the table
create table LogStringTable
(
ID int identity (1,1) not null,
stringValue nvarchar(400) not null,
attributeTypeId int not null,
logItemId int not null
constraint FKATIhasStringValues
foreign key ( attributeTypeId )
references LogAttributeType (Id),
constraint FKItemHasStringvalues
foreign key (LogItemId )
references LogItem ( Id )
) on primary
there are four indices
primary key index on Id (clustered)
and an the other columns (not unique)
thank you mike
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>
|||Hello Adam,
I dropped all indices and tried again
-> nothing principaly changed.
The times are shorter, but they are still growing endless,
with each 10000 insert.
When I have 100.000 entries in that table than the performance is reduce to
about
15 inserts/second compared with 100 inserts/second when starting with a
blank table.
And the performance goes down and down.
Greets mike
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>
|||hello adam,
i know now, that it is not a problem if the sql server.
it has to do with ado.net.
currently i don't know what it is, but now I inserted 10.000 nvarchars with
the
query analyzer and it lasts about 5 seconds
regardless how many records are in the table.
so i have to look into the ado.net stuff.
thank you for your help
I'll let you know what is is, when i know it.
thank you very much
greets michael
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>
|||Hello Adam,
I got it.
There is an option at the data adapter called
refresh the dataset
This was set to true.
I set it to false and now my world is perpendicular again.
The insert times for 10.000 stings are now about 5-7 seconds.
Unfortunatly, I even didn't use a dataset, so this option is useless even
when set to true.
I think this is worthy a microsoft call.
thank you for your help.
mike.
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>

Insert performance/nvarchar

hello,
i wrote a performance test for sequential inserts with ado.net on a P4 2GHz
512 Meg Ram machine
and got the following scores:
insert 10000 ints 1:30 mins
insert 10000 reals 1:20 mins
inserting 10000 nvarchars
first 10000: 1:30
second 10000: 4:11
third 10000: 6:50
fourth 10000: 9:30
fifth 10000: 12:12
sixth 10000: 15:00
seventh 10000 18:20
so the times gets worse and worse.
i would expect, that the convergate but they don't
Is this normal?
If yes we will have problems, because we expect a couple of millions entries
in this
table where this strings are stored.
all tables for the performance test have the same stucture and indices
except of
the datatype which is tested, which is
id
value
Can you give me a hint how to speed this?
thanks mikeDo you have your databases auto-growing during these tests, or did you set
the files to a large enough size before the tests to ensure that they
wouldn't grow?
Do you have the columns indexed? Are the inserts causing page splits?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
news:E8610339-B39C-4A69-BD95-7EA882D0D228@.microsoft.com...
> hello,
> i wrote a performance test for sequential inserts with ado.net on a P4
2GHz
> 512 Meg Ram machine
> and got the following scores:
> insert 10000 ints 1:30 mins
> insert 10000 reals 1:20 mins
> inserting 10000 nvarchars
> first 10000: 1:30
> second 10000: 4:11
> third 10000: 6:50
> fourth 10000: 9:30
> fifth 10000: 12:12
> sixth 10000: 15:00
> seventh 10000 18:20
> so the times gets worse and worse.
> i would expect, that the convergate but they don't
> Is this normal?
> If yes we will have problems, because we expect a couple of millions
entries
> in this
> table where this strings are stored.
> all tables for the performance test have the same stucture and indices
> except of
> the datatype which is tested, which is
> id
> value
> Can you give me a hint how to speed this?
> thanks mike|||Hello Adam,
yes its auto-growing
yes columns are indexed
most inserts are NOT causing page splits
thanks mike
"Adam Machanic" wrote:

> Do you have your databases auto-growing during these tests, or did you set
> the files to a large enough size before the tests to ensure that they
> wouldn't grow?
> Do you have the columns indexed? Are the inserts causing page splits?
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:E8610339-B39C-4A69-BD95-7EA882D0D228@.microsoft.com...
> 2GHz
> entries
>
>|||You'll get more consistent results if you grow the file first...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
news:857ED961-21D6-4B62-B2DF-07B3FB24F3FA@.microsoft.com...[vbcol=seagreen]
> Hello Adam,
> yes its auto-growing
> yes columns are indexed
> most inserts are NOT causing page splits
> thanks mike
>
> "Adam Machanic" wrote:
>
set[vbcol=seagreen]|||hello adam,
nope,
i dropped the old database, created a new one with fixed size
600 meg (for data and tranlog).
The behaviour is still the same.
The insert times are growing endless.
greetings mike
"Adam Machanic" wrote:

> You'll get more consistent results if you grow the file first...
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:857ED961-21D6-4B62-B2DF-07B3FB24F3FA@.microsoft.com...
> set
>
>|||Can you post the table definitions, including constraints and indexes?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...[vbcol=seagreen]
> hello adam,
> nope,
> i dropped the old database, created a new one with fixed size
> 600 meg (for data and tranlog).
> The behaviour is still the same.
> The insert times are growing endless.
> greetings mike
>
> "Adam Machanic" wrote:
>
you[vbcol=seagreen]
they[vbcol=seagreen]
splits?[vbcol=seagreen]
message[vbcol=seagreen]
a P4[vbcol=seagreen]
millions[vbcol=seagreen]
indices[vbcol=seagreen]|||Hello Adam,
here comes the table
create table LogStringTable
(
ID int identity (1,1) not null,
stringValue nvarchar(400) not null,
attributeTypeId int not null,
logItemId int not null
constraint FKATIhasStringValues
foreign key ( attributeTypeId )
references LogAttributeType (Id),
constraint FKItemHasStringvalues
foreign key (LogItemId )
references LogItem ( Id )
) on primary
there are four indices
primary key index on Id (clustered)
and an the other columns (not unique)
thank you mike
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>|||Hello Adam,
I dropped all indices and tried again
-> nothing principaly changed.
The times are shorter, but they are still growing endless,
with each 10000 insert.
When I have 100.000 entries in that table than the performance is reduce to
about
15 inserts/second compared with 100 inserts/second when starting with a
blank table.
And the performance goes down and down.
Greets mike
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>|||hello adam,
i know now, that it is not a problem if the sql server.
it has to do with ado.net.
currently i don't know what it is, but now I inserted 10.000 nvarchars with
the
query analyzer and it lasts about 5 seconds
regardless how many records are in the table.
so i have to look into the ado.net stuff.
thank you for your help
I'll let you know what is is, when i know it.
thank you very much
greets michael
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>|||Hello Adam,
I got it.
There is an option at the data adapter called
refresh the dataset
This was set to true.
I set it to false and now my world is perpendicular again.
The insert times for 10.000 stings are now about 5-7 seconds.
Unfortunatly, I even didn't use a dataset, so this option is useless even
when set to true.
I think this is worthy a microsoft call.
thank you for your help.
mike.
"Adam Machanic" wrote:

> Can you post the table definitions, including constraints and indexes?
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Michael Zdarsky" <zdarsky@.zac-it.com.(nospamplease)> wrote in message
> news:021A9342-82D0-48B5-8746-9F6E013AC032@.microsoft.com...
> you
> they
> splits?
> message
> a P4
> millions
> indices
>
>