2

How can I alter a column's attribute using a sql script?

Here's what I've tried but I got errors:

ALTER TABLE [dbo].[tblBiometricPattern] COLUMN BiometricPatternID TINYINT NOT NULL IDENTITY(1,1)

Thank you in advance.

Here's the error message that appears when executed:

Incorrect syntax near the keyword 'COLUMN'.
3
  • 2
    i would seriously question how wise creating an IDENTITY on a tinyint is Commented Jan 31, 2011 at 8:14
  • 1
    Identity on a tinyint is a no-no. Basically it's either a really small table, and you're better off managing the ID yourself (to keep consistent across deployments and such), or it's a large table, and then tinyint is just, well, tiny! Commented Jan 31, 2011 at 8:20
  • It just happen that I just wanted to try it on a different data type. =) Commented Jan 31, 2011 at 8:22

3 Answers 3

2

If you're trying to alter the column so that it's an IDENTITY column... you can't do that. You can add a new column with the identity property, but you can't alter an existing column.

If that's not what you're trying to do, perhaps you could include the actual error messages you're getting.


The general form for altering an existing column is:

ALTER TABLE [dbo].[tblBiometricPattern] ALTER COLUMN BiometricPatternID TINYINT NOT NULL IDENTITY(1,1)

(that is, you were missing the word "ALTER" before COLUMN). But as I say, this will now return an error telling you that you can't change the IDENTITY property of the column.


If the column is already an identity column, and you're just altering the datatype, then leave off the IDENTITY() property. It will still be an identity column:

ALTER TABLE [dbo].[tblBiometricPattern] ALTER COLUMN BiometricPatternID TINYINT NOT NULL
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the information Damien_The_Unbeliever. I've already included the error message on the SQL.
2

ALTER TABLE table_name ALTER COLUMN column_name datatype

Comments

1

If you want to alter/modify column of a table.
For MySQL / Oracle (prior version 10G):

ALTER TABLE table_name MODIFY COLUMN column_name datatype;

For Oracle 10G and later:

ALTER TABLE table_name MODIFY column_name datatype;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.