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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Create table-issue
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwacz23
Starting Member

44 Posts

Posted - 11/11/2012 :  06:20:20  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/11/2012 :  07:14:57  Show Profile  Reply with Quote
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 - 11/11/2012 :  09:07:26  Show Profile  Reply with Quote
Thanks!!!
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000