Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alter SQL Table default data type during design

Tags:

sql

sql-server

I would like to change the default data type when designing a table in SQL Server Management Studio Table Designer. My current default is nchar(10) and I am creating a table with a lot of integer data types. I looked in Tools Options but could not find anyplace to change this. I'm running SQL Server 2008 R2.

like image 516
Alan Fisher Avatar asked Jan 05 '13 19:01

Alan Fisher


People also ask

Can ALTER TABLE change data type?

We can use ALTER TABLE ALTER COLUMN statement to change the datatype of the column. The syntax to change the datatype of the column is the following. In the syntax, Tbl_name: Specify the table name that contains the column that you want to change.

Can we alter default value in SQL?

You can use the ALTER TABLE statement to add, change, or remove the default value for a column.

How do I set default value in query?

Select the column for which you want to specify a default value. In the Column Properties tab, enter the new default value in the Default Value or Binding property. To enter a numeric default value, enter the number. For an object or function enter its name.


2 Answers

It is possible, but requires a modification of the registry. This is a tiresome change to make every time you wish to change the default, so I agree with NYCdotNet.

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell\DataProject

Screenshot of regpath

like image 66
MarkD Avatar answered Sep 30 '22 13:09

MarkD


It sounds like you're ready to create your table using T-SQL and not the designer. A variation of the below code will cover you for putting together a basic schema and if you want to do more stuff you can always revise the table in the designer later.

CREATE TABLE MyTableName (
  MyID INT NOT NULL IDENTITY(1,1),
  MyColumn1 INT NOT NULL,
  MyColumn2 INT NULL,
  MyColumn3 VARCHAR(100) NULL,
  PRIMARY KEY (MyID)
)
like image 21
NYCdotNet Avatar answered Sep 30 '22 14:09

NYCdotNet