Saturday, February 25, 2012

defaults

Can someone give me a simple example of how you use the
defaults in sql server 2000? I cant figure it outSee following exmaple:
(while creating table)
CREATE TABLE multinulls (
a int NULL,
b char(5) default 'hello'
)
you can also create default as an object and bind it to table's column
Ex:
CREATE DEFAULT abc_const AS 'abc'
GO
sp_bindefault abc_const, 'test_defaults.char1'
GO
-Vishal
"bill" <bkelleman@.pcdata1.com> wrote in message
news:02a901c377be$aada4a30$a101280a@.phx.gbl...
> Can someone give me a simple example of how you use the
> defaults in sql server 2000? I cant figure it out|||What exactly do you mean? How to insert default values or How to set it up?
Setup.
For example Open EM, Create a table two columns
Column 1 name it Log_Date datetime with a default of getdate()
Column 2 name it test_data varchar(20)
Open the table and insert something on the test_data column click on the
exclamation point to execute
or simply use query analyzer
BEGIN TRANSACTION
CREATE TABLE dbo.test0001
(
log_date datetime NULL,
test_data varchar(20) NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.TEST001 ADD CONSTRAINT
DF_Table1_log_date DEFAULT getdate() FOR log_date
GO
COMMIT
INSERT INTO TEST0001(TEST_DATA)
SELECT 'TEST1'
SELECT * FROM TEST0001
If you create a new default on a column to an existing table with data then
you need to do something like
insert into test0001 default values
select * from test0001
Hope this helps
Yovan Fernandez
"bill" <bkelleman@.pcdata1.com> wrote in message
news:02a901c377be$aada4a30$a101280a@.phx.gbl...
> Can someone give me a simple example of how you use the
> defaults in sql server 2000? I cant figure it out

No comments:

Post a Comment