Showing posts with label language. Show all posts
Showing posts with label language. Show all posts

Sunday, March 11, 2012

Columns vs. Rows

hi,

I'm building a multi-lingual website

In my database tables I have, in some of them, a column with the Language, because some of the columns depend on what language the user wants to see the site.

My question is: what is better? have that column and consequently two row (for two languages) with repeated column information? or have two column within a row with the language specification?

e.g.

table: id, description, price

(1) With language:

id,description, price, language='EX'

id,description, price, language='EN'

vs.

(2)

id, descriptionEN,descriptionEX,price

if I have 500 products

in 1 whould result in 1000 entries

in 2 just 500 results

can anyone tell me a diference/advantage between the two approachs?

thanks in advance.

In a problem like this, I would be guided by the following:

If the number of languages is fixed (i.e. the number of columns is not expected to change), go with the second approach (each language in a different field)

In case the number of languages can increase, go with the first approach as it gives you the flexibility to add another row for every new language.

Saturday, February 25, 2012

Column name as the result of a query?

Simple example would look like that in MS SQL

SELECT 'a' AS (SELECT language_name FROM language WHERE language_id = 1)

So that the display is

English
a

as we assume that

SELECT language_name FROM language WHERE language_id = 1

returns only English

I have tried to that with a variable but it does not work

declare @.that as varchar(15);
set @.that = (select language_name_u from language where language_id = 1);
select 'a' as @.that

LOL

I just tried another way as i was going to post

declare @.that as varchar(15);
set @.that = (select language_name_u from language where language_id = 1);
select 'a' as "@.that"

and it worked!

Posting anyway so people might answer with a better solution with no variable

Thanks a lot

Mordandeclare @.that as varchar(15);
set @.that = (select language_name_u from language where language_id = 1);
select 'a'= @.that