tags:

views:

323

answers:

3

I'm learning how to use SQL Server Management Studio and can't figure out how to insert a new row into a table.

Table Structure:

ID,
Field1,
Field2

Query:

INSERT INTO Table (Field1,Field2) VALUES(1,2)

Error:

Major Error 0x80040E14, Minor Error 25503

I'm probably missing something very noobie like. Any help would be appreciated.

+1  A: 

Does your table have an auto-incrementing ID field? If not, you will need to manually specify the value for the ID in your INSERT statement.

You can check if the ID field is auto-incrementing by using the Object Explorer, navigating to the table and expanding the Columns node. Find the ID column, right-click on it and select Properties. If the Identity property is set to False it means that the ID field is NOT auto-incrementing.

Your other option for adding a row to the table is to navigate to the table in Object Explorer, right clicking on it and selecting Open Table. You can then go to the last row in the grid and manually enter the values for the columns.

TLiebe
ID is set as the primary key, and identity, with the identity seed and increment set to 1. Based on my understanding of this software, this is the equivalent of specifying an auto increment. So that is why I do not specify the ID explicitly.
Soo
Try adding a row through the Open Table process as I describe in my edited post. Do you get the same error? Also - what are the field types for Field1 and Field2? Are you sure they're numeric fields? If not you'll need to surround the values you're adding with quotes.
TLiebe
When I navigate to the table, there are two folders: Columns and Indexes. I don't see the option to view the whole table.
Soo
Right-click on the actual table name and there should be an option to open the table. I'm using SQL Server 2005, SQL Server 2008 might call it something slightly different.
TLiebe
These are the options I see:Edit TablesPropertiesDeleteReports > Custom ReportsRefreshI'm using Microsoft SQL Server Management Studio. Maybe I'm using the wrong software?
Soo
SQL Server Management Studio is the right software. Maybe it's a permissions problem. You're only seeing some of the options that I have in my database. Do you have the right permissions to be able to view the table data?
TLiebe
A: 

Management studio will very kindly script inserts, updates, selects and deletes for you. Navigate to the table in the explorer, right click, 'Script table as', choose 'Insert'.

What does that spit out and how does it differ to what you wrote?

Mark Storey-Smith
+1  A: 

Ok, I was on the verge of pulling out all of my hair, and it appears using single quotes instead of double quotes fixed the problem.

Now, I want to pull my hair out even more.

Thanks for the replies everyone. This one was my mistake.

Soo