Valhalla Legends Archive

Programming => Web Development => Topic started by: Archangel on May 26, 2008, 10:14 PM

Title: SQL Databases
Post by: Archangel on May 26, 2008, 10:14 PM
I'm starting to learn how to use SQL databases and i was wondering if its ok to have 2 tables for the users infromation, for example:

Having table: USERS with the rows: USER_ID USERNAME PASSWORD
and then having: USERS_INFO with the rows: USERS_INFO_ID ADRESS PHONE

the idea is having 2 separate tables to manage the users information, is this a correct way of doing this?

If so, what command should i be using to request the user adress using the user_id?

Edit: im new to this theme, so dont go hard with me :).
Title: Re: SQL Databases
Post by: Barabajagal on May 27, 2008, 12:24 AM
One table, multiple fields.
Title: Re: SQL Databases
Post by: Archangel on May 27, 2008, 07:57 AM
Quote from: Andy on May 27, 2008, 12:24 AM
One table, multiple fields.

k, thanks :]. I will post if i got any more doubts.
Title: Re: SQL Databases
Post by: FrOzeN on May 27, 2008, 08:22 AM
It really depends on the data you'll be storing. You have to determine how flexible your database needs to be. If you just wanted to know the user's main address, then putting it all into one table would probably be sufficient. But say the information you were collecting required room to allow for client's that have two or more addresses. In that scenario you would create a second table which stored all the address' and referenced each address to a ClientID.
Title: Re: SQL Databases
Post by: MyndFyre on May 28, 2008, 12:31 AM
This is a process we call "normalizing a database (http://www.google.com/search?q=database+normalization&rls=com.microsoft:*&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1)."  There's a pretty great Wikipedia article (http://en.wikipedia.org/wiki/Database_normalization) about it and lots of Google pages.

Basically, you should take a look at the logical objects that you'll be storing; where there are relationships of 1:n or m:n, these are almost always prime candidates for normalization.

In your user table, for instance, consider that you might want to store a list of user's IM contact info.  So, consider that a user object might be represented:


class CUser
{
    public:
        const std::string& GetUserName() const;
        const std::string* GetProfileIMLinks() const;
        const int GetProfileIMLinkCount() const;
    private:
        // etc
}

This class represents a user that has multiple IM links in his profile.  Your software might define an IM link as a hypertext link that can include the user's name.  For instance, all AIM links might be "aim:goim?user=%%USERNAME%%

A database schema for this might looks something like this (this is T-SQL for MS-SQL products):

CREATE TABLE [Users]
{
    UserID int NOT NULL IDENTITY(1,1) PRIMARY KEY,
    UserName nvarchar(75) NOT NULL
}

CREATE TABLE [IMLinks]
{
    ProtocolID int NOT NULL IDENTITY(1,1) PRIMARY KEY,
    ProtocolName nvarchar(10) NOT NULL UNIQUE,
    ProtocolLinkFormat nvarchar(125) NOT NULL
}

CREATE TABLE [UserIMs]
{
    UserID int NOT NULL PRIMARY KEY REFERENCES [Users](UserID) ON DELETE CASCADE,
    ProtocolID int NOT NULL PRIMARY KEY REFERENCES [IMLinks](ProtocolID) ON DELETE CASCADE,
    UserName nvarchar(30) NOT NULL
}


With these three tables you have everything you need to have unlimited IM protocol fields and unlimited IM profiles per user.  Consider:
Users:
1  MyndFyre 
2  Archangel

IMLinks:
1  AIM  aim:goim?userid=%%USERNAME%%
2  MSN  http://members.msn.com/%%USERNAME%%
3  GTalk  googletalk:talk?userid=%%USERNAME%%   (Note: I have no idea if these work)

UserIMs:
1  1  MyndFyre
1  2  myndfyre@gmail.com
1  3  myndfyre@gmail.com
2  2  Danownage@gmail.com

Do you see how there are links by ID across the different tables?  These relational links allow us to make sure that our database integrity is good as well as avoid repeating information.  NOTE: Although UserIMs has "myndfyre@gmail.com" for both 1/2 and 1/3, realize that this information is actually separate.  They're separate addresses, one for MSN and one for Google Talk.
Title: Re: SQL Databases
Post by: Banana fanna fo fanna on June 01, 2008, 12:08 PM
i wouldn't use sql if i were you. the technology is outdated and is barely in use anymore. only a few vendors support the technology until its end of life later this year. no real company still uses a sql database these days. sql is slow, inflexible, and overall lacking in relevance to any career plans you may have.

instead, i would use ajax.
Title: Re: SQL Databases
Post by: iago on June 02, 2008, 11:32 AM
Quote from: Banana fanna fo fanna on June 01, 2008, 12:08 PM
i wouldn't use sql if i were you. the technology is outdated and is barely in use anymore. only a few vendors support the technology until its end of life later this year. no real company still uses a sql database these days. sql is slow, inflexible, and overall lacking in relevance to any career plans you may have.

instead, i would use ajax.
Just to be clear (for newbies), that post didn't make sense. :)
Title: Re: SQL Databases
Post by: Invert on June 07, 2008, 04:21 PM
Quote from: Banana fanna fo fanna on June 01, 2008, 12:08 PM
i wouldn't use sql if i were you. the technology is outdated and is barely in use anymore. only a few vendors support the technology until its end of life later this year. no real company still uses a sql database these days. sql is slow, inflexible, and overall lacking in relevance to any career plans you may have.

instead, i would use ajax.

^
|
This is the dumbest thing I have ever read on the Web Development forums.
Title: Re: SQL Databases
Post by: Banana fanna fo fanna on June 07, 2008, 11:30 PM
im super serial guys.
Title: Re: SQL Databases
Post by: Don Cullen on October 30, 2008, 02:01 PM
Quote from: Invert on June 07, 2008, 04:21 PM
Quote from: Banana fanna fo fanna on June 01, 2008, 12:08 PM
i wouldn't use sql if i were you. the technology is outdated and is barely in use anymore. only a few vendors support the technology until its end of life later this year. no real company still uses a sql database these days. sql is slow, inflexible, and overall lacking in relevance to any career plans you may have.

instead, i would use ajax.

^
|
This is the dumbest thing I have ever read on the Web Development forums.

Seconded.
Title: Re: SQL Databases
Post by: Grok on November 09, 2008, 12:38 PM
Quote from: Banana fanna fo fanna on June 01, 2008, 12:08 PM
i wouldn't use sql if i were you. the technology is outdated and is barely in use anymore. only a few vendors support the technology until its end of life later this year. no real company still uses a sql database these days. sql is slow, inflexible, and overall lacking in relevance to any career plans you may have.

instead, i would use ajax.

???   :o

Nonsense.
Title: Re: SQL Databases
Post by: bulletproof tiger on November 11, 2008, 09:54 PM
What does that even mean...
Title: Re: SQL Databases
Post by: macyui on January 05, 2010, 04:12 AM
Quote from: Grok on November 09, 2008, 12:38 PM
Quote from: Banana fanna fo fanna on June 01, 2008, 12:08 PM
i wouldn't use sql if i were you. the technology is outdated and is barely in use anymore. only a few vendors support the technology until its end of life later this year. no real company still uses a sql database these days. sql is slow, inflexible, and overall lacking in relevance to any career plans you may have.

instead, i would use ajax.

uh, i work at zynga and we use the following:
mysql database
memcache
mongoDB for persistence
php to wrap facebook api
java and smartfox for socket server
flash client with some javascript


what is wrong with mysql btw?
Title: Re: SQL Databases
Post by: rabbit on January 05, 2010, 09:31 AM
Dunno.  AJAX doesn't replace a database anyway....
Title: Re: SQL Databases
Post by: smithshn on May 17, 2010, 12:19 PM
You can use the normalization. Normalization can sort the data and it manage the database properly.Therefore, you can access your database as fast in minimum duration by query.