|
Hi there,
I have a generic class called Product that has general properties that each product will have. Then I have a class called Book, and Computer. This was easy to do in C# code, but now I have to create the table structures. I'm not sure what is the best way to do it? I was thinking of creating a table called Product, and a table called Book. And then have a product identifier in the Book table to reference the Product table? What will the relation be between these 2 tables? 1:1? Can someone please give me some direction as to what to do and what is the best way of doing it?
Regards
Brendan
|
|
|
|
|
Book should not be a table, it is a TYPE of product (as is Computer). If you go down the path of having a table for each product type (because each product type has different attributes after all) then you will get your self into a maintenance (and data) nightmare.
Have a product table with all the general attributes as you have done, add a large description field and see if that will meet your needs.
IF you absolutely MUST have additional attributes you might consider an attribute type and attribute table but this is going to add a level of complexity that will make support difficult.
There are entire books written and consultants make fortunes writing product structures so don't be scared to experiment.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for the reply. Book was just an example. There will be other product types as well. Like computers, clothes, etc etc. So I think it is a little impractical to have all the attributes in one table. Or what do you think?
What product structures are you talking of? Give some examples?
|
|
|
|
|
The structure should be something like this (as Mycroft suggested):
ProductType ' (Book, Manchester, Cookware, ...)
ID INT IDENTITY(1,1) PRIMARY KEY,
Name VarChar(50) UNIQUE NOT NULL
ProductCategory ' (Fiction, NonFiction, Sheets, Pillow Cases, Pots, Pans,...)
ID INT IDENTITY(1,1) PRIMARY KEY,
ProductType_ID INT NOT NULL FOREIGN KEY REFERENCES ProductType(ID),
Name VarChar(50)
Product
ID INT IDENTITY(1,1) PRIMARY KEY,
ProductCategory_ID INT NOT NULL FOREIGN KEY REFERENCES ProductCategory(ID),
Name VarChar(50) NOT NULL
...
...
To add additional attributes, extend this to Properties...
ProductProperty ' (Price, Dimension, Volume, ...)
ID INT IDENTITY(1,) PRIMARY KEY
ProductType_ID INT NOT NULL FOREIGN KEY REFERENCES ProductType(ID),
Name VarChar(50) NOT NULL,
UOM VarChar(20) NOT NULL,
Description VarChar(50)
ProductPropertyValue
ID INT IDENTITY(1,1) PRIMARY KEY,
ProductProperty_ID INT NOT NULL FOREIGN KEY REFERENCES ProductProperty(ID),
Product_ID INT NOT NULL FOREIGN KEY REFERENCES Product(ID)
Value VarChar(MAX)
Wire these together with Foreign Keys and you are away - As Mycroft said, this adds aonother layer of complexity.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
modified on Thursday, October 1, 2009 6:28 AM
|
|
|
|
|
Thanks, it makes a lot more sense now. I'm just confused to your product category and your product type. Could you explain a little more please?
Lets say I have a book product. Product category would be like religion and auto biographies, and product type would be book?
Why do you have the following ProductType ' (Price, Dimension, Volume,...) Shouldn't price be generalised into the product table?
|
|
|
|
|
OK,
ProductType would be Book,
ProductCategory would be NonFiction
Product: ProductCategory would be NonFiction
Name would be Book Title
You could then select from your tables as so:
SELECT * FROM Product p
JOIN ProductCategory pc
ON p.ProductCategory_ID = pc.ID
JOIN ProductType pt
ON pc.ProductType_ID = pt.ID
WHERE pt.Name = 'Book'
this gives you much flexibility selecting by Type, Category and Name
etc...
Hope this makes things clearer. Create a dummy DB in SSMS and generate a Database diagram - the structure will become clearer.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
modified on Thursday, October 1, 2009 6:27 AM
|
|
|
|
|
hi everybody .
i am trying to use pivot
i use northwind data base
i try to execute the following sql statement in my sql server management studio
SELECT * FROM Orders
PIVOT (COUNT(employeeID) FOR employeeID IN ([1],[2],[3],[4],[5],[6],[7],[8],[9])) p
but it gives me that error , i don't know what is wrong with the above statement , actually i didn't change the query from the article that i learn from , i copied and pasted it inside the sql management studio
i got that error
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
Human knowledge belongs to the world.
|
|
|
|
|
I used this on AdventureWorks (I done't have northwind) and it worked fine. I got the IDs with a select distinct. Dammed if I can see a difference.
SELECT * FROM Sales.SalesOrderHeader
PIVOT (COUNT(SalesPersonID) FOR SalesPersonID IN ([274],[275],[276],[277])) p
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
Your Northwind db may not have compatibility level of 90 which is a requirement for the Pivot clause. Try this:
ALTER DATABASE [NorthWind] SET COMPATIBILITY_LEVEL = 90
Hope that helps.
Regards,
Syed Mehroz Alam
My Blog | My Articles
Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
|
|
|
|
|
|
hi
how i can backup oracle 10g like backup and restore in sql server ?
i want to backup tables and data
thank's in advance
|
|
|
|
|
I thought the title was dumb - and even had this ready for you backup[^] but then I read the content.
Correct me if I'm wrong but you seem to be asking if you can back up an Oracle database and restore it into SQL Server, assuming I have not completely misinterpreted you question.
You CANNOT do that. There may be tools around that will allow you to generate a script from Oracle to create the equivalent database in SQL Server and then query the data across but backup is not going to work.
|
|
|
|
|
Hi all,
I would like to get your help and guidance in implementing the following requirements.
please consider the following situation.
We have an address book application. The app will have fields like name/age/Sex by default. I want to give the user the freedom to add his own fields to the application. Like website address/email etc. This wil be decided by the user while the sets up the application for the first time. I have a clear understanding of doing this at the UI level(using dynamic controls to hold the value) how can the same be handled at the database level? Like how should the table be designed to accomodate this dynamic column creation.
my second requirement is
While we search our inbox in GMAIL using the default search box(not the advanced options) we key in the keyword. And gmail returns the results irrespective of where the search keyword appears( it may be in the subject line/ message body/from email address etc.)
I want the same feature be implemented in a windows application( I want the search to be done against all the columns in a given table or given set of tables).
www.BeginWithDisbelief.com
hi hi hi hi
|
|
|
|
|
Some ideas
1
Traditional solution is to have a number of user defined blank columns on a table and allow the user to name and use them. This limits the number of additional fields to the user defined columns you create. It does make query easier.
Another way is to have an attribute type and attribute table where the user can create a type (web address) and create an attribute record for an address where required. This allows unlimited attributes to be created but makes supporting queries more difficult.
2
You are asking for 2 very different things, GMail queries 2 or 3 fields, subject and body, you want to query any field in any table. A simple compound where clause using OR will do that.
Select *
From EmailTable
Where Address like '%searchstring%' or Subject like '%searchstring%' or Body like '%searchstring%'
|
|
|
|
|
|
I have installed visual studio 2008. Then I installed sqlserver management studio. I connect using windows authentication. But there is another option to connect using sqlserver authentication. Where will I get the login name and password to connect using sqlserver authentication.
For test purpose I have connected using windowsauthentication and then created a login by right clicking the security folder and I have chosen sqlserver authentication and provided necessary information and clicked ok.
But when I tried to login by this new login name using sqlserver authentication It shows the following error:
"A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233)"
Am I in the right way to login using sqlserver authentication? If I am in right way why I am getting the error?? Please help to solve the problem. I really need to test the option: sqlserver authentication
|
|
|
|
|
1. Check that mixed mode authentication is enabled.
2. Check that the "sa" login is enabled; I think it's disabled by default.
|
|
|
|
|
I have enabled the sa login. But how can I enable mixed mode?
|
|
|
|
|
You can enable mix mode Authentication via connecting to SQL Server in Mamagement Studio via Windows Authentication then Open the Properties of the Server. Select Security Page listed in left panel.
At this page, there is Server Authentication Block, Choose SQL Server & Window Authentication Mode.
I hope it gonna help u.
|
|
|
|
|
Thanks a lotzz!!! It's really great. It is working....
|
|
|
|
|
|
Unfortunately the server doesn't allow ftp for security so I can't backup the database and then send it through ftp to the other server.
So is there anyway I can do this from sql server 2008?
Is there a way to write the url or path of the remote server in order to save the backup file?
example: \\1.2.3.4\.... something like that?
|
|
|
|
|
Backups are done Locally. That is why when you try to make a Backup, it only gives you a Local Filesystem option. So what you can do is that back them localy and move them Programatially.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Thanks for the reply.
Do you mean create something like a windows service to move the backuup file to another server? How can I do that if ftp is disabled on the server?
|
|
|
|
|
If you cant have Access to the FTP , you can share the Folder in the Destination Folder and Map it in the Machine that does the Backups. and move the backups Between these Folder. You can Add this as a Batch File and that Batch File gets Executed as a Job in SQL After the Backups are done.
Hope this Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|