Showing posts with label records. Show all posts
Showing posts with label records. Show all posts

Thursday, March 29, 2012

Consolidate records

I consider security A to be equivalent to C so I want to consolidate these
positions. Three scenarios:
If an account holds both A and C I want to add the C quantity to the A
position and delete the C position.
If the account holds A but not C then no action.
If the account holds C but not A I want to update the C position to A.
My requirements are such that I need UPDATE and DELETE statement not a
SELECT statement so that my desired results would be produced by SELECT *
FROM #Positions
Any help would be appreciated.
CREATE TABLE [dbo].[#Positions] (
[AccountID] [int] NOT NULL ,
[SecurityID] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Quantity] [int] NULL
) ON [PRIMARY]
GO
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (1,'A',20)
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (1,'B',25)
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (1,'C',25)
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (2,'A',15)
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (2,'B',5)
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (3,'B',5)
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (3,'C',10)
INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (4,'C',15)
Expected results
1,A,45
1,B,25
2,A,15
2,B,5
3,A,10
3,B,5
4,A,15Please explain NULL quantity to me; I understand >=0, but not a NULL.
Create a synonym table,then create a VIEW with the base name and totals
and use it.|||Terri
The following UPDATE/DELETE statemenst should help you out:
-- Update SecurityID A with the values for SecurityID C where the AccountID
is the same
UPDATE a
SET a.quantity = a.quantity + b.quantity
FROM #Positions a JOIN #Positions b
ON a.accountid = b.accountid
AND a.securityid = 'A'
AND b.securityid = 'C'
-- Delete any of the SecurityID C rows that were used in the previous update
DELETE b
FROM #Positions a JOIN #Positions b
ON a.accountid = b.accountid
AND a.securityid = 'A'
AND b.securityid = 'C'
-- Update SecurityID C to SecurityID A
UPDATE #Positions
SET securityid = 'A'
WHERE securityid = 'C'
- Peter Ward
WARDY IT Solutions
"Terri" wrote:

> I consider security A to be equivalent to C so I want to consolidate these
> positions. Three scenarios:
> If an account holds both A and C I want to add the C quantity to the A
> position and delete the C position.
> If the account holds A but not C then no action.
> If the account holds C but not A I want to update the C position to A.
> My requirements are such that I need UPDATE and DELETE statement not a
> SELECT statement so that my desired results would be produced by SELECT *
> FROM #Positions
> Any help would be appreciated.
> CREATE TABLE [dbo].[#Positions] (
> [AccountID] [int] NOT NULL ,
> [SecurityID] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [Quantity] [int] NULL
> ) ON [PRIMARY]
> GO
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (1,'A',20)
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (1,'B',25)
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (1,'C',25)
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (2,'A',15)
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (2,'B',5)
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (3,'B',5)
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (3,'C',10)
> INSERT INTO #Positions (AccountID,SecurityID,Quantity) VALUES (4,'C',15)
> Expected results
> 1,A,45
> 1,B,25
> 2,A,15
> 2,B,5
> 3,A,10
> 3,B,5
> 4,A,15
>
>sqlsql

Tuesday, March 27, 2012

Consistency Errors - Large Table

