Below this is what I'm writing. On the last step it is crashing. Thank you for help. I tried what I found for example:
SET ANSI_WARNINGS OFF
INSERT INTO bands (name)
VALUES ('Iron Maiden');
SET ANSI_WARNINGS ON
GO
But it did not work.
CREATE TABLE bands (
id INT NOT NULL IDENTITY,
name NVARCHAR NOT NULL,
PRIMARY KEY (id) -
)
CREATE TABLE Albums (
id INT NOT NULL IDENTITY,
name NVARCHAR NOT NULL,
release_year INT,
band_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (band_id) REFERENCES bands(id),
INSERT INTO bands (name)
VALUES ('Iron Maiden');
String or binary data would be truncated in table 'Record_Company.dbo.bands', column 'name'. Truncated value: 'I'.
CodePudding user response:
https://www.sqlservertutorial.net/sql-server-basics/sql-server-nvarchar/
NVARCHAR(n)
Code language: SQL (Structured Query Language) (sql) In this syntax, n defines the string length that ranges from 1 to 4,000. If you don’t specify the string length, its default value is 1.
(emphasis mine)
So your NVARCHAR
is interpreted as NVARCHAR(1)
which means it can hold a string of only 1 character. Your string "Iron Maiden" is truncated to the first character, "I".