1

I'm trying to insert some data into a SQL Server table I created from scratch and cannot add the two values I would like to add which is 'Technology Question' under the column technology questions nor am I able to enter a time stamp under my time_entered column.

I'm basically trying to create a Microsoft SQL Server database to eventually take over the existence of an existing SQLite3 database so in my early test case here I am attempting to pull in one piece of data from the existing SQLite3 table into the SQL Server table.

I have tried changing the syntax around in as many ways as I can think of but am failing to get anywhere e.g. ensuring single quote tick around data values etc.

select * from questiontype

select [Technology Questions], time_entered
from questiontype

INSERT INTO questiontype ([Technology Questions], time_entered)
VALUES ('Technology Question', '2019-03-23 16:59')

I was hoping to see the data values 'Technology Question', '2019-03-23 16:59' in their respective columns within the SQL Server table 'questiontype'

When I try to do above I get the following,

Msg 8152, Level 16, State 4, Line 6
String or binary data would be truncated

10
  • Post the table DDL, or run sp_help 'questiontype' to see the column data types and maximum lengths. If the column's max length is too short to accommodate the data, SQL Server will give you that error. Commented Mar 24, 2019 at 17:45
  • Thanks! That solves that problem. Secondary issue I have is now when I run that cmd I get 'Msg 515, Level 16, State 2, Line 6 Cannot insert the value NULL into column 'int', table 'TALLY.dbo.questiontype'; column does not allow nulls. INSERT fails. The statement has been terminated.' But I though the int column wasn't supposed to be a null Commented Mar 24, 2019 at 17:53
  • Questiontype is the table, not a column. I thought when creating a basic table you had to create a column name such as int for integer, and set it not allow nulls so subsequent data entry into the table would auto-increment e.g. record #1, record #2, record #3 etc Commented Mar 24, 2019 at 18:23
  • Calling your column int is a rarely (never) a good idea. int is a keyword, for the data type of the same name, and calling your column that will be confusing. In your insert statement you aren't inserting a value into your column int and hence the error. It's quite clear here. Commented Mar 24, 2019 at 18:29
  • Yes I found I made a mistake with that. I changed into to column name 'ID', type int and also set it as the primary key. When I try to run the aforementioned insert statement I am still getting the 'Msg 515, Level 16, State 2, Line 6 Cannot insert the value NULL into column 'ID', table 'TALLY.dbo.questiontype'; column does not allow nulls. INSERT fails. The statement has been terminated.' statement Commented Mar 24, 2019 at 18:31

1 Answer 1

1

Multiple issues but had to set column name to be ID instead of 'INT' and had to make sure it held the identity property. Also had to increase the character limitation for each column.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.