I have a large table with 10 million records. It has only one clustered
index (0% fill factor) Total size of database is about 15 GB.
I am always running into consistency errors. It's frustating. Every two
days or so I run into a problem.
I have switched to another computer, and still getting errors, so I'm
not sure if it's a hardware problem or not.
Every day I run a query to update 3 million records in this table from
a flat file.
I get consistency errors often.
Object ID 802101898, index ID 0: Page (1:416734) could not be
processed. See other errors for details.
Server: Msg 8944, Level 16, State 1, Line 1
Table error: Object ID 802101898, index ID 0, page (1:416734), row 8.
Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 2477 and
535.
So I run CHECKDB with repair errors but that doesn't always help. So I
have to restore from the latest backup.
Could someone shed some light on this problem?You should contact Product Support to help you. Most likely its hardware
errors. When you switched to anothe computer, did you move the database to a
new IO subsystem and make sure it was clean of all consistency errors?
Paul Randal
Lead Program Manager, Microsoft SQL Server Storage Engine
http://blogs.msdn.com/sqlserverstor...ne/default.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
<simone_maynard@.hotmail.com> wrote in message
news:1152928287.932830.124060@.h48g2000cwc.googlegroups.com...
>I have a large table with 10 million records. It has only one clustered
> index (0% fill factor) Total size of database is about 15 GB.
> I am always running into consistency errors. It's frustating. Every two
> days or so I run into a problem.
> I have switched to another computer, and still getting errors, so I'm
> not sure if it's a hardware problem or not.
> Every day I run a query to update 3 million records in this table from
> a flat file.
> I get consistency errors often.
> Object ID 802101898, index ID 0: Page (1:416734) could not be
> processed. See other errors for details.
> Server: Msg 8944, Level 16, State 1, Line 1
> Table error: Object ID 802101898, index ID 0, page (1:416734), row 8.
> Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 2477 and
> 535.
> So I run CHECKDB with repair errors but that doesn't always help. So I
> have to restore from the latest backup.
> Could someone shed some light on this problem?
>|||Version of SQLServer including SPs? OS and SPs? SQL? DDL for table?
J.
On 14 Jul 2006 18:51:27 -0700, simone_maynard@.hotmail.com wrote:
>I have a large table with 10 million records. It has only one clustered
>index (0% fill factor) Total size of database is about 15 GB.
>I am always running into consistency errors. It's frustating. Every two
>days or so I run into a problem.
>I have switched to another computer, and still getting errors, so I'm
>not sure if it's a hardware problem or not.
>Every day I run a query to update 3 million records in this table from
>a flat file.
>I get consistency errors often.
>Object ID 802101898, index ID 0: Page (1:416734) could not be
>processed. See other errors for details.
>Server: Msg 8944, Level 16, State 1, Line 1
>Table error: Object ID 802101898, index ID 0, page (1:416734), row 8.
>Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 2477 and
>535.
>So I run CHECKDB with repair errors but that doesn't always help. So I
>have to restore from the latest backup.
>Could someone shed some light on this problem?

Consistency Errors - Large Table

I have a large table with 10 million records. It has only one clustered
index (0% fill factor) Total size of database is about 15 GB.
I am always running into consistency errors. It's frustating. Every two
days or so I run into a problem.
I have switched to another computer, and still getting errors, so I'm
not sure if it's a hardware problem or not.
Every day I run a query to update 3 million records in this table from
a flat file.
I get consistency errors often.
Object ID 802101898, index ID 0: Page (1:416734) could not be
processed. See other errors for details.
Server: Msg 8944, Level 16, State 1, Line 1
Table error: Object ID 802101898, index ID 0, page (1:416734), row 8.
Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 2477 and
535.
So I run CHECKDB with repair errors but that doesn't always help. So I
have to restore from the latest backup.
Could someone shed some light on this problem?You should contact Product Support to help you. Most likely its hardware
errors. When you switched to anothe computer, did you move the database to a
new IO subsystem and make sure it was clean of all consistency errors?
--
Paul Randal
Lead Program Manager, Microsoft SQL Server Storage Engine
http://blogs.msdn.com/sqlserverstorageengine/default.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
<simone_maynard@.hotmail.com> wrote in message
news:1152928287.932830.124060@.h48g2000cwc.googlegroups.com...
>I have a large table with 10 million records. It has only one clustered
> index (0% fill factor) Total size of database is about 15 GB.
> I am always running into consistency errors. It's frustating. Every two
> days or so I run into a problem.
> I have switched to another computer, and still getting errors, so I'm
> not sure if it's a hardware problem or not.
> Every day I run a query to update 3 million records in this table from
> a flat file.
> I get consistency errors often.
> Object ID 802101898, index ID 0: Page (1:416734) could not be
> processed. See other errors for details.
> Server: Msg 8944, Level 16, State 1, Line 1
> Table error: Object ID 802101898, index ID 0, page (1:416734), row 8.
> Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 2477 and
> 535.
> So I run CHECKDB with repair errors but that doesn't always help. So I
> have to restore from the latest backup.
> Could someone shed some light on this problem?
>|||Version of SQLServer including SPs? OS and SPs? SQL? DDL for table?
J.
On 14 Jul 2006 18:51:27 -0700, simone_maynard@.hotmail.com wrote:
>I have a large table with 10 million records. It has only one clustered
>index (0% fill factor) Total size of database is about 15 GB.
>I am always running into consistency errors. It's frustating. Every two
>days or so I run into a problem.
>I have switched to another computer, and still getting errors, so I'm
>not sure if it's a hardware problem or not.
>Every day I run a query to update 3 million records in this table from
>a flat file.
>I get consistency errors often.
>Object ID 802101898, index ID 0: Page (1:416734) could not be
>processed. See other errors for details.
>Server: Msg 8944, Level 16, State 1, Line 1
>Table error: Object ID 802101898, index ID 0, page (1:416734), row 8.
>Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 2477 and
>535.
>So I run CHECKDB with repair errors but that doesn't always help. So I
>have to restore from the latest backup.
>Could someone shed some light on this problem?

