473,758 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where do I put my Database relations... at DATABASE level or in PROGRAM LEVEL?

Mybe it's a stupid question but :
I'm starting to learn VB.NET. I have some basic skills. I'm from
Mainframe world and I have same question to make my DATABASES (tables
and relation)
I would like to make ask my question by example. Let's say I'm a
sales company I'm selling products to customers. Okay?
I have these tables (databases) and fields and I have these questions.

I have created these tables in VB.NET Database Connections IDE
interface. These 3 files and fields are visually created and I have
also entered some test data.
This is the structure: 1 Customer can have Multiple order, 1
OrderHeader can have Multiple orderDetailline s.
So I only store in OrderHeader the Main things like customer, Order
remark. Everything which is related to product I store it in
OrderDetailTalb e like product, price etc.

MY Intention: I don't want to set my RELEATIONS on DATABASE level,
but in PROGRAM LEVEL, I mean I don't want to visualize to draw a line
from Customer table to Order Header and from Order Header to Order
Detail.........
In Mainframe world we don't put DATABASE relations in DATABASE level,
but in PROGRAM level. ......
My QUESTION: IS this allowed by VB.NET? Can I build an application
like this? Is this a correct way to do? Or do I need to make a Database
Relation DIAGRAM?

WHAT is your idea about it as Experienced VB.NET programmer?

1) CustomerTable
==============
- Customer ID
- Customer Name
- Customer Address
- Customer City
- Customer Country
- Customer Payment term

2) OrderHeaderTabl e
=============== ==
- Order Number
- Order Type
- Order line
- Customer ID
- OrderRemark
-

3) OrderDetailTabl e
===============
- Order Number
- Order Type
- Order line
- Customer ID
- Product
- Sales price
- Extented price
Thanks
Mesut

Mar 16 '06 #1
8 1589
TB
I am not really an expert on this but I think you obtain everything your
want by way of your SQL statement.

For example if you want to display a list of products of an order by a
particular customer, and assuming that you have created three tables
(Customers, Orders and Orderlines), your SQL statement would be something
like
SELECT c.Firstname, c.Lastname, l.productID, l.productname FROM Customers as
c
INNER JOIN Orders AS o ON c.CustomerID = o.CustomerID
INNER JOIN Orderlines AS l ON o.OrderID = l.OrderID
WHERE c.CustomerID = 23 AND o.OrderID = 10
ORDER BY l.ProductID

The values 23 and 10 are just example.

Then you can build your code to display the resulting output.

Cheers

TB
<me***@edpnet.b e> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
Mybe it's a stupid question but :
I'm starting to learn VB.NET. I have some basic skills. I'm from
Mainframe world and I have same question to make my DATABASES (tables
and relation)
I would like to make ask my question by example. Let's say I'm a
sales company I'm selling products to customers. Okay?
I have these tables (databases) and fields and I have these questions.

I have created these tables in VB.NET Database Connections IDE
interface. These 3 files and fields are visually created and I have
also entered some test data.
This is the structure: 1 Customer can have Multiple order, 1
OrderHeader can have Multiple orderDetailline s.
So I only store in OrderHeader the Main things like customer, Order
remark. Everything which is related to product I store it in
OrderDetailTalb e like product, price etc.

MY Intention: I don't want to set my RELEATIONS on DATABASE level,
but in PROGRAM LEVEL, I mean I don't want to visualize to draw a line
from Customer table to Order Header and from Order Header to Order
Detail.........
In Mainframe world we don't put DATABASE relations in DATABASE level,
but in PROGRAM level. ......
My QUESTION: IS this allowed by VB.NET? Can I build an application
like this? Is this a correct way to do? Or do I need to make a Database
Relation DIAGRAM?

WHAT is your idea about it as Experienced VB.NET programmer?

1) CustomerTable
==============
- Customer ID
- Customer Name
- Customer Address
- Customer City
- Customer Country
- Customer Payment term

