| | |
How to put New record at the end of Database Table
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 38
Reputation:
Solved Threads: 0
Dear Friends,
When i enter a new record in SQL Database from my C# application, the record stores in the database at random locations, but i want to make sure that every record must be enter at the end of the Table.
Actually i have to get the Last Balance of Customer, and it must be at the last record, but whenever i put a new record it stores at the middle or above, i need it to be store at the last so i get the last balance...
Plz help me out Dear Friends...
When i enter a new record in SQL Database from my C# application, the record stores in the database at random locations, but i want to make sure that every record must be enter at the end of the Table.
Actually i have to get the Last Balance of Customer, and it must be at the last record, but whenever i put a new record it stores at the middle or above, i need it to be store at the last so i get the last balance...
Plz help me out Dear Friends...
0
#2 15 Days Ago
>How to put New record at the end of Database Table.
A table is an unordered recordset. The position of a record in the table is not relevant unless you impose an order on it.
If your table has transaction date column then use SELECT statement with ORDER BY clause.
A table is an unordered recordset. The position of a record in the table is not relevant unless you impose an order on it.
If your table has transaction date column then use SELECT statement with ORDER BY clause.
text Syntax (Toggle Plain Text)
str="select * from tableName order by transactiondate"
Failure is not fatal, but failure to change might be. - John Wooden
0
#3 15 Days Ago
The physical order of records written to an SQL table are determined by the clustered index if one is present. If one isn't present then they are just added in the order they are inserted and likewise they are returned in the order they are selected unless you use an order by clause.
You should add a "CreateDate" column or an auto incrementing record id column to determine which record is the last record. By default an autoinc primary key column creates the clustered index unless you specify to override it.
IE default value and clustered:
A nonclustered version:
[edit]
Also if someone changes a clustered index that you are relying on to determine order than you cannot figure out by a column value then you run the risk of ruining your database by changing an index. This is a bad idea.... add another way to determine record sequence.
[/edit]
You should add a "CreateDate" column or an auto incrementing record id column to determine which record is the last record. By default an autoinc primary key column creates the clustered index unless you specify to override it.
IE default value and clustered:
sql Syntax (Toggle Plain Text)
CREATE TABLE Test ( RecordId INT identity(1000, 1) PRIMARY KEY )
A nonclustered version:
sql Syntax (Toggle Plain Text)
CREATE TABLE Test ( RecordId INT identity(1000, 1) PRIMARY KEY NONCLUSTERED )
[edit]
Also if someone changes a clustered index that you are relying on to determine order than you cannot figure out by a column value then you run the risk of ruining your database by changing an index. This is a bad idea.... add another way to determine record sequence.
[/edit]
Last edited by sknake; 15 Days Ago at 11:11 pm.
![]() |
Similar Threads
- Problem in randomizing selection from Access database table (VB.NET)
- Fields in an Access database table (VB.NET)
- Populating Listbox with database table values (VB.NET)
- Connection.Execute command to Delete Records from MS Access Database Table (Visual Basic 4 / 5 / 6)
- Help needed with code to add record to access database using VB 2005 (Visual Basic 4 / 5 / 6)
- JSP Database (JSP)
- Problem Amending Database Table (Visual Basic 4 / 5 / 6)
- database table design problems (Database Design)
Other Threads in the C# Forum
- Previous Thread: "ComException unhandeled by User Code"
- Next Thread: Connection to remote SQL Database problem in app
| Thread Tools | Search this Thread |
.net .net2008 access acquisition ado.net age amd array asp asp.net aspconnection avatar backup basic bigbrother bluegene breach c# chips cloud connectingtodatabaseinuse connection courier crm daniweb database databaseconnection databasesearch delphi development dos dreamweaver economy energy enterprise enterprisesoftware gui hacker hacking hardware ibm ibm.news images integration intelibm java linux login medicine memory microsoft msmsql mssqlserver2005 mssqlserverandasp mvc2 myregfun mysql mysql.data.client nationalsecurity news openoffice opensource operatingsystem oracle pc permission php ps3 query read recession record recovery redhat russia search security server servlet software sql sqlite sqlserver stop sun supercomputer supercomputing survey technology tracking trends ubuntu uk update vb vb.net vb6 windows working x86







