sql server programming:
If there is only 1 BIT column, it will occupy one byte per row. If you have
up to 8, it should still only occupy one byte per row.
Of course, you could always confirm this for yourself by running a quick
test:
CREATE DATABASE splunge
GO
USE splunge
GO
CREATE TABLE foo1 -- 1 bit col
(
a BIT NOT NULL DEFAULT 1
)
CREATE TABLE foo2 -- 4 bit cols
(
a BIT NOT NULL DEFAULT 1,
b BIT NOT NULL DEFAULT 1,
c BIT NOT NULL DEFAULT 1,
d BIT NOT NULL DEFAULT 1
)
CREATE TABLE foo3 -- 8 bit cols
(
a BIT NOT NULL DEFAULT 1,
b BIT NOT NULL DEFAULT 1,
c BIT NOT NULL DEFAULT 1,
d BIT NOT NULL DEFAULT 1,
e BIT NOT NULL DEFAULT 1,
f BIT NOT NULL DEFAULT 1,
g BIT NOT NULL DEFAULT 1,
h BIT NOT NULL DEFAULT 1
)
CREATE TABLE foo4 -- 9 bit cols
(
a BIT NOT NULL DEFAULT 1,
b BIT NOT NULL DEFAULT 1,
c BIT NOT NULL DEFAULT 1,
d BIT NOT NULL DEFAULT 1,
e BIT NOT NULL DEFAULT 1,
f BIT NOT NULL DEFAULT 1,
g BIT NOT NULL DEFAULT 1,
h BIT NOT NULL DEFAULT 1,
i BIT NOT NULL DEFAULT 1
)
GO
SET NOCOUNT ON
DECLARE @i INT
SET @i = 0
WHILE @i < 10000
BEGIN
INSERT foo1 DEFAULT VALUES
INSERT foo2 DEFAULT VALUES
INSERT foo3 DEFAULT VALUES
INSERT foo4 DEFAULT VALUES
SET @i = @i + 1
END
GO
EXEC sp_spaceused foo1
EXEC sp_spaceused foo2
EXEC sp_spaceused foo3
EXEC sp_spaceused foo4
GO
USE master
GO
DROP DATABASE splunge
GO
--
http://www.aspfaq.com/ (Reverse address to reply.)
[quoted text, click to view] "Prabhat" <not_a_mail@hotmail.com> wrote in message
news:OzjG7fDaEHA.3116@TK2MSFTNGP10.phx.gbl...
> Hi All,
>
> How much space a BIT Datatype takes in SQL Server Table.
>
> I read from BOL that if I have 8 or less that will take 1 byte of space.
> What does that specify the size of a table with only one bit field?
>
> IS THAT 1 BIT or 1 BYTE or 16KB (a Page Size)
>
> Thanks for any reply.
> Prabhat
>
>