Considerations when delete records from table.

Hello, I'm developing application which monitors network packets. The monitoring data are saved into table. Monitoring table maintains the data for fixed quantum time,for example during one 1 hour. So, every minute before or after insert new data, I delete the time-expired data. I doubt that the endless delete operation would results in some problems(increasing index,etc..).

Is this mechanism safe to the dbms?

Aren't there round-robin(?) style table?

thats wat OLTP is for.... just keep the update statistics to auto (its default) , if ur using indexes.....also there may be fragmentation issues ...but thats a DBA activity/Db maintainance...

Consecutive numbering WITHOUT Identity

Hi,

I'mtrying to insert records from one table into another table. Thedestination table has a ROWID field which cannot be an identity key,but needs to 'act like' an identity key and have its value populatedwith (Max(ROWID) + 1) for each row added to the table.

To mythinking, simply using (Max(ROWID) + 1) in my SELECT statement will notwork as it will only be evaluated once so if I am adding 1000 recordsand Max(ROWID) is 1234, all 1000 entries will end up having a ROWID of1235.

Is there a way to accomplish this?

Thanks

Hi,

you can increment the row id locally in your program after doing an update in a loop:
rowID = <select max rowid blablabla>
while <there are still rows to add>
Command.executenonquery() - using rowID
rowID +=1
Loop

you can also use a trigger in the database to update the rowid column after insert

|||

Yes.

You can readMax(ROWID) from database intoApplication("id") at the start of web application,e.g. 1234 to avoid frequent access to database.

After insert just add id by 1.

Hope it helps.

Sunday, March 25, 2012

Connectivity with sql server

The problem what iam facing,is while updating records from
a network system to sql server,the time taken is very high.
I would like to know how to make faster updation of record
to my sql database.
And what role does ODBC play here.and is there any log
file or temporary files created at server end,if i would
like to know the path.and does it got to do anything with
the record updation speed.
I would be a great help for me...!!What type of update are you doing? Is this a one-time thing or a
continuously needed update? What is your table structure, what does your
update statement look like? Do you have indexes on the table? What recovery
mode are you running the database in? How many users are connected to the
server when you run this update? Are there any locking/blocking issues? Lots
of questions, answer them and I'm sure someone can help.
Ray Higdon MCSE, MCDBA, CCNA
--
"ssd" <ssd_myworld@.yahoo.com.sg> wrote in message
news:0e8e01c3deff$e7afc9f0$a601280a@.phx.gbl...
quote:

