Default Constraint On Columns Pros And Cons?

Oct 26, 2007



Are there any vices to using default constraints on all columns in your table.
For example an Int that defaults to 0
or a char or varchar that defaults to ''

I know that 0 and Null are not the same thing. But if your programs don't have the concept of NULL then you have to convert the NULL to zero.

So, DEFAULT CONSTRAINTS on every column. Is it good or Bad?

Thanks

Darin Clark

View 10 Replies


ADVERTISEMENT

Pros/Cons Of Multivalue Database Columns

Jun 27, 2004

I'm just wondering what any pros and cons of using multivalue columns in a database are.

I'm designing a database which will have a column for FABRIC_TYPES_AVAILABLE for a certain FURNITURE_ITEM. Each FURNITURE_ITEM can have multiple FABRIC_TYPES_AVAILABLE of course. So I was just going to store a 2 or 3 digit number of the FABRIC_TYPES_AVAILABLE in that row. So I would have something like....34,24,453,32,23,45,67,65,43,21,21,45.

Anyway....thanks in advance for any information. Links I could read would be great too...b/c I did do a bit of searching, but didnt find much.

View 6 Replies View Related

SQL Server Pros And Cons

May 22, 2002

My company is thinking about moving to a product that uses Microsoft SQL Server and I have been asked to find out what are the Pros and Cons of the product, if any.

Any feedback is appreciated.

Thank You

Pam

View 2 Replies View Related

Upgrade SQL 7 To SQL 2K: Pros And Cons

Aug 13, 2001

Anyone know where I could find some good articles about pros and cons of upgrading SQL 7 to SQL 2K?

Our boss suddenly got this bug up his rear that we need to upgrade. :(
Probably because we are to a point where everything is running smoothly, and he needs to throw a monkey wrench in it.

We are a very small shop, and are not stressing SQL 7 in the least. I am interested to read some articles about SQL 2K, because right now, I can't see any possible reason an upgrade would be worth doing.

Thanks.

View 2 Replies View Related

Pros / Cons To This Approach

Nov 3, 2005

I have a requirement where I need to perform a query for positioninformation. But for some types of entries, I need to "expand" the rowto include additional position rows. Let me explain with an example:An index is a security that is made up of components where eachcomponent has a "weight" or a number of shares. So if I have 1 share ofthe index, I have X shares of each component.AAPL is an Equity, CSCO is an Equity, SPY is an Index. Lets say thatSPY has one component, AAPL, with shares being 10. (1 share of SPY = 10shares of AAPL).So, I do some trading and I end up with positions as follows:+10 AAPL-5 CSCO+2 SPYThe query I need returns:+10 AAPL-5 CSCO+2 SPY+20 AAPL (from 2 SPY * 10 shares)which becomes (after grouping):+30 AAPL-5 CSCO+2 SPY-----------------------------------------Based on that criteria and the following schema (and sample data):-- Drop tablesDROP TABLE [SecurityMaster]DROP TABLE [Position]DROP TABLE [IndexComponent]-- Create tablesCREATE TABLE [SecurityMaster] ([Symbol] VARCHAR(10), [SecurityType] VARCHAR(10))CREATE TABLE [Position] ([Account] VARCHAR(10), [Symbol] VARCHAR(10), [Position] INT)CREATE TABLE [IndexComponent] ([IndexSymbol] VARCHAR(10), [ComponentSymbol] VARCHAR(10), [Shares] INT)--Populate tablesINSERT INTO [SecurityMaster] VALUES ('AAPL', 'Equity')INSERT INTO [SecurityMaster] VALUES ('MSFT', 'Equity')INSERT INTO [SecurityMaster] VALUES ('MNTAM', 'Option')INSERT INTO [SecurityMaster] VALUES ('CSCO', 'Equity')INSERT INTO [SecurityMaster] VALUES ('SPY', 'Index')INSERT INTO [Position] VALUES ('001', 'AAPL', 10)INSERT INTO [Position] VALUES ('001', 'MSFT', -5)INSERT INTO [Position] VALUES ('001', 'CSCO', 10)INSERT INTO [Position] VALUES ('001', 'SPY', 15)INSERT INTO [Position] VALUES ('001', 'QQQQ', 21)INSERT INTO [Position] VALUES ('002', 'MNTAM', 10)INSERT INTO [Position] VALUES ('002', 'APPL', 20)INSERT INTO [Position] VALUES ('003', 'SPY', -2)INSERT INTO [IndexComponent] VALUES ('SPY', 'AAPL', 25)INSERT INTO [IndexComponent] VALUES ('SPY', 'CSCO', 50)INSERT INTO [IndexComponent] VALUES ('QQQQ', 'AAPL', 33)-- *****************************-- Based on the rules:-- 1) Index positions appear like other positions (account /symbol) pair, but-- its components show up as new rows of account (of index),symbol (equal--to component symbol), position (equal to shares * index position)-- 2) One row for each account / symbol pair (GROUP BY account andsymbol, SUM position)-- Expected output (without grouping) (sorted by account / symbol)-- 001 AAPL 10-- 001 AAPL 375 (component shares * index position) (25* 15) (SPY)-- 001 AAPL 693 (component shares * index position) (33* 21) (QQQQ)-- 001 CSCO 10-- 001 CSCO 750 (component shares * index position) (50* 15) (SPY)-- 001 MSFT -5-- 001 QQQQ 21-- 001 SPY 15-- 002 AAPL 20-- 002 MNTAM 10-- 003 AAPL -50 (component shares * index position) (25* -2) (SPY)-- 003 CSCO -100 (component shares * index position) (50* -2) (SPY)-- 003 SPY -2-- Expected output (with grouping account / symbol) (sorted by account/ symbol)-- 001 AAPL 1078-- 001 CSCO 760-- 001 MSFT -5-- 001 QQQQ 21-- 001 SPY 15-- 002 AAPL 20-- 002 MNTAM 10-- 003 AAPL -50-- 003 CSCO -100-- 003 SPY -2---------------------------------------------Is a UNION the best way to perform the query. What are the pros andcons? What, if any, is a better way?SELECT[Account], [Symbol], SUM([Position]) AS [Position]FROM(SELECT[Account], [Symbol] , [Position]FROM[Position]UNION ALLSELECTP.[Account] , IC.[ComponentSymbol] AS [Symbol] , (P.[Position] *IC.[Shares]) AS [Position]FROM[IndexComponent] ICJOIN[Position] PONP.[Symbol] = IC.[IndexSymbol]) DGROUP BY[Account], [Symbol]ORDER BY[Account], [Symbol]

View 5 Replies View Related

UniqueIdentifier Pros And Cons ??

Jul 20, 2005

Hi alli am building a SQL 2000 database that it is proving a littlechallenging, i have companies with multiple addresses, phone numbers,owning mine sites etc and also joint ventures so maybe you get thepicture with a few design issues that i ma encounteringMy queriy is about a primary key identity, and which one to use withrespect to either the identity data type or the unique identifier ,I am aessentiall building an address table to hold all multipleaddresses as well as phone numbers etc, so my desire to have a uniqueidentity for each record is very important.My view is i will run in to violation errors by just using the tableidentity data type, i could i suppose use composit primary keys butthat may have a performance impact, although thiis will not be a hightransaction database.Does anyone know about performance issues regarding each identitysolution, by using a generated 16 bit identifier there are going to behuge numbers for the DB to verify. or am i worried about nothing?any views greatly appreciatedregardsGreg

View 17 Replies View Related

Pros And Cons Of Stored Procedures

Mar 28, 2004

can anyone explain the Pros and Cons of Stored Procedures ??

thanks

View 2 Replies View Related

Pros And Cons Of Using Stored Procedures

Sep 19, 2007

Im about to start converting code to Stored Procedures for all my reports in Reporting Services. I was wondering what the pros and cons of this may be.

View 17 Replies View Related

Network Backup Again - What Are The Pros And Cons

Sep 11, 2007

Thanks for the help on the previous thread.

It seems to me that either by accident or design, SQL Server tends to steer you away from backing up directly over the network.

Are there reasons for not doing this because you obviously don't want to leave your backups on a local drive in case the drive fails?

Some possibilties that I can think of are:-

1. Local drives have faster access times and SQL backups can get quite large. I did a quick test and found that a netwrok backup takes 2 to 3 times longer than it does on a local drive.
2. Backing up on the netwrok could hog too much bandwidth. I haven't tested this and would be surprised it it's true.
3. There could be some reason that you don't want the Server and Agent services running under a domain account but want to leave them on the Local System account. I am not aware of any such reasons by the way.
4. Local drives persumably have a slightly higher availability than network drives. If the server is running, the drive should be available.

View 8 Replies View Related

What Are The Cons And Pros Of Using Nvarchar(max) Versus Ntext?

Apr 4, 2007

Like in the subject: What are the cons and pros of using nvarchar(max) versus ntext?
Does it have something to do with having to enable full text search perhaps in the latter case?

View 2 Replies View Related

PROS And CONS Of Seperate Databases For CACHING...

May 9, 2006

I have a main database...for this large Web site...and Im wondering
what would be the PROS and CONS of using another database (located on
the same, or on another SQL Server). Im just thinking this would be
good incase we ever needed to take some load off one of the servers.

Also, we will be integrating Community Server into this Web site. Of
course you know CS adds its own database objects which crowd up our
main database objects.

We were thinking of giving CS its own database also; bad practice, or....it doesn't matter much?

Thank you

View 3 Replies View Related

GUID Pros And Cons (was: Question Mssql2005)

Aug 17, 2006

I was wanting to know. I am making a site that might be come big. And me and this dude are considering pickering abotu GUID. I don't want to use them but he does. And I was wondering what should we do? I know nothing about guids

View 1 Replies View Related

Query Excution Process- Pros And Cons

Jun 15, 2006

vinod writes "Q1>Should I apply filter in sequence(based on primarykey,not null,comparision,between clause) ?

-How to apply filter in correct format,and SQL server internally execute it.
Q2>Should I use 'is not Null' to be put at the last?

Q3>Should I use 'between clause' rather than relation operator i.e(empid>10 and empid<200)

Q4>Does filters of sequence has any impact on the query execution process


table1[pkey1,col1,col2,col3] -->pkey is pkey1
table2[pkey2,pkey1,col11,col12,col13]--->pkey is pkey2, and pkey1 is foreign key

CaseI->select table2.pkey2,table1.col1 ,table2.col12
from table1 inner join table2
on table1.pkey1=table2.pkey1
where (table1.col3>100 and table1.col3<300 ) and table2.pkey1=2020 and table2.col13 is not null

CaseII->select table2.pkey2,table1.col1 ,table2.col12
from table1 inner join table2
on table1.pkey1=table2.pkey1
where (table1.col3 between 101 and 299 ) and pkey1=2020 and table2.col13 is not null"

View 1 Replies View Related

Saving Files (Binaries) Into Database - Pros And Cons

Jun 19, 2008

Can someone provide information or a link to information regarding the pros and cons of saving files directly into a SQL 2005 database?
I'm actually for saving files to a database (cleaner implementation then just saving the location then having to get the file, etc), but my project manager is not convinced so I need to make an argument for (or against depending on what I actually find out) using varbinary data type.
Thanks.

View 2 Replies View Related

What Are Cons And Pros For Using IDENTITY Property As PK In SQL SERVER 2000?

Jul 20, 2005

Hi All!We are doing new development for SQL Server 2000 and also moving fromSQL 7.0 to SQL Server 2000.What are cons and pros for using IDENTITY property as PK in SQL SERVER2000?Please, share your experience in using IDENTITY as PK .Does SCOPE_IDENTITY makes life easier in SQL 2000?Is there issues with DENTITY property when moving DB from one serverto another? (the same version of SQL Server)Thank you in advance,Andy

View 49 Replies View Related

Storing SSIS Packages Within SQLServer; Pros/cons

Feb 26, 2008

hi all,
I was wondering if anyone knows of any pros/cons on storing SSIS (2005) packages within SQL Server 2005 SP2.
We're contemplating the migration/storage of a large number of packages, a minority of which designed in dts (SQLServer 2000) and using third party activx components.

thanks much for any feedback,
Cosmin

View 3 Replies View Related

Pros And Cons Of Placing Indexes On Separate File Groups

Apr 20, 2001

We are in the process of replacing our primary production server. In the process of determining how SQL server is going to be structured, it has been suggested that I place all current and new indexes on a separate file group. These filegroups would then reside on a separate shelf on the server. What are the pros and cons of doing this?

View 2 Replies View Related

Pros And Cons Of Using Transaction Replication Doing Initialization From Database Backups

Jun 27, 2007



I am using transaction replication between a transaction and reporting database server. When I use a snapshot to initialize my subscribers, I currently get a lot of deadlocks during the snapshot creation. I am considering using a database backup instead. Can anyone tells me how to reduce the table locks that I am getting during snapshot creation or advice on using database backups?



View 1 Replies View Related

Is DEFAULT A Constraint?

Aug 8, 2006

Hi,I see the following in Books Online: CONSTRAINT--Is an optional keywordindicating the beginning of a PRIMARY KEY, NOT NULL, UNIQUE, FOREIGNKEY, or CHECK constraint definition...But I have a table column defined as follows:[MONTH] [decimal] (2, 0) NOT NULL CONSTRAINT[DF__TBLNAME__MONTH__216361A7] DEFAULT (0)My question: Is "DEFAULT" a constraint, or is it called something else?Thanks,Eric

View 2 Replies View Related

Default And Check Constraint Value

Jul 26, 2004

Hi,
I need list out the defaulat and constraint value in SQL2K. Where I get those values.
Thanks,
Ravi

View 3 Replies View Related

Changing A BIT To An INT Where There's A CONSTRAINT And A DEFAULT

Jan 2, 2007

A few weeks ago a client asked me to add a column to a table so Icreated this script:ALTER TABLE dbo.tblIndividual ADD fldRenewalStatus BIT NOT NULLCONSTRAINT fldRenewalStatus_Default DEFAULT 0Now they want to change it from a BIT to an INT, to store an enum.Fair enough. However, no matter how much I wrangle with a script, Ican't find a reliable way to alter the column. I've mixed and matchedthe following and nothing seems to work:EXEC sp_unbindefault 'tblIndividual.fldRenewalStatus'DROP DEFAULT DF_tblIndividual_fldRenewalStatusALTER TABLE tblIndividualDROP CONSTRAINT fldRenewalStatus_DefaultALTER TABLE tblIndividualDROP COLUMN fldRenewalStatusGOALTER TABLE tblIndividualADD fldRenewalStatus int NOT NULLCONSTRAINT fldRenewalStatus_Default DEFAULT 0Thoughts?ThanksEdward

View 4 Replies View Related

Default Constraint Problem

Apr 16, 2008

Hello,

I have a table set up called tbl_DailySummary_new. In that table I have a column called €˜RevType€™ char(2) NOT NULL Default €˜00€™. I'm trying to populate this table from another table called tbl_DailySummary. The RevType column in tbl_DailySummary allows null values (and has them). When I attempt to insert all records from tbl_dailysummary into tbl_DailySummary_new, I get the following error message:


Msg 515, Level 16, State 2, Line 1

Cannot insert the value NULL into column 'RevType', table 'TxnRptg.dbo.tbl_DailySummary_new'; column does not allow nulls. INSERT fails.

The statement has been terminated.


Why dosen€™t the default constraint on the RevType column in the new table pick this up?

Thank you for your help!

cdun2

View 2 Replies View Related

Default Constraint Problem

May 20, 2008



Hi ,

I want to define default constraint for a column to force it to UPPER.

USE [GLP]
GO
ALTER TABLE [dbo].[col1] ADD CONSTRAINT [DF_col1_TypeCode] DEFAULT (N'UPPER(col1)') FOR [col1]. Its defined..

But when I tried ti insert into records..It not convertedto uppecase at all...Isn't it possible this way ?

Thanks,
-V

View 3 Replies View Related

Restoring A Default Constraint

Apr 28, 2008

Troops,

I'm a software developer trying to hack my way thru a SQL script to increase the size of a column. The column has a constraint on it that won't allow the alter unless its dropped.

Alter command:
ALTER TABLE dbo.QueueBack ALTER Column QBQueue varchar(4) NOT NULL

Message response:
Msg 5074, Level 16, State 1, Line 10
The object 'DF__QueueBack__QBQue__76818E95' is dependent on column 'QBQueue'.
Msg 4922, Level 16, State 9, Line 10
ALTER TABLE ALTER COLUMN QBQueue failed because one or more objects access this column.


So, my script drops the default constraint, alters the column size and then adds the constraint back. The problem is that the constraint does NOT appear to be the same as it was prior. I can run the Alter command on the column and it will allow me to change the size of the column... where it prohibited me from doing such before. How do I restore the default constraint so it is exactly the way it was before I dropped it?

Thx,

Stretch

---------------------------------

Script for drop, alter, add... modified slightly for simplicity...

declare @Error int

BEGIN TRAN
SELECT @Error = 0

DECLARE @defname VARCHAR(100), @cmd VARCHAR(1000)

-- this is retrieved at run time from the sysconstraints table; hard-coded here...
set @defname = 'DF__QueueBack__QBCategory'

IF @defname <> ''
BEGIN
SET @cmd = 'ALTER TABLE dbo.QueueBack DROP CONSTRAINT '+ @defname
EXEC(@cmd)

if @@ERROR = -1
BEGIN
SET @Error = -1
END
END

if @Error = 0
BEGIN
-- modify the column
ALTER TABLE dbo.QueueBack ALTER Column QBCategory varchar(7) NOT NULL

if @@ERROR = -1
BEGIN
SET @Error = -1
END
END

if @Error = 0
BEGIN
-- Add the default constraint back
SET @cmd = 'ALTER TABLE dbo.QueueBack ADD CONSTRAINT '+ @defname + ' DEFAULT ('''') FOR QBCategory'
EXEC(@cmd)

if @@ERROR = -1
BEGIN
SET @Error = -1
END
END


if @Error = 0
BEGIN
-- Commit if no error...
COMMIT TRAN
END
ELSE
BEGIN
-- Rollback if error...
ROLLBACK TRAN
END

GO

View 1 Replies View Related

Read And Write A Constraint Or Default Value

Nov 20, 2007

Okay, maybe I'm getting ahead of myself.
Using SQL Server Express, VWD and .net 2.0 I've figured out how to drop a Table Column Constraint or Default Value/Binding and then Create it again using a stored procedure. What I can't figure out is how to retrieve that column's constraint value and write it to, say a label, in an aspx page, simply for reference. Is it possible? In this case the Data Type of the column is money.
I'm using it to perform a calculation to a column with a value that the user inserts into another column. (Column1(user input) minus Column2(with Default Value) = Column3(Difference). I just want to read Column2's Default Value for reference so I know whether to change it or not.

View 6 Replies View Related

Alter Column With Default Constraint

Dec 7, 2001

I can't seem to get the syntax correct for ALTERing an existing column with a default constraint. I've been to Help and BOL. There are examples that show how to use the ALTER command to add a column with a default constraint but not how to do it on an existing column.

Any help would be appreciated.

Sidney Ives

View 1 Replies View Related

How To Tell SQL Server To Use The Default Constraint Name When Adding One?

Oct 26, 2005

Hi guys,

I have this problem. I want to add a new primary key to a table but i want the name of the contstraint to be generated by the system. I have this TSQL code.


ALTER TABLE TableTest
ADD CONSTRAINT PRIMARY KEY (C1)


Reading the BOL, it says that if you don't supply a name for the constraint it generates one. But I get this error "Incorrect syntax near the keyword 'PRIMARY'".

If I add a name to the constraint, it works fine.
I'm using SQL Server 2000

Thanks
Darkneon

View 7 Replies View Related

Convert Function In Default Constraint

Aug 23, 2006

I have two fields CourseID and Erpid in table.

CourseID has identity property with integer datatype.

I need to add a default value for Erpid column which will show a value like 'A' + CourseID column. Erpid is Varchar column.

How can I use Convert function in default constraint?

Thanks!

View 4 Replies View Related

Alter A Default Constraint In A Table

Jun 12, 2007

I have a default constratint on DateColumn getdate()-1

I have used enterprise manager to update it to yesterday's date everyday.

I would like to have a SQL which can check for the date in the system
or even a trigger which checks when the date changes the constraint is updated itself. If this is not possible I would like to have a stored procedure which I will schedule to run as a job everyday once.

So if today 6/12/2006, the default value in the Datecolumn should be
6/11/2006.

This gives me a error, i tried but could not fix the bug.

Alter Table TABLE_NAME
Alter Constraint DF_DATECOLUMN
Default getdate()-1

Ashley Rhodes

View 4 Replies View Related

Adding A Default Constraint To An Existing Column

Mar 9, 2000

I cannot figure out how to add a default constraint to an existing column. The syntax I'm using is :

ALTER TABLE table_name WITH NOCHECK
ADD CONSTRAINT column_name DEFAULT (0)

This gives me a syntax error.

The column was originally added with a default constraint of 1 to a 2.6 million row table.
I dropped the existing constraint and need to add the new default constraint of 0 for that column.

Anyone have any ideas? Thanks in advance.

View 2 Replies View Related

Alter Column Datatype With Default Constraint

Mar 16, 2004

I need to alter the datatype of a column from smallint to decimal (14,2) but the column was originally created with the following:

alter my_table
add col_1 smallintNot Null
constraint df_my_table__col_1 default 0
go

I want to keep the default constraint, but i get errors when I try to do the following to alter the datatype:

alter table my_table
alter column col_1 decimal(14,2)Not Null
go

Do I need to drop the constraint before I alter the column and then rebuild the constraint? An example would be helpful.

Thx

View 1 Replies View Related

SQL 2012 :: Property Test Is Not Available For Default Constraint

Sep 9, 2014

What are the tables are having the Default Constraint those table's Script the User can't generate but remaining tables He/She can generate,If i want DENY he/she to do not generate the script those are not having the DF Constraints what should i do.....

View 1 Replies View Related

Transact SQL :: Delete A Default Constraint On A Column?

May 5, 2015

 I have a table named [New Item] and created a default constraint on a column, and i wanted to change the data type of the column using the query

alter table [new item]
alter column pcs_qty decimal(15,2) not null

but the name of the default constraint is 'DF__New Item__Pcs_Qt__2D12A970' and i am not able to delete the constraint because it contains a space in between.Is there any work around for this.

I tried to delete the constraint by using the query

alter table [new item]
drop constraint 'DF__New Item__Pcs_Qt__2D12A970'

but I am getting the exception,

Msg 102, Level 15, State 1, Line 2

Incorrect syntax near 'DF__New Item__Pcs_Qt__2D12A970'.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved