Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
I’m sorry that my question is long, but I’m beginner in databases and I need serious help
My problem is that’s my first professional program, it’s shop management system, but I’ve a few experience in databases
I built this program with (C# & SQL Server 2014)
I’m afraid of the data handling on windows form (datagridview) specially after 1 or 2 years there will be a huge number of records in the database
I see win Forms dealing with data in a perfect way while database contains a few records just for testing, it's perfect in searching using sql statements and everything, but i don't know what will be the situation after years of data inserting

What I have tried:

I tried to follow the data normalization theory in some tables
This is a simple explain to my project, for anyone with experience read and tell me I’m on the right way or what:
I’ve table for products, and a table for sell bills(invoices) including some columns: (Invoice ID\ Client ID, total price, payed, remains, Date)
And another table named (Bill Content) this table contains products ID’s that linked to specific bill by bill id (this table will be huge, let’s say user will insert 300 bills per day and every bill contains about 1-5 records in the content table, this is what I’m afraid of) and using (JOIN) to retrieve bill content, to avoid data repeat and reduce data size
Is that’s right? Is that’s the concept of data normalization?
but for some reason I’ve to break this role in the activity table that every action (Deposit, withdrawal, sell operation, etc. ) every action will be inserted with nvarchar(MAX) cell to describe this operation (sell or buy or salary)
can I do that or repeated text cell will affects the database performance? specially after 1 or 2 years there will be a huge number of records.
Posted
Updated 1-Jun-17 17:50pm
Comments
RossMW 1-Jun-17 22:43pm    
Generic questions are hard for us to answer as the answer realy will depend on the specifics.

I suggest SQL books and fully understanding databases first as to change the structure afterwards can be a major mission.

Generally speaking if the table are properly indexed and the structure is correct then SQL performance will not be the issue. Joins and indexes will generally work better on numeric type fields

Try to avoid nvarchar(Max) unless the number of records is small. Better to fully determine the size of the data and have a field size to suit.

1 solution

As your question is generic it's possible to answer only on generic level, but few points you should consider.

First of all, you emphasize Forms as a technology but actually the technology you use for the user interface is not affecting the efficiency of the database usage.The key point is how you connect to the database, which technology you use, how you query the database and so on.

As you said, one goal for normalization is to prevent repetitive data in order to keep the size smaller, but that's not all. The other aspect is to keep modifications simple. Since the data exists only in one place, if it is modified, it needs to be modified only in one place. This saves time and effort when changes occur. The same principle applies to calculated data. You should try to avoid storing calculated data and instead do the calculations when fetching the data.

Now what comes to speed itself, indexing is the main thing here. In order for the database to work efficiently, you need proper indexing to support all your operations. Remember, indexing does not only affect selecting. It also affects inserts, updates, and deletions, both in good and bad. This is why you need to carefully decide which indexes to build so that they support your WHERE clauses. Try to avoid over-indexing as this slows the modifications.

Another key thing is how you use the database in your program. Always fetch only the data you need, no more. This means that you should filter the data in the SQL, not on the client side.

About the design. Try to prefer 3rd normal form, this keeps the database structure easy to understand. Also do use surrogates as primary keys. This helps you to avoid unnecessary updates on referenced key fields.

One big thing is the data types. Remember to use correct data types for each column. Do not use varchar for dates and so on. Also never use fields that contain multiple data items, instead split them to separate columns.

Good luck :)
 
Share this answer
 
Comments
XRushdy 2-Jun-17 2:18am    
I really appreciate your help, this exactly what i need.
Obviously you understood my question very well
So you've pointed me to some valuable informations that i always needed, not just in this project.
And I know that my question is primitive (just generic informations) but i doubted that anyone will understand what I meant
Now you say this is the right way to deal with big database: two tables for example
XRushdy 2-Jun-17 2:18am    
Bill table be like:
Bill_ID(AutoNum&PrimaryKey) \ Date \ Client_ID \ notes \ etc.
XRushdy 2-Jun-17 2:19am    
And Bill content table be like:
Some AutoNum&PrimaryKey \ Bill_ID \Product_name \Brand\etc.
XRushdy 2-Jun-17 2:19am    
And just make the two columns(Bill_ID) are the same integer number? And when retrieving specific Bill content search in content table for records that carries the Bill_ID value? Is that indexing that you talked about?
One last thing, can you please explain in a few lines what you mean by “ Also do use surrogates as primary keys” or just apply this theory to my example that I talked about).
Finally I want to say again that I appreciate your respond it was so helpful and any other instructions you can say about this example I will be grateful to read.
Wendelius 2-Jun-17 13:24pm    
About indexing. Primary and unique keys are indexed automatically. What you need to do is to create sufficient indexes on other columns to support operations. For example in your example, the Bill_Id should be indexed in BillContent table because you're going to use it excessively in select statements.

Then about surrogates, it's a key that has no other purpose than to be just a key. One example is autonumbered field as you have used in your example. You cand find more information in Surrogate key - Wikipedia[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900