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
 Auto Date

Author  Topic 

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-05-31 : 07:46:22
i want to create a table in which a column is the date and time the column must be automatically updated when data is added in the table as the identity column can u give a suggestion

CREATE TABLE firms
(
ItemNo int IDENTITY NOT NULL,
CustomerName varchar(30) NOT NULL,
Address1 varchar(30) NOT NULL,
date& time
Contact varchar(25) NOT NULL,
Phone char(15) NOT NULL
)

beside the date & time wt can i add to auto update the column

KaShYaP

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-05-31 : 08:08:42
please consider

KaShYaP
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-05-31 : 08:11:34
Use getdate() function at the time of insertion or updation...

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-31 : 08:14:32
CREATE TABLE firms
(
ItemNo int IDENTITY NOT NULL,
CustomerName varchar(30) NOT NULL,
Address1 varchar(30) NOT NULL,
date_time datetime default getdate(),
Contact varchar(25) NOT NULL,
Phone char(15) NOT NULL
)

Madhivanan

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

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-05-31 : 08:20:23
quote:
Originally posted by madhivanan

CREATE TABLE firms
(
ItemNo int IDENTITY NOT NULL,
CustomerName varchar(30) NOT NULL,
Address1 varchar(30) NOT NULL,
date_time datetime default getdate(),
Contact varchar(25) NOT NULL,
Phone char(15) NOT NULL
)

Madhivanan

Failing to plan is Planning to fail



this works but i can't insert the data into the table wt's the reason i can't understand

KaShYaP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-31 : 08:22:09
quote:
Originally posted by kashyapsid

quote:
Originally posted by madhivanan

CREATE TABLE firms
(
ItemNo int IDENTITY NOT NULL,
CustomerName varchar(30) NOT NULL,
Address1 varchar(30) NOT NULL,
date_time datetime default getdate(),
Contact varchar(25) NOT NULL,
Phone char(15) NOT NULL
)

Madhivanan

Failing to plan is Planning to fail



this works but i can't insert the data into the table wt's the reason i can't understand

KaShYaP


You need to omit that column in the INSERT statement

Madhivanan

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

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-05-31 : 08:24:09
@madivan
|ItemNo|CustomerName|Address1|date_time|

this is the table & i have removed the last two columns that are contact & phone
Plz consider

KaShYaP
Go to Top of Page

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-05-31 : 08:25:49
insert into firms ('Jow', 'plipians')

i am using this command

KaShYaP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-31 : 08:27:44
insert into firms (CustomerName,Address1)
select 'Jow', 'plipians'


Madhivanan

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

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-05-31 : 08:29:08
thanks alot this works really thanks for considering

KaShYaP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-31 : 08:30:00
quote:
Originally posted by kashyapsid

thanks alot this works really thanks for considering

KaShYaP


You are welcome

Madhivanan

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

- Advertisement -