hello
hello

Reputation: 29

Error: Invalid column name

I get these errors:

Invalid column name 'Addmin'.

Invalid column name 'Addmin'.

The multi-part identifier "[email protected]" could not be bound.

Invalid column name 'P@55word'.

Invalid column name 'BioMedical_Sciences'.

I am trying to enter data into a table. I have included my create table code too so you can look at the data types and so on.

CREATE TABLE Accounts 
(
     ID INT NOT NULL,
     FIRSTNAME CHAR(20) NOT NULL,
     SURNAME CHAR(20) NOT NULL,
     EMAIL CHAR(50) NOT NULL,
     PASSWORD CHAR(20) NOT NULL,
     AGE INT NOT NULL,
     COURSE CHAR(25),      

     PRIMARY KEY (ID)
);

ALTER TABLE Accounts
ALTER COLUMN FIRSTNAME CHAR;

ALTER TABLE Accounts
ALTER COLUMN SURNAME CHAR;

ALTER TABLE Accounts
ALTER COLUMN EMAIL CHAR;

ALTER TABLE Accounts
ALTER COLUMN PASSWORD CHAR;

ALTER TABLE Accounts
ALTER COLUMN AGE INT;

ALTER TABLE Accounts
ALTER COLUMN COURSE CHAR;

INSERT INTO Accounts (ID, FIRSTNAME, SURNAME, EMAIL, PASSWORD, AGE, COURSE)
VALUES (1, Addmin, Addmin, [email protected], P@55word, 19, BioMedical_Sciences);

Upvotes: 1

Views: 3076

Answers (1)

Aamir Mulla
Aamir Mulla

Reputation: 76

Default char length is 1.

https://learn.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql

When you altered the column types, you reset the char column sizes to 1, and hence the truncation is occurring.

Upvotes: 5

Related Questions