Solved

TSQL Insert With Just Default Values

Posted on 2011-03-03
3
211 Views
Last Modified: 2012-05-11
Hi Experts,

Don't know if this is possible. Have a table with just an ID and datetime so both are set with defaults.

CREATE TABLE [dbo].[tb_ErrorLog](
	[errorLogID] [int] IDENTITY(1,1) NOT NULL,
	[errorLogDate] [datetime] NOT NULL,
 CONSTRAINT [PK_tb_ErrorLog] PRIMARY KEY CLUSTERED 
(
	[errorLogID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[tb_ErrorLog] ADD  CONSTRAINT [DF_tb_ErrorLog_errorLogDate]  DEFAULT (getdate()) FOR [errorLogDate]
GO

Open in new window


All I want to do is to increment the table with a record every time a particular web page is reached.

So how do you write the INSERT statement without any passed values?

Regs,
Numb
0
Comment
Question by:ComfortablyNumb
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35026483
INSERT INTO [SS].[dbo].[tb_ErrorLog]
           ([errorLogDate])
     VALUES
           (default)
0
 
LVL 10

Accepted Solution

by:
Asim Nazir earned 500 total points
ID: 35026516
Also you can use following:
INSERT INTO [SS].[dbo].[tb_ErrorLog]
           DEFAULT VALUES
0
 

Author Closing Comment

by:ComfortablyNumb
ID: 35026589
As simple as that! cheers
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question