2) OrderHeaderTabl e
=============== ==
- Order Number
- Order Type
- Order line
- Customer ID
- OrderRemark
-

3) OrderDetailTabl e
===============
- Order Number
- Order Type
- Order line
- Customer ID
- Product
- Sales price
- Extented price
Thanks
Mesut

Mar 16 '06 #2
Just to make sure, the "diagram" establish behind the scene the referential
integrity (using FOREIGN KEY constraints). You can do it in script if you
prefer.

My personal preference would be to always have referential integrity defined
in the DB. It will prevent an inconsistent database if your program by
mistake doesn't enforce this correctly plus it will prevent to introduce
inconsistencies from whatever else could access the database or when it
evolves etc...

That said if you have the same compelling reason than on mainframes for not
doing so, you are anyway never forced to define this in your DB...

--
Patrice

<me***@edpnet.b e> a écrit dans le message de news:
11************* *********@z34g2 00...legr oups.com...
Mybe it's a stupid question but :
I'm starting to learn VB.NET. I have some basic skills. I'm from
Mainframe world and I have same question to make my DATABASES (tables
and relation)
I would like to make ask my question by example. Let's say I'm a
sales company I'm selling products to customers. Okay?
I have these tables (databases) and fields and I have these questions.

I have created these tables in VB.NET Database Connections IDE
interface. These 3 files and fields are visually created and I have
also entered some test data.
This is the structure: 1 Customer can have Multiple order, 1
OrderHeader can have Multiple orderDetailline s.
So I only store in OrderHeader the Main things like customer, Order
remark. Everything which is related to product I store it in
OrderDetailTalb e like product, price etc.

MY Intention: I don't want to set my RELEATIONS on DATABASE level,
but in PROGRAM LEVEL, I mean I don't want to visualize to draw a line
from Customer table to Order Header and from Order Header to Order
Detail.........
In Mainframe world we don't put DATABASE relations in DATABASE level,
but in PROGRAM level. ......
My QUESTION: IS this allowed by VB.NET? Can I build an application
like this? Is this a correct way to do? Or do I need to make a Database
Relation DIAGRAM?

WHAT is your idea about it as Experienced VB.NET programmer?

1) CustomerTable
==============
- Customer ID
- Customer Name
- Customer Address
- Customer City
- Customer Country
- Customer Payment term

2) OrderHeaderTabl e
=============== ==
- Order Number
- Order Type
- Order line
- Customer ID
- OrderRemark
-

3) OrderDetailTabl e
===============
- Order Number
- Order Type
- Order line
- Customer ID
- Product
- Sales price
- Extented price
Thanks
Mesut

Mar 16 '06 #3
>>... Or do I need to make a Database Relation DIAGRAM?<<

If you create your tables properly using FOREIGN KEY constraints the
software (e.g., visio, enterprise manager, ERwin, Mgmt Studio) will be
able to automatically create a diagram that shows table relations.

This is an abreviated example of the proper way to create the tables
in SQL Server 2005.

-- Code
CREATE TABLE Customers
(
CU_ID int PRIMARY KEY,
CU_Name varchar(30) NOT NULL,
CU_Address varchar(50) NOT NULL,
CU_City varchar(30) NOT NULL,
CU_Country varchar(30) NOT NULL,
CU_PaymenTerm varchar(30) NOT NULL
);

CREATE TABLE Products
(
PR_ID int PRIMARY KEY,
PR_Description varchar(100) NOT NULL,
PR_Price smallmoney NOT NULL,
PR_Qty smallint NOT NULL
);

CREATE TABLE Orders
(
OR_ID int PRIMARY KEY,
CU_ID int FOREIGN KEY REFERENCES Customers(CU_ID ),
OR_Type varchar(30) NOT NULL,
OR_Description varchar(1000) NULL
);

CREATE TABLE OrderDetails
(
OD_ID tinyint PRIMARY KEY,
OR_ID int FOREIGN KEY REFERENCES Orders(OR_ID),
PR_ID int FOREIGN KEY REFERENCES Products(PR_ID) ,
PR_Price smallmoney NOT NULL,
OD_Qty smallint NOT NULL
);
-- End of Code

IMO, it is much better to use SQL instead of the GUI to create
your tables. The main benefit, at least for me, is it forces me to
think through the design. Plus, I can recreate the entire database
easily when a design change is made.
Garth
www.SQLBook.com
Mar 16 '06 #4
Thank you all, all information was really useful

If I correct understand I can better use constrains (database
relations) but it's not obligated by the system (Visual
Studio.Net)...

TB : Thank you for the SQL sample, that was also the my idea to use
it.

Patrice: I think you've got the right words... I don't want to
define Foreign Key Constrains. In Mainframe we just read the
OrderHeader and then we read OrderDetail in the program. But there is
no constrains (links with tables). But I agree then you can have
OrderDetail Record information without OrderHeader Record, but this is
not my issue for the moment...

Garth: That sample is also very good. I'm using Visual Studio.NET
Express Edtion + SQL 2005 Express... Where do you type your code to
create these tables?

sorry guys here is my last queston:
- When a Field e.g. Payment term is NOT NULL means : when the primary
field is filled in (record created) the NOT NULL fields are obligated
to fill in. You should have filled in a value CORRECT?

regards,

Mesut

Mar 16 '06 #5
TB
That´s right.

Whenever a new row is added, something has to be put into a Not Null column,
for example a 0 for a numeric column or an empty space for a varchar column.

TB

<me***@edpnet.b e> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Thank you all, all information was really useful

If I correct understand I can better use constrains (database
relations) but it's not obligated by the system (Visual
Studio.Net)...

TB : Thank you for the SQL sample, that was also the my idea to use
it.

Patrice: I think you've got the right words... I don't want to
define Foreign Key Constrains. In Mainframe we just read the
OrderHeader and then we read OrderDetail in the program. But there is
no constrains (links with tables). But I agree then you can have
OrderDetail Record information without OrderHeader Record, but this is
not my issue for the moment...

Garth: That sample is also very good. I'm using Visual Studio.NET
Express Edtion + SQL 2005 Express... Where do you type your code to
create these tables?

sorry guys here is my last queston:
- When a Field e.g. Payment term is NOT NULL means : when the primary
field is filled in (record created) the NOT NULL fields are obligated
to fill in. You should have filled in a value CORRECT?

regards,

Mesut

Mar 16 '06 #6
> Garth: That sample is also very good. I'm using Visual Studio.NET
Express Edtion + SQL 2005 Express... Where do you type your code to
create these tables?


Go to Microsoft's website and look for: Microsoft SQL Server
Management Studio Express. I believe there are other free tools
available, but cannot recommend any because I haven't used them.

One more thing...you were asking about NOT NULL...If possible,
I like to define the domain of a column via a CHECK constraint when
creating a table. This accomplishes two goals:

1. It prohibits invalid data from being inserted into the column, and
2. It allows other developers to know more about the data more
quickly.

It's one thing to know a column can accept up to thirty characters
(e.g., varchar(30)), but it really helps to know that the only valid entries
are x, y and z. And, of course, it is also helpful to define DEFAULT
constraints as well.

The following table definition is from my current project...it contains
examples of these types of constraints.
CREATE TABLE WorkItems
(
WI_ID int PRIMARY KEY,
WI_Type varchar(8) NOT NULL CHECK (WI_Type IN ('Issue','Proje ct','Task')),
WI_Title varchar(100) NULL,
WI_Priority varchar(10) NULL CHECK (WI_Priority IN ('(1) High','(2)
Normal','(3) Low')),
WS_ID tinyint FOREIGN KEY REFERENCES WorkItemStatuse s(WS_ID),
WI_PercentCompl ete varchar(3) NULL,
WI_AssignedTo int NULL REFERENCES Employees(EM_ID ),-- Holds ProjectLeader for
Projects
WI_Description varchar(1000) NULL, -- Holds Comment for Issues
WI_StartDate datetime NULL,
WI_DueDate datetime NULL,
WI_CreatedDate datetime NOT NULL DEFAULT GETDATE(),
WI_CreatedBy int NOT NULL REFERENCES Employees(EM_ID ),
WI_LastModified Date datetime NULL,
WI_LastModified By int NULL REFERENCES Employees(EM_ID ),
WI_Caller int NULL REFERENCES Employees(EM_ID ),
BR_ID varchar(15) NULL REFERENCES Branches(BR_ID) ,
WC_ID tinyint NULL FOREIGN KEY REFERENCES WorkItemCategor ies(WC_ID),
WI_EmployeeWith IssuePhoneNumbe r varchar(15) NULL,
);

Garth
www.sqlbook.com
Mar 16 '06 #7
One last thing...you should post your database design/programming
related questions in microsoft.publi c.sqlserver.pro gramming. There
are a lot of very smart, helpful people that monitor that newsgroup
and you will get excellent answers and tips. At least that's always
been my experience.
Mar 16 '06 #8
Thanks guys. I have learned more today. I will follow your advices.

regards,

Mesut

Mar 17 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2992
by: Bose | last post by:
Hi I have to make export of SQL Server Database to MS Access and I have done it with the tables but now I need to transfer(export) the relations, keys and indexes. Can any1 tell me how to read relations,keys and indexes from SQL Server and convert them to MS Access.(it seams that for creation of indexes in MS Access ADOX is the only way but ADOX cannot read all information about keys,indexes from SQL Server.) All I can see is that I have...
2
7817
by: DMAC | last post by:
The following failed in EM (or whatever it is called now management studio I think) and I scripted it out and ran it in a query window to get more info. This works fine in SQL 2000 but not in 2005. I also tried to 'create' the database first then ran this command below but with the 'force restore over existing database' checked on but this failed also which is odd as well. Any ideas. This is my very first play with 2005 so it is not off to...
2
3311
by: tekanet | last post by:
Hello folks, I'm developing a program that reads an access MDB file and produce some scripts to rebuild the same structure against other databases (MSSQL, MySQL and so on). Reading structure of tables and fields was quite simple. Now I'm stuck because I can't find where to read to access infos about indexes and relationships. Probably for relationships I've to read the hidden table MSysRelationships (I didn't do that 'till now), but I...
5
3905
by: Bob Alston | last post by:
I have a where used utility that shows where any table or query is used - in a query, form or table. I would like some kind of diagram that shows these relations. I have some reports that require a lot of queries with query_totals and union queries to produce current day, current week, current month, current year to date and prior day, week month and year data.. these are Unioned together with appropriate keys to serve as input to a...
6
1776
by: Frank Rizzo | last post by:
Hello, I am writing a server that will be inserting/reading/updating the database on multiple threads. I understand that you can't have more than 1 reader open on a database connection. Are there any other limitations? Like can I have more than one command object inserting on the same connection? Any other pitfalls, I should look out for? Thanks.
4
1658
by: Chris | last post by:
Hi, I am wondering where in my ASP.NET application to load a dropdown list box that basically only changes once a year. I load a drop down list box with about 40 locations. If it never changes should I put it in the page load event of the page? Could I not put the loading of the dataset into the applicaton start event? or
2
2871
by: Joe | last post by:
Hi I have a dataset with 3 tables and 2 relations Is there a way to when I am at 1 row to tell if there is a relation on that row ??? I have the code hardcoded but try to make it work if the # of tables and #relations increase or decrease So I can just pass any dataset and walk thru the rows?? Thanks
12
7017
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a foreign Key relationship or does this always indicate some sort of underlying design flaw. Something that requires a re evaluation of the problem domain? The reason I ask is because in our application, the user can perform x
41
18216
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
10076
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9740
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8744
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7287
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3832
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2702
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.