> The problem what iam facing,is while updating records from
> a network system to sql server,the time taken is very high.
> I would like to know how to make faster updation of record
> to my sql database.
> And what role does ODBC play here.and is there any log
> file or temporary files created at server end,if i would
> like to know the path.and does it got to do anything with
> the record updation speed.
> I would be a great help for me...!!
|||I got one sql server connected to 5 workstations,A small
vb application which updates 10-15 fileds,submission of
each record is taking 35-40secs,we will be updating 50
records at a time span of 30-45 minutes.
Here the time taken to update each record is pain taking.
How can i over come this problem inorder to submit my
records faster.
And ODBC got to do anything at workstation end,i mean we
got to configure ODBC at workstation.sqlsql

Monday, March 19, 2012

ConnectionCheckForData Error on Delete

Hi,
I'm trying to delete 1.5 million records from at table containing 121
million records using a delete with a simple subquery. After some time
processing the following error message is returned in Query Analyzer:
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
(CheckforData()).
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation.
Connection Broken
The system is Windows 2000 Server (SP4) and SQL Server 2000 EE (SP3 -
8.00.818).
I did some checking on the net and saw where an install of SP3a fixed a
related error message however the KB states that because most of the issues
are related to setup that SP3a need not be installed if SP3 is currently
installed.
Has anyone encountered this problem and if so how did you resolve it?
Thanks
JerryFollow up:
Ran the delete statement directly from QA on the SQL Server to remove the
network connectivity as a possible issue. Received the following error:
Server: Msg 8646, Level 21, State 1, Line 1
The index entry for row ID was not found in index ID 2, of table 1403152044,
in database 'XXX'.
Connection Broken
Referenced to KB Article 822747 - possible corrupt nonclustered index.
Dropped the NC index and the deleted now succeeded. Now rebuilding the NC
index again.
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:eC3SJlWXFHA.3188@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I'm trying to delete 1.5 million records from at table containing 121
> million records using a delete with a simple subquery. After some time
> processing the following error message is returned in Query Analyzer:
> [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
> (CheckforData()).
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation.
> Connection Broken
> The system is Windows 2000 Server (SP4) and SQL Server 2000 EE (SP3 -
> 8.00.818).
> I did some checking on the net and saw where an install of SP3a fixed a
> related error message however the KB states that because most of the
> issues are related to setup that SP3a need not be installed if SP3 is
> currently installed.
> Has anyone encountered this problem and if so how did you resolve it?
> Thanks
> Jerry
>

ConnectionCheckForData Error on Delete

Hi,
I'm trying to delete 1.5 million records from at table containing 121
million records using a delete with a simple subquery. After some time
processing the following error message is returned in Query Analyzer:
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForD
ata
(CheckforData()).
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation.
Connection Broken
The system is Windows 2000 Server (SP4) and SQL Server 2000 EE (SP3 -
8.00.818).
I did some checking on the net and saw where an install of SP3a fixed a
related error message however the KB states that because most of the issues
are related to setup that SP3a need not be installed if SP3 is currently
installed.
Has anyone encountered this problem and if so how did you resolve it?
Thanks
JerryFollow up:
Ran the delete statement directly from QA on the SQL Server to remove the
network connectivity as a possible issue. Received the following error:
Server: Msg 8646, Level 21, State 1, Line 1
The index entry for row ID was not found in index ID 2, of table 1403152044,
in database 'XXX'.
Connection Broken
Referenced to KB Article 822747 - possible corrupt nonclustered index.
Dropped the NC index and the deleted now succeeded. Now rebuilding the NC
index again.
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:eC3SJlWXFHA.3188@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I'm trying to delete 1.5 million records from at table containing 121
> million records using a delete with a simple subquery. After some time
> processing the following error message is returned in Query Analyzer:
> [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckFo
rData
> (CheckforData()).
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation.
> Connection Broken
> The system is Windows 2000 Server (SP4) and SQL Server 2000 EE (SP3 -
> 8.00.818).
> I did some checking on the net and saw where an install of SP3a fixed a
> related error message however the KB states that because most of the
> issues are related to setup that SP3a need not be installed if SP3 is
> currently installed.
> Has anyone encountered this problem and if so how did you resolve it?
> Thanks
> Jerry
>

ConnectionCheckForData Error on Delete

Hi,
I'm trying to delete 1.5 million records from at table containing 121
million records using a delete with a simple subquery. After some time
processing the following error message is returned in Query Analyzer:
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
(CheckforData()).
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation.
Connection Broken
The system is Windows 2000 Server (SP4) and SQL Server 2000 EE (SP3 -
8.00.818).
I did some checking on the net and saw where an install of SP3a fixed a
related error message however the KB states that because most of the issues
are related to setup that SP3a need not be installed if SP3 is currently
installed.
Has anyone encountered this problem and if so how did you resolve it?
Thanks
Jerry
Follow up:
Ran the delete statement directly from QA on the SQL Server to remove the
network connectivity as a possible issue. Received the following error:
Server: Msg 8646, Level 21, State 1, Line 1
The index entry for row ID was not found in index ID 2, of table 1403152044,
in database 'XXX'.
Connection Broken
Referenced to KB Article 822747 - possible corrupt nonclustered index.
Dropped the NC index and the deleted now succeeded. Now rebuilding the NC
index again.
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:eC3SJlWXFHA.3188@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I'm trying to delete 1.5 million records from at table containing 121
> million records using a delete with a simple subquery. After some time
> processing the following error message is returned in Query Analyzer:
> [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
> (CheckforData()).
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation.
> Connection Broken
> The system is Windows 2000 Server (SP4) and SQL Server 2000 EE (SP3 -
> 8.00.818).
> I did some checking on the net and saw where an install of SP3a fixed a
> related error message however the KB states that because most of the
> issues are related to setup that SP3a need not be installed if SP3 is
> currently installed.
> Has anyone encountered this problem and if so how did you resolve it?
> Thanks
> Jerry
>

Saturday, February 25, 2012

Connection string to SQL Server database

I am a java programmer and currently developing a web application that is suposed to keep records of all Computers that are purchased or written off. I have my database sitting at MSSQL server express ed. 2005 and so far i only know to connect to Access DB. Can someone help me with the syntax to connect to MSSQL server.

reply to [email removed]

Quote:

Originally Posted by Java25

I am a java programmer and currently developing a web application that is suposed to keep records of all Computers that are purchased or written off. I have my database sitting at MSSQL server express ed. 2005 and so far i only know to connect to Access DB. Can someone help me with the syntax to connect to MSSQL server.

reply to Me


Check this site .. and you ll find the connections to all the existing databases in the world ;-) .. it really worked for me and I am using this for the past 4 yrs.

http://www.connectionstrings.com/

HTH..

Friday, February 10, 2012

Connection Problem with Remote Server

If I do this:
select * from tblAmcareDetail
I get my records back but as soon as try to specify column names I get:
Server: Msg 207, Level 16, State 3, Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name
'apexorderid'.
I think it must be a connection problem because I don't have this problem on
local servers. The server is registered by it's ip address and I'm running
the query under the servers sa account.
Can anyone help?Doesn't sound like a connection problem.
Are you sure the table on the server.database you're connecting to has
this column?
Is the server/db/table you're connecting to perhaps setup with a
case-sensitive collation? If so, you'll need to query using the case of
column names as in the table definition.
Spike wrote:
> If I do this:
> select * from tblAmcareDetail
> I get my records back but as soon as try to specify column names I get:
> Server: Msg 207, Level 16, State 3, Line 1
> [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name
> 'apexorderid'.
> I think it must be a connection problem because I don't have this problem
on
> local servers. The server is registered by it's ip address and I'm runnin
g
> the query under the servers sa account.
> Can anyone help?
>