Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, May 7, 2016

Why this insert query go into error?

Why this insert query go into error?


I am very new to Microsoft SQL Server and I have a problem with this INSERT query that inserts a new record in a very very big table (it has many columns).

I have this query:

INSERT INTO VulnerabilityAlertDocument ([Id],                       [VulnerabilityAlertId],                       [SourceId],                       [BugTraqID],                       [Title],                       [StatusID],                       [CVE],                       [Published],                       [LastUpdated],                       [Remote],                      [Local],                      [Credibility],                      [Classification],                      [Availability],                       [Ease],                      [Authentication],                       [CVSS2_BaseScore],                       [CVSS2_TemporalScore],                       [CVSS2_BaseVector],                       [CVSS2_TemporalVector],                       [CVSS1_BaseScore],                       [CVSS1_TemporalScore],                       [NVD_CVSS2_BaseScore],                       [NVD_CVSS2_ComponentString],                       [ImpactRating],                       [Severity],                       [EaseofExploit],                       [UrgencyRating],                       [LastChange],                       [ShortSummary],                       [Impact],                       [TechnicalDescription],                       [AttackScenario],                       [Exploit],                       [Credit],                       [URL],                       [AlertStatusId],                       [Type],                       [DetailLevel],                       [Language],                       [dd])  VALUES('10000',          '10000',          'TEST',          '5',         'TEST TITLE',         '1',         'TEST CVE',         '1998-04-30 00:00:00.000',         '2007-11-05 16:32:34.000',         'TEST REMOTE',         'TEST LOCAL',         'TEST CREDIBILITY',         'TEST CLASSIFICATION',         'TEST Availability',         'TEST EASE',         'TEST Authentication',         'TEST CVSS2_BaseScore',         'TEST VSS2_TemporalScore',         'TEST CVSS2_BaseVector',         'TEST VSS2_TemporalVector',         'TEST CVSS1_BaseScore',         'TEST CVSS1_TemporalScore',         'TEST NVD_CVSS2_BaseScore',         'TEST NVD_CVSS2_ComponentString',         '2',         '3',         '10',         '7',         'TEST LastChange',         'TEST ShortSummary',         'TEST IMPACT',         'TEST TechnicalDescription',         'TEST AttackScenario',         'TEST Exploit',         'TEST Credit',         'TEST URL',         '5',         '3',         '1',         'TEST Language',         'NULL');  

In which I insert a specific value into a specified column (I specify columns by the first query section, and I specify the related values by the second section of the query)

The problem is that when I try to execute the previous query I obtain the following error

Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'VulnerabilityAlertDocument' when IDENTITY_INSERT is set to OFF.

Why? What does this mean? How can I change my query to solve this problem and so insert the record in my table?

Answer by Alexander for Why this insert query go into error?


Try SET IDENTITY_INSERT VulnerabilityAlertDocument ON before INSERT

After INSERT, add SET IDENTITY_INSERT VulnerabilityAlertDocument OFF

Answer by Abhishek Chaudhary for Why this insert query go into error?


Use SET IDENTITY_INSERT ON before your query. Identity columns are auto-increasing and so do not allow insertion. You need to explicitly state that you want to insert data into the column so that SQL server allows it.

Make sure you do not insert duplicate values for this column.

The best practice is to avoid inserting values into IDENTITY column.

Answer by Akrem for Why this insert query go into error?


you have an identity column then you don't have to insert the Id, you have to delete Id from your query and the value of the Id

Answer by jean for Why this insert query go into error?


Remove the [Id] column from the list of columns and its corresponding value '10000'. The error is due you are trying to populate a column with a value and SQL is complaining that a automated handled value just he can provide. BTW, you don't need to quote your numeric values if that columns are of numeric type.

Answer by Ahmed Hillal for Why this insert query go into error?


Remove "[ID]"

write it like that:

INSERT INTO your table name

For example: If you have Instructor table with attributes ID, name and dept_name Use: Insert Command like bellow

Insert Into Instructor (ID, name, dept_name) Values (11111, 'Andrea', 'Biology');  

Try this and let me show you result !!


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.