Solved

sql null

Posted on 2011-03-09
6
187 Views
Last Modified: 2012-05-11
I have a smallint data type in sql ex 2008.
I want a default value of 0 so what do I do?
0
Comment
Question by:jagguy
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35089453
You could set a default value on the column in the table design, is that what you mean?
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 35089460
in the column definition for the table   have the phrase  DEFAULT 0

create table x  (col1 smallint default 0  , ....)

or
alter table x alter column x smallint default 0

Insert into x (col2,....)     -- but don't name the col1
  values (1,2,...)     -column col1 will get the default

or Insert into x (col1,col2,...)
 values (DEFAULT,1,2,...)   -- using the KEYWORD DEFAULT


is that what you where asking for ?  otherwise please be specific and state what you need to know understand...
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35089467

use alter table to create a constraint

alter table emp2
add constraint MyColumnDefX default (1) for MyColumn
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:jagguy
ID: 35089730
IN sql management studio what can i do because i am using this an dprefer to use this.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 35089736
Go to the table design view, select column and set default value to 0
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 35089895
in management studio

select new query

and run the code!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now