?
Solved

want to allow null values

Posted on 2010-01-11
6
Medium Priority
?
224 Views
Last Modified: 2012-05-08
want to set
date, orderid, trackingnumber, shipper, cost, void, name,address


to allow null values
(from not null to null)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[trackingnumbers](
	[trackingnumberid] [int] IDENTITY(1,1) NOT NULL,
	[date] [datetime] NOT NULL CONSTRAINT [DF_trackingnumbers_date]  DEFAULT (getdate()),
	[orderid] [varchar](50) NOT NULL,
	[trackingnumber] [varchar](50) NOT NULL,
	[shipper] [varchar](10) NOT NULL,
	[cost] [decimal](10, 2) NOT NULL,
	[void] [varchar](20) NOT NULL,
	[name] [varchar](100) NOT NULL,
	[address] [varchar](100) NOT NULL,
 CONSTRAINT [PK__trackingnumbers__2B3F6F97] PRIMARY KEY CLUSTERED 
(
	[trackingnumberid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Open in new window

0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 26288800
use this
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[trackingnumbers](
        [trackingnumberid] [int] IDENTITY(1,1) NOT NULL,
        [date] [datetime] CONSTRAINT [DF_trackingnumbers_date]  DEFAULT (getdate()),
        [orderid] [varchar](50),
        [trackingnumber] [varchar](50),
        [shipper] [varchar](10),
        [cost] [decimal](10, 2),
        [void] [varchar](20),
        [name] [varchar](100),
        [address] [varchar](100),
 CONSTRAINT [PK__trackingnumbers__2B3F6F97] PRIMARY KEY CLUSTERED 
(
        [trackingnumberid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Open in new window

0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 1000 total points
ID: 26288802
CREATE TABLE [dbo].[trackingnumbers](
      [trackingnumberid] [int] IDENTITY(1,1) NOT NULL,
      [date] [datetime] NULL CONSTRAINT [DF_trackingnumbers_date]  DEFAULT (getdate()),
      [orderid] [varchar](50) NULL,
      [trackingnumber] [varchar](50) NULL,
      [shipper] [varchar](10) NULL,
      [cost] [decimal](10, 2) NULL,
      [void] [varchar](20) NULL,
      [name] [varchar](100) NULL,
      [address] [varchar](100) NULL,
 CONSTRAINT [PK__trackingnumbers__2B3F6F97] PRIMARY KEY CLUSTERED
(
      [trackingnumberid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


or for an existing table

ALTER TABLE [dbo].[trackingnumbers] alter column [orderid] [varchar](50)  NULL   --
0
 

Author Comment

by:rgb192
ID: 26288819


trackingnumbers is an existing table

would i do this
ALTER TABLE [dbo].[trackingnumbers] alter column [orderid] [varchar](50)  NULL   --

for every column
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 26

Expert Comment

by:tigin44
ID: 26288876
instead copy the current data to a temporary table ... recreate the table and move the data back to the original table
0
 
LVL 26

Assisted Solution

by:tigin44
tigin44 earned 1000 total points
ID: 26288886
this should do that
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

SELECT * INTO trackingnumbers_TMP
FROM trackingnumbers

DROP TABLE trackingnumbers

CREATE TABLE [dbo].[trackingnumbers](
        [trackingnumberid] [int] IDENTITY(1,1) NOT NULL,
        [date] [datetime] CONSTRAINT [DF_trackingnumbers_date]  DEFAULT (getdate()),
        [orderid] [varchar](50),
        [trackingnumber] [varchar](50),
        [shipper] [varchar](10),
        [cost] [decimal](10, 2),
        [void] [varchar](20),
        [name] [varchar](100),
        [address] [varchar](100),
 CONSTRAINT [PK__trackingnumbers__2B3F6F97] PRIMARY KEY CLUSTERED 
(
        [trackingnumberid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

INSERT INTO trackingnumbers
SELECT * FROM trackingnumbers_TMP

GO
SET ANSI_PADDING OFF

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 31675833
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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