Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
CREATE TABLE Employee (
	employee_id INTEGER PRIMARY KEY IDENTITY,
    contractor_id INTEGER,
    first_name VARCHAR(25),
    last_name VARCHAR(25),
    email VARCHAR(30),
    SSN VARCHAR(11),
    street_address VARCHAR(255),
    city VARCHAR(50),
    state VARCHAR(50),
    zip INTEGER(5),
    department_id INTEGER,
    building_assigned INTEGER
	);


Can someone explain to me why I keep getting this error -
Msg 2716, Level 16, State 1, Line 1
Column, parameter, or variable #10: Cannot specify a column width on data type int.


What I have tried:

I don't know where to even begin, because this is for my intro class and I'm very lost.
Posted
Updated 31-Oct-22 22:07pm
v2

1 solution

Read the error message:
Cannot specify a column width on data type int.
Then look at your code, and find all the INT datatype columns:
SQL
CREATE TABLE Employee (
	employee_id INTEGER PRIMARY KEY IDENTITY,
    contractor_id INTEGER,
...
    zip INTEGER(5),
    department_id INTEGER,
    building_assigned INTEGER
	);
One of these is not like the others:
SQL
zip INTEGER(5),
As the error message says, you can't specify a width for integer values: they all take the same amount of space: 4 bytes.
Remove the (5) bit.

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900