andrelange91 andrelange91 - 1 year ago 98
SQL Question

add bool column within existing table

I am trying to dd a column, to a database with the program Microsoft SQL Server Management Studio.

I already have a database, with a table, in that table i need to add another column.. but it keeps saying it cannot find type bool or boolean.

my code :

ALTER TABLE table_name ADD IsOpen boolean GO

Any ideas ?

side question, any idea how to alter an existing column ? i have a column called "budget" but it needs to be "Budget".

Answer Source

You need to use bit instead of bool datatype

ALTER TABLE table_name ADD IsOpen bit

Here some info about datatypes

Data type   Access  SQLServer   Oracle  MySQL   PostgreSQL
boolean     Yes/No   Bit         Byte   N/A      Boolean

Answer for Qustion 2

The syntax to rename a column in an existing table in SQL Server (Transact-SQL) is:


sp_rename 'table_name.old_column_name', 'new_column_name', 'COLUMN';

For your column :

sp_rename 'table_name.budget', 'Budget', 'COLUMN';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download