Showing posts with label datatypes. Show all posts
Showing posts with label datatypes. Show all posts

Sunday, March 25, 2012

Best practise of storing a column which is of string type

Hi,

Hi I am currently using SQL Server 2005.

Whats the difference between nvarchar & varchar datatypes in SQL server and which is opted best to store strings.

Thanks,

Uma Ramiya

nvarchar is used commonly used to store national characters / unicode characters. so if your front end application accepts unicode characters to be stored to your db then you should use nvarchar. if not use varchar instead
|||

I use ASp.Net 2.0 as front end. In that case what should I use

Thanks,

Uma Ramiya

|||its not dependent on asp.net. it depends on the localization of your application e.g. does your asp.net application can be viewed, transalated and/or accepts inputs with chinese , korean characters, etc. then you should use nvarchar. if you application only stores english characters then use varchar
|||

If you want to store english (latin based) string then you can use varchar.

If you want to store non-english string (ex. Japanese, Hindi, Tamil etc) then you have to use NVarchar.

Nvarchar uses Unicode (which supports all the alphabets/numbers)

Varchar Uses ASCII CODE (which supports only english alphabets/numbers)

Nvarchar each char occupies 2 Byte

Varchar each char occupies 1 Byte

Nvarchar max length in SQL Server 2000 = 4000

Varchar max length in SQL Server 2005 = 8000

If your app supports (or planned to support on future) Globilization/Localization then use the NVarchar

Otherwise Varchar is more enough..

Sunday, March 11, 2012

Best practice datatypes

HI all,
Which ould be the best datatype to use. I have possibilities of monetory
values from 0 to 1000000000
I've heard that the money datatype is not readily used. Should I use
numeric. What do you guys use
Thanks
RobertRobert Bravery wrote:
> HI all,
> Which ould be the best datatype to use. I have possibilities of monetory
> values from 0 to 1000000000
> I've heard that the money datatype is not readily used. Should I use
> numeric. What do you guys use
> Thanks
> Robert
Not MONEY or SMALLMONEY. See:
http://groups.google.co.uk/group/mi...718f3de3?hl=en&
DECIMAL or INTEGER should be suitable in your case.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks David,
Very informative, I never knew this was the case
Thanks
Robert
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1139567259.859890.220900@.g14g2000cwa.googlegroups.com...
> Robert Bravery wrote:
> Not MONEY or SMALLMONEY. See:
>
http://groups.google.co.uk/group/mi...rogramming/msg/
df52c1b2718f3de3?hl=en&
> DECIMAL or INTEGER should be suitable in your case.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>

Friday, February 24, 2012

best approach

I have two tables with same datatypes. I need to view all the rows
from both tables and check to see if they exist in a third table while
viewing the data. My plan thus far is to use a union query and a
function that returns a bit showing if they are in third table. Should
I use this approach (shown below) or should this be a join query
between the union portion and third table with consideration to speed
and viability?
select chemical, fncExist(cid) as exist
from table1
union all
select chemical, fncExist(cid) as exist
from table2
where:
CREATE FUNCTION dbo.fncExist
(
@.cid int
)
RETURNS bit
AS
BEGIN
declare @.exist int
declare @.bln bit
select @.exist =Count(id) from table3 where vid = @.cid
if @.exist>0
begin
@.bln=1
end
else
begin
@.bln=0
end
RETURN @.bln
ENDUsing a scalar function like this can really bring performance down to
snail-on-glue speed.
Try something like this:
select <column list>
,exist
= case when <third table>.<unique key> is null
then 0
else 1
end
from (
select chemical
,cid
from table1
union all
select chemical
,cid
from table2
) Both
left join <third table>
on <third table>.cid = Both.cid
ML
http://milambda.blogspot.com/|||Thanks thats what I needed to know.