Re: Data Types

From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 02/20/04


Date: Fri, 20 Feb 2004 17:17:19 +0100

Steve,

Inline...

-- 
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:u$EJCk89DHA.2324@tk2msftngp13.phx.gbl...
> Hi all
>
> Sorry if this isn't the best place to ask this question. I've only
recently
> moved to SQL Server and I don't know the best newsgroups yet.
This group is the right one for these types of questions. And, Welcome :-).
>
> Does a Unique Identifier data type take up less storage space than a 32
> character varchar data type?
I encourage you to find the documentation for these things (Books Online),
the Transact-SQL reference. A uniqueidentifier uses 16 bytes.
DECLARE @a uniqueidentifier
SET @a = NEWID()
SELECT DATALENGTH(@a), LEN(@a)
> Also, I have 2 date fields in my tables, one
> for when the record is created and the other for when the record is
> modified. In the past I have set these values from my application
(seperate
> VB app), but I'm looking at the data types and think that the TimeStamp
type
> would update to the current time when the record is modified (is that
> correct?),
No, timestamp in SQL Server is really a binary "counter", it doesn't carry a
datetime value. This partly is why MS is trying to make us use the name
'rowversion' for the datatype instead.
> but what's the best method to set the create date? I would prefer
> not to have to create triggers on all my tables (there are quite a few).
You can have a default for your INSERT statements, but that won't take care
of UPDATEs. Your choices are, as far as I can see, triggers or client/stored
procedure code.
> When specifying a TimeStamp field, can you tell it only to update the time
> if there isn't a value in there already, as will be the case for new
> records?
By "isn't a value", do you mean NULL or time portion is 00:00:00? Doesn't
matter much as you would need to set the "whole " value in your code, there
are no built-in mechanisms to only set one part of the value.
>
> Thanks for any help.
>
> Kind Regards,
> Steve.
>
>


Relevant Pages

  • Re: Convert help needed desperately
    ... overflow error converting expression to data type datetime. ... Is my sql server hosed???? ... > the timestamp data type. ...
    (microsoft.public.sqlserver.programming)
  • Re: Data Types
    ... >> Steve, ... >> Tibor Karaszi, SQL Server MVP ... >>> character varchar data type? ... A uniqueidentifier uses 16 bytes. ...
    (microsoft.public.sqlserver.programming)
  • Re: Date Stamp
    ... HireDate etc.) and the issue about reserved words. ... TIMESTAMP is a standard SQL data type, ... Acess/Jet's big sister, SQL Server, has a TIMESTAMP ...
    (microsoft.public.access.tablesdbdesign)
  • Re: MS-SQL Related
    ... What error message do you see? ... What is uniqueidentifier as a data type? ... Also what is the data type for setting unique STRINGS ((nchar, ... SQL Server does not allow me set primary keys for columns where data ...
    (comp.databases.ms-sqlserver)
  • Re: How to create a timestamp?
    ... SQL Server's Timestamp is a SQL Server specific data type that is simply an ... shows you the SQL Server data type along with the SQL Client equivalent ...
    (microsoft.public.dotnet.languages.vb)