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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Create table-issue

Author  Topic 

kwacz23
Starting Member

44 Posts

Posted - 2012-11-11 : 06:20:20
Hi,

I would like to create table where one column will be automatically fulfilled. Please find below

CREATE TABLE Users
(Id int not null primary key,
Imie varchar(255),
kod_stanowiska varchar(255),
kod_zespolu varchar(255),
id_przelozonego varchar(255),
data_zatrudnienia datetime,
wynagrodzenie varchar(255),
lastmodification datetime DEFAULT getdate())

When I am trying add regords like:
insert into Users
values
(1,'Adrian','5','2','2','2012-06-30 23:59:59','5000')

There is the error message : 'Column name or number of supplied values does not match table definition'.
I do not understand why because the last column should be filled automatically by 'getdate'.

Could you help me where I am wrong.

rEGARDS,

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-11 : 07:14:57
Change the syntax to explicitly list the column names as shown below. Having a default value does not let you exclude the data for that column unless you explicitly list columns. Some other types of columns - identity columns, computed columns etc. would let you or may require you to do so, but not having a default value
insert into Users
(Id, Imie, kod_stanowiska, kod_zespolu,id_przelozoneg,data_zatrudnienia,wynagrodzenie)
values
(1,'Adrian','5','2','2','2012-06-30 23:59:59','5000')
Go to Top of Page

kwacz23
Starting Member

44 Posts

Posted - 2012-11-11 : 09:07:26
Thanks!!!
Go to Top of Page
   

- Advertisement -