Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 regarding default data in tables

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2006-10-19 : 02:27:16
hi,
i wish to create a table which contain fields num,name. i want to maintain some default data in column name. so iwant to insert my default data say(ram,ramu1,ram2) in the column at the time of my table craetion.
i written the code
create table tab1
(
num int primary key,
name char(20),
insert into tab1(name) values(ram)
)

but it is throwing some erroes.
can u pls suggest me a way to deal this task.

thanx in advance,
rammohan

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-19 : 02:35:26
[code]CREATE TABLE tab1
(
num int IDENTITY (1, 1) NOT NULL PRIMARY KEY,
name varchar(20) NOT NULL,
keycol AS (name + convert(varchar, num))
)[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-10-19 : 03:17:15
you have to create the default constraint for it



ALTER TABLE dbo.Tab ADD CONSTRAINT
DF_Tab_Name DEFAULT 'Ram' FOR Name

Go
-- Then Insert the values in the table..
Insert Tab
DEfault values



Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-20 : 10:21:38

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -