DB Design :: Restructuring Tables For Fast Data Retrieval?

May 28, 2015

I have below DB structure in MSSQL for a small application which follow relational approach. Data retrieval (for Hostels) will need several Join, may be Key-Value approach where data retrieval will be fast.

Hostels
------------
HostelId,
Name,
Address,
CategotyId,
SubCategoryId,
FoodCategoryId,
LandLordId

Data:

1 H1 Address1 1 1 2 20
2 H2 Address2 1 2 2 21
3 H3 Address3 2 2 1 17

Category
----------
CategoryId,
CategoryName

[code]...

View 10 Replies


ADVERTISEMENT

T-SQL (SS2K8) :: Possible Pivot / CTE Recursion Restructuring Of Data

Sep 7, 2015

I have a table (folderstructure) with the following columns:

pcmid, cmid, foldername
pcmid is the parent directory
cmid is the directory
foldername is the name of the directory

e.g. note, number of levels are unknown

cmid pcmid name
1 NULL c:
101 1 level1
201 101 level2
45 101 level2a
56 201 level3
57 201 level3a

I'm looking to create a table that has cmid followed by the full directory path

So either (using above):

cmid path
1 c:
101 c:level1
201 c:level1level2
45 c:level1level2a
56 c:level1level2level3
57 c:level1level2level3a

etc.

OR

cmid 1 2 3 4
1 c:
101 c: level1
201 c: level1 level2
45 c: level1 level2a
56 c: level1 level2 level3
57 c: level1 level2 level3a

etc.

I've can use recursion to allocate a level to each name /cmid/pcmid combination

I could use multiple self joins

Is there a way this can be achieved using pivots or CTE recursion or something else...

View 2 Replies View Related

Database Design For Fast Client Updates

Mar 29, 2006

I'm trying to work out a database design to make it quicker for my clientprogram to read and display updates to the data set. Currently it reads inthe entire data set again after each change, which was acceptable when thedata set was small but now it's large enough to start causing noticabledelays. I've come up with a possible solution but am looking for others'input on its suitability to the problem.Here is the DDL for one of the tables:create table epl_packages(customer varchar(8) not null, -- package_type char not null, -- primary keypackage_no int not null, -- /dimensions varchar(50) not null default(0),weight_kg int not null,despatch_id int, -- filled in on despatchloaded bit not null default(0),item_count int not null default(0))alter table epl_packagesadd constraint pk_epl_packagesprimary key (customer, package_type, package_no)My first thought was to add a datetime column to each table to record thetime of the last change, but that would only work for inserts and updates.So I figured that a separate table for deletions would make this complete.DDL would be something like:create table epl_packages(customer varchar(8) not null,package_type char not null,package_no int not null,dimensions varchar(50) not null default(0),weight_kg int not null,despatch_id int,loaded bit not null default(0),item_count int not null default(0),last_update_time datetime default(getdate()) -- new column)alter table epl_packagesadd constraint pk_epl_packagesprimary key (customer, package_type, package_no)create table epl_packages_deletions(delete_time datetime,customer varchar(8) not null,package_type char not null,package_no int not null)And then these triggers on update and delete (insert is handled automaticallyby the default constraint on last_update_time):create trigger tr_upd_epl_packageson epl_packagesfor updateas-- check for primary key changeif (columns_updated() & 1792) > 0 -- first three columns: 256+512+1024insert epl_packages_deletionsselectgetdate(),customer,package_type,package_nofrom deletedupdate Aset last_update_time = getdate()from epl_packages Ajoin inserted Bon A.customer = B.customer andA.package_type = B.package_type andA.package_no = B.package_nogocreate trigger tr_del_epl_packageson epl_packagesfor deleteasinsert epl_packages_deletionsselectgetdate(),customer,package_type,package_nofrom deletedgoThe client program would then do the initial read as follows:select getdate()selectcustomer,package_type,package_no,dimensions,weight_kg,despatch_id,loaded,item_countfrom epl_packageswherecustomer = {current customer}order bycustomer,package_type,package_noIt would store the output of getdate() to be used in subsequent updates,which would be read from the server as follows:select getdate()selectcustomer,package_type,package_no,dimensions,weight_kg,despatch_id,loaded,item_countfrom epl_packageswherecustomer = {current customer} andlast_update_time > {output of getdate() from previous read}order bycustomer,package_type,package_noselectcustomer,package_type,package_nofrom epl_packages_deletionswherecustomer = {current customer} anddelete_time > {output of getdate() from previous read}The client program will then apply the deletions and the updated/insertedrows, in that order. This would be done for each table displayed in theclient.Any critical comments on this approach and any improvements that couldbe made would be much appreciated!

View 4 Replies View Related

DB Design :: Inserting Data From 3 Tables Into 1 Table

Jun 10, 2015

I have 3 tables (accnt, jobcost, and servic15). all with the same fields (code, jno, ven, date). I need to insert the data from these tables into another table called dummy with the same fields, in one statement or query.

View 3 Replies View Related

Data Retrieval

Jan 7, 2008

i m having a huge problem! how to retrieve data from notepad files using asp.net and store the info in fields in MS-Access/Sql db? Plz help !!

View 1 Replies View Related

DB Design :: How To Copy Data From Existing Table To Normalized Tables

May 20, 2015

I normalized the below tables but I am finding it difficult to copy data to the new tables.  How do I copy data from existing table to the normalized tables? see the table structure below and other supporting information:

SKU_DATA(SKU,SKU_Description,Department,Buyer) Note: this table already has data in it.
CREATE TABLE SKU_DATA (
SKU   
   Integer NOT
NULL,

[code].....

The table structure above have two three determinants( SKU,SKU_Description and Buyer).  SKU and SKU_Description are candidate keys. Primary key is SKU.

Normalization : SKU_DATA(SKU,SKU_Description, Buyer)
 BUYER(Buyer,Department)

View 2 Replies View Related

SQL Server Data Retrieval

Jul 12, 2004

Hi,



I wanted to retrieve all the databases present in an SQL Server and put them in an Dropdown list.

Then retrieve all tables of the selected database

and finally retrieve all data from the selected table (This i know)

How do i accomplish the above two.


Regards
Vijay R

View 3 Replies View Related

Data Retrieval Using IDataReader

Nov 16, 2007

Code Block

string commandString = "SELECT Id,Name FROM [DatabaseTable];";
using (SqlConnection conn = new SqlConnection(connectionString))
{

SqlCommand cmd = new SqlCommand(commandString, conn);
conn.Open();
IDataReader rdr = cmd.ExecuteReader();


IList ids = new List();
IList names = new List();
while (rdr.Read())
{

ids.Add((int)rdr[0]);
names.Add((String)rdr[1]);
}
rdr.Close()
}




What i want to know is if there is any better way of obtaining the 'id' and 'name' data
values then just assuming that id is the first returned object and name is the second returned object in each reader record.

ie. Is there any way to retrieve a specific field from the reader in a Dictionary-type manner...?





Code Block

while(rdr.Read())
{

ids.Add( (int)rdr["Id"] );
names.Add( (String)rdr["Name"] );
}




View 6 Replies View Related

Data Retrieval Terribly Slow

Jul 27, 2006

Hi,
I'm using ASP.NET 1.1, SQL Server 2000 Server:
I  followed the ASP.NET 1.1 Starter Kit's Commerce application and applied the same principles it had written the code to retrieve data to my web application I created.  For example I've written this Function in a class to return a sqldatareader:
Public Function GetAdvanceSearch(ByVal s As String, ByVal Ext As Integer, ByVal fdate As DateTime, ByVal tdate As DateTime) As SqlDataReader
Dim oDrAdSearch As SqlDataReaderDim oCmdGetSearch As New SqlCommand("spAdvanceSearch", oComConn)
With oCmdGetSearch   .CommandType = CommandType.StoredProcedure   .Parameters.Add(New SqlParameter("@DialNo", SqlDbType.VarChar)).Value = s   .Parameters.Add(New SqlParameter("@FDate", SqlDbType.DateTime)).Value = fdate   .Parameters.Add(New SqlParameter("@TDate", SqlDbType.DateTime)).Value = tdate   .Parameters.Add(New SqlParameter("@Ext", SqlDbType.Int)).Value = ExtEnd With
oComConn.Open()oDrAdSearch = oCmdGetSearch.ExecuteReader(CommandBehavior.CloseConnection)
If oDrAdSearch.HasRows Then   Return oDrAdSearchElse   Return NothingEnd If
End Function
And When I'm calling this function I do write in this way (assuming that this function is in a class called "Calls"):
Dim objCalls as New Calls
DataGrid1.DataSource = objCalls.GetAdvanceSearch(<PARAMS.......>)DataGrid1.Databind
My application is a Telephone Call Recording System and could expect vast amount of data. Averagely, a month may produce approximately 50,000 records or more. So while querying through my web application for a month, the application itself either gets stuck or the retrieval speed gets drastically slow. However I'm using Datareaders for every querying scenario. My Web application is hosted in a Windows 2000 Server and accessed via Local Network or IntraNet.
What are the ways I could make this retrieval more speedier and efficient? I would like to hear from anyone who have come across this problem and anyone who could help me on this.
Thanks in Advance. Looking forward for a reply from some one.
 

View 3 Replies View Related

DATA Retrieval Stored Procedure

Mar 29, 2001

Is there a stored proceduire that grabs all the data from a specified table and places it in a file.

View 1 Replies View Related

Complicated Data Retrieval Routine

May 4, 2006

Hello all,

I'm stumped on how to solve this question so I figured i'd ask the community. As a warning i'm not sure best how to describe my situation so i'll try and give as much detail as I can.

First in table A, I have two columns that already have data in them that are numeric (Col1, Col2). Also, in table A I have two more columns that are going to derive their data based of a complicated data retrieveal routine (Col3, Col4). So my table structure looks something like this:


Code:

Table A
Col1 Col2 Col3 Col4
20 20 NULL NULL

(Where Col3, and Col4 are going to be populated based off the routine)



The Data for Col3 and Col4 is in an excel spreadsheet that i'd like to convert into a table for MSSQL. However i'm not sure how to do this because in the spreadsheet there is a lookup routine (that i'm trying to copy to MSSQL code, i'll show that in a minute) that generates its values based off data in the X / Y columns, so something like this:


Code:

_|1__|2___|3__
0|0 |0 |0
1|1 |15 |25



So when 2 is met, and 1 is met, they would equal '15'. No arithmetic involved, just simply matching up the X / Y and pulling the data.

My question is, how do I create tables out of this, so my lookup routines can get the values as a result of matching X / Y? (2, 1 = 15)???

The excel routine is this:

=IF(VLOOKUP(F66,'Appendix A'!A5:K56,MATCH(F68,'Appendix A'!A4:K4,1),TRUE)>F46/12*0.125,F46/12*0.125,(VLOOKUP(F66,'Appendix A'!A5:K56,MATCH(F68,'Appendix A'!A4:K4,1),TRUE)))

Thanks!

View 3 Replies View Related

SQL Server Data Retrieval Problem

Apr 11, 2007

Hello,

i am getting a hard time in minimizing time for data retrieval, over SQL Server DataBase. My DataBase consist of 2 tables. One of the table has more than 10000 entries and other table with more than 10 million entries. I have used SQLNative Client for connecting to data base and my goal was to find a value from the 1st table and search it out in 2nd table. The result is more than hundered thousand rows. Now the problem is: the time it took for retrieving those rows is much slower approx. 12 minutes. Can this time be cut down. I have used SQLClient connection to make sure it is accessing SQL server on a direct access base.



Also, i am using

SqlClient::SqlDataReader

for reading, getting rows returned by the my query.



Please help me out.

Thanx.



R. T.

View 4 Replies View Related

Question On Data Retrieval Using RDA Pull

Jun 3, 2008

Hi All,


I am working on an application to retrieve data to the windows ce 3.0 handheld from the Sql server database. I am able to retrieve the data from the server using RDA pull method and able to see the data on the local handheld database. To display the retrieved data in the dialog to the user, it requires to query the local databse and get the information and then display the information, which is taking some time.

My question is, to reduce the time and improve the performance , instead of pulling the data to the local table, is there any way to pull the data and have it in memory and display the details to the user?

To develop the above application, I used some of the code to pull the data from the server from the sample application C:Program FilesMicrosoft SQL Server CE 2.0SampleseVCeVCReplRdaHPC. I am developing the application for windows ce 3.0 device using eVC 3.0

thanks
pyd.

View 4 Replies View Related

Data Retrieval For Reports From Summary Table.

Feb 22, 2007

Hi,
I have a summary table like this






 
Field1
Field2
Field3
Field4
Field5


AAA11
value1
value2
value3
value4
value5


AAB23
value6
value7
value8
value9
value10


BCD14
value11
value12
value13
value14
value15


GFD12
value16
value17
value18
value19
value20


SDL25
value21
value22
value23
value24
value25


AUD56
value26
value27
value28
value29
value30


BER11
value31
value32
value33
value34
value35









Columns are obviously fixed, but not rows.
I want to show this data using lables and SqlDataReader for report purpose like;
Label1.text=dr("value16").toString( )
Label2.text=dr("value28").toString( )
Label3.text=dr("value31").toString( )  etc
 
 Do you have any idea how i can do it or am I approaching it in the wrong way????
 
Thanks.
Michelle
 

View 1 Replies View Related

Data Retrieval Is Much Slower In RS Than In Management Studio

Feb 16, 2007

A call to a stored procedure completes in 13 seconds when ran from within SQL Server Management Studio. A report whose data source uses the same stored procedure can take as long as 10 minutes to run. The same parameter values are used in both the direct call and the report. The execution log says almost all of that time is spent on data retrieval. How could that be? What might be the cause?

View 14 Replies View Related

How To Add Explicit Null For Missing Data While Retrieval

Feb 27, 2008


Hi there,
I was wondering if someone could propose a solution for the following scenario:

TimeID column would have values from 1 to 6 and rows will be inserted only for those timeIDs where we have Data value as well. While retrieving data we would like to have all timeID range returned with explicitly specifying NULL for missing Data column. Please see below to better understand the situation.


create table test

(

TimeID INT,

Data INT

)


INSERT INTO test VALUES(1, 100)

INSERT INTO test VALUES(2, 180)

INSERT INTO test VALUES(4, 550)

INSERT INTO test VALUES(6, 120)


select * from test

1 100

2 180

4 550

6 120


Desired resultset

1 100

2 180

3 NULL

4 550

5 NULL

6 120

...

View 14 Replies View Related

Data Retrieval From Online Database - Paid Consultant Required

Jul 20, 2005

Hi,I wonder if anyone can help with the following on a fee paying basisfor the the design or development of some type of script or utility orpiece of code to do the following work.I wish to retrieve some data from an online database that is in thepublic domain. The online database has a search facility that matchesthe entry (name) in a search box then returns a screen stating that amatch has been found or not found.If a match is found there is a button to click that proceeds to thescreen containing the data which is simply two names. It is these twonames that I wish to retrieve and store them in something like a textfile where they are associated with the original entry (name) used inthe search box.I have a list of the entries for the search box that can be suppliedin sample format for testing as a columnar text file or commadelimited file or a spreadsheet.. I would need the procedure toprocess the list of search entries, retrieve the data then move on tothe next one in the list. Obviously, if a match was not found then theprocess would need to move on the the next entry in the list withperhaps a message saying "No Match" until the entire list wasprocessed.The PC I hope to run the process on is a Windows XP machine and if Ineed to purchase any particular software that is necessary for the jobthen I am quite willing to do so. Also, as I pointed out above I wouldpay for the work to be done.I hope that I have explained the above OK and that I have posted it tothe correct newsgroup(s). If it is not in the correct newsgroup Iwould be grateful if anyone could point me in the right direction.RegardsDave Gibson

View 1 Replies View Related

How To Extract Data From LDAP And Then Import It Into SQL Database (for Quicker Retrieval)

Apr 21, 2008



Hi Everyone,
Am a third year student doing work placement.
Could anyone please give me clues on how to go about extracting data from a LDAP and then into an SQL database?

1 A defined subset of data is to be extracted from GDS on a nightly basis,
2 Then imported into a SQL database for quick & easy retrieval.
3 A web interface is required to present data retrieved from the SQL database.

I will appreciate every assistance.

Regards
Lidiolo

View 6 Replies View Related

Problem With Database Filegroup Restructuring In SQL Server?

Mar 7, 2006

Hi,I have the following SQL procedure I am running to clean up a filegroupand move all data to a single .MDF file:use <db_name>print 'Move <db_name> db contents to MDF file'DBCC SHRINKFILE ('<db_name>_1_Data', EMPTYFILE)DBCC SHRINKFILE ('<db_name>_Log', EMPTYFILE)DBCC SHRINKFILE ('<db_name>_2_Data', EMPTYFILE)DBCC SHRINKFILE ('<db_name>_log2', EMPTYFILE)goTrouble is that I get the following error:Server: Msg 1105, Level 17, State 2, Line 3Could not allocate space for object '<company_name>. Inv. Line' indatabase '<db_name>' because the 'Data Filegroup 1' filegroup is full.There are five files:- a .MDF file (which is already set as the primary filegroup, 43MB insize);- <db_name>_1_data.ndf (this file is 11GB in size);- <db_name>_2_data.ndf (this file is 4GB in size, empty & cannot beshrunk);- 2 .LDF filesI have been able to remove the "<db_name>_2_data.ndf" filesuccessfully, but moving the objects from filegroup 1 to the primaryfilegroup has yielded the same error message every time. Any ideas onwhat I can do to resolve this?

View 1 Replies View Related

How To Move Data Fast

Jan 23, 2004

Hello everybody
We need to move table T1 from database A to T1 database B on same server

size of table T1 15 GB and 40000000 rows

database B just created and will act as warehouse

could it be done simply by
1.creating table T1 on db B and then
2.set db to simple recovery
3.
insert into B.dbo.T1
select * from A.dbo.T1
4. create all the indexes on table T1 in db B

free disk space is 35GB

Any idea how to optimze import
Thank you

View 5 Replies View Related

Data Access :: Why Bcp Out Is Fast

Jun 10, 2015

why bcp out (exporting data to a text file from a sql table using bcp utility ) is faster ?

View 6 Replies View Related

Fast Loading Relational Data

Apr 8, 2006

I am searching for a way to fast load relation data. I know how to load data fast but how can i store relation data fast.

For example :

Table1 ( tabel1Id int identity , name varchar(255) )

Table2 ( tabel2Id int identity , table2Id , name varchar(255))



When i insert 50 records into Table1 i can't get the 50 identity fields back, to insert the related data into Table2.



I think one of the solutions could be returning a selection of
Table1 joined with syslockinfo, but i have no idea how to do it.



Does anyone have an idea?

View 3 Replies View Related

Fast Loading Of Data To Table

Jul 10, 2007

Hi Every one,

How can I load or copy say millions of rows to a table in the database faster?

Thanks,
Mejo George

View 6 Replies View Related

Pull Data From Cache 5.0 To SQL 2000 (fast?)

Jul 20, 2005

I'm currently working with a 10 million plus row database with the dataresiding on a Unix box with Cache 5.0. The problems is that it can take fivedays to pull one table from Cache to SQL 2000 using the ODBC connectionprovided by Cache in a SQL 2000 DTS package. I think the real problem isconverting the data from the post relational format (Cache) to a relationalformat (SQL 2000)???Does anyone have any ideas / suggestions on how to speed this transfer ofdata? I'm very new to Cache and any help would be greatly appreciated.Thanks,-p

View 3 Replies View Related

Reliable, Fast Method Of Exporting Data To Sql

Jul 5, 2007

Hi,



For this scenario, what is the best method of exporting data to sql 2005.



I want to export data from desktop app across internet to sql which can do on a row by row basis, but this is very slow and if the connection goes down halfway then pretty much buggered.



What is the best, reliable and fastest way to copy data across internet (several thousand rows), I have read about Bulk Insert etc... but also how would get around an upload and crashes half way, is there a way of uploading and until the whole upload goes through then the data is inserted into the database.



Would appreciate any guidance.



Richard

View 3 Replies View Related

Fast Uploading Data From Client To SQL2000 Database

Mar 4, 2005

Does anyone know how to upload (bulk) data from a client (written in Excel VBA) to a remote SQL2000 database? Of coarse I tried "INSERT INTO" and rst.addnew but I noticed this is much, much slower as downloading from the same remote database.

Thanks.

View 3 Replies View Related

Reporting Services :: Report Builder V3 Subreport Data Retrieval Failed For Subreport

Nov 3, 2015

I am trying to create a report with a sub report in Sql Server 2012 using Report Builder Version 3.  I can run the subreport without any problems.  I read where using a shared connection can cause this error so both the main report and the subreport use a connection that is embedded in my report.  

For testing, I created the subreport without a parameter and added it to the main report.  When I ran it that way, the report worked and sub report displayed the data.  So I know it can read from the database.It seems to only give me this error when I am trying to tie the two reports together using a parameter.  

View 2 Replies View Related

Transact SQL :: Fast Data Loading With Partition Switching Strategy

Jul 28, 2015

I’m looking for clearity on partition switching. The idea is to use many BULK INSERT statements into table dbo.X_n in parallel and when BULK INSERT for table dbo.X_n is completed, switch dbo.X_n into dbo.bigdaddy. I think this is the fastest way to upload a couple hundred GB of data.

In learning about partition switching (in part) from The Data Loading Performance Guide under Partition SWITCH, I hear the instructions to say copy the main table exactly to become a target. But in that same step (#1), I read that we need to change the default file group of the target (dbo.X_n) from the default file group. Then it says I need to match indexes and lists the filegroup as something we need to match with the main table.

As an overview of the partition switching strategy, I think the whole point of BULK INSERT with partitioning is to have seperate files (in same group) to enable concurrent uploading where each table has its own file. Once the upload is completed to a table (dbo.X_n) then we do the partition switch into the main table (dbo.bigdaddy). The data we just uploaded doesn’t actually move, just the metadata for it.

When I read the instructions linked above, I hear “Don’t have the same filegroup on your target as the main table. You must have the same filegroup on your target as the main table.”

Where am I disconnected?

View 5 Replies View Related

SQL Server 2012 :: Fast Data Loading With Partition Switching Strategy

Jul 28, 2015

I’m looking for clearity on partition switching. The idea is to use many BULK INSERT statements into table dbo.X_n in parallel and when BULK INSERT for table dbo.X_n is completed, switch dbo.X_n into dbo.bigdaddy. I think this is the fastest way to upload a couple hundred GB of data.

In learning about partition switching (in part) from The Data Loading Performance Guide under Partition SWITCH, I hear the instructions to say copy the main table exactly to become a target. But in that same step (#1), I read that we need to change the default file group of the target (dbo.X_n) from the default file group. Then it says I need to match indexes and lists the filegroup as something we need to match with the main table.

As an overview of the partition switching strategy, I think the whole point of BULK INSERT with partitioning is to have seperate files (in same group) to enable concurrent uploading where each table has its own file. Once the upload is completed to a table (dbo.X_n) then we do the partition switch into the main table (dbo.bigdaddy). The data we just uploaded doesn’t actually move, just the metadata for it.

“Don’t have the same filegroup on your target as the main table. You must have the same filegroup on your target as the main table.”

View 1 Replies View Related

Table Data Retrieval And Optimization Optimization Help

Apr 10, 2008

Hello Everybody,

I have a small tricky problem here...need help of all you experts.

Let me explain in detail. I have three tables

1. Emp Table: Columns-> EMPID and DeptID
2. Dept Table: Columns-> DeptName and DeptID
3. Team table : Columns -> Date, EmpID1, EmpID2, DeptNo.

There is a stored procedure which runs every day, and for "EVERY" deptID that exists in the dept table, selects two employee from emp table and puts them in the team table. Now assuming that there are several thousands of departments in the dept table, the amount of data entered in Team table is tremendous every day.

If I continue to run the stored proc for 1 month, the team table will have lots of rows in it and I have to retain all the records.

The real problem is when I want to retrive data for a employee(empid1 or empid2) from Team table and view the related details like date, deptno and empid1 or empid2 from emp table.
HOw do we optimise the data retrieval and storage for the table Team. I cannot use partitions as I have SQL server 2005 standard edition.

Please help me to optimize the query and data retrieval time from Team table.


Thanks,
Ganesh

View 4 Replies View Related

Tables Design Help

May 13, 2007

I used to get flat files which i need to import into tables..
The flat files data which contains.....

How should i design the tables so that i can get the output in single row...

Table1ForRow1
--------------
col1,100
col2,1
col3,xx
col4,yy
col5,,,
col6,20030101

Table1ForRow2
-------------
col1,100
col2,2
col3,20030101

Table1ForRow3
------------
col1,100
col2,3
col3,01
col4,20030101

FlatFiledata:
------------
100,1,xx,yy,,20030101
100,2,20030101
100,3,01,20030101

I want the output:
100,1,xx,yy,20030101,2,3,01

View 1 Replies View Related

Design -- Should This Be Split Up Into A Few Tables?

Feb 5, 2005

I'm grappling with this design problem right now:

I have a table of users. Every user has an e-mail address and (hashed) password. Some of those users work for a company, and some of them do not. Of those who do not work for a company, some are salespeople who sell to one or more companies. Some users are simply administrators who don't work for a specific company. So here's what my users table looks like right now: "UserID, Email, Password, CompanyID (Nullable), IsAdmin"
And here's my companies table: "CompanyID, CompanyName, SalespersonID"

Of course, I could separate it out and make a Users table, an Employees table, and a Salespeople table. The way the relationship works out, though, I could use the same ID number for all three tables, and that indicates to me that perhaps they all belong in the same table. It seems silly, after all to have a Salespeople table whose only field is "UserID."

Two factors of the first design concern me: First is the fact that a salesperson could also have a company. I guess I could write a check constraint to prevent this, but doesn't having the companyID in the Users table violate a normalization rule? Maybe? The second is the fact that the Companies table relies upon Users, which in turn relies upon Companies. In OOP, this usually isn't a good thing, but I'm not sure whether it's cause for concern in a relational database.

Anyway, I really don't know what I should be doing with this design. Any suggestions?

Thanks in advance,
-Starwiz

View 1 Replies View Related

Need Some Help With Design Of Tables/views

Jul 23, 2005

I have an applicaton in which I collect data for different parametersfor a set of devices. The data are entered into a single table, eachset of name, value pairs time-stamped and associated with a device.The definition of the table is as follows:CREATE TABLE devicedata(device_idintNOT NULL REFERENCES devices(id),-- id in the devicetabledatetimedatetimePRIMARY KEY CLUSTERED,-- date creatednamenvarchar(256)NOT NULL,-- name of the attributevaluesql_variantNOT NULL-- value)For example, I have 3 devices, and each is monitored for two attributes-- temperature and pressure. Data for these are gathered at say every20 minute and every 15 minute intervals.The table is filled with records over a period of time, and I canperform a variety of SQL queries.I have another requirement which requires me to retrieve the *latest*values of temperature and pressure for each device.Ideally, I'd like to use the data I have collected to get thisinformation, and I suppose I can.What I need is the SELECT statement to do this.I'd appreciate it very much, if someone can help provide that.Conceivably, I could use a SQL server View for making this easier forsome of my users.One alternate technique I thought was to create another table which I*update* with the latest value, each time I *insert* into the abovetable. But it seems like a waste to do so, and introduces needlessreferential integrity issues (minor). Maybe for fast access, that isthe best thing to do.I have requirements to maintain this data for several months/year ortwo, so I am dealing with a large number of samples.Any help would be appreciated.(I apologize if this post appears twice)

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved