Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

want to allow null values

Posted on 2010-01-11
6
Medium Priority
?
225 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
  • 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
 
LVL 1

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 1

Author Closing Comment

by:rgb192
ID: 31675833
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

581 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