title: Check constraint in SQL Server 2008
body: <p>Please, I just starting to learn SQL and got stuck. I'm trying to build a database for my test project, I've created some tables, did the relations, defined primary and foreign keys.....all of this in SQL Server 2008 through Visual interface (table design/edit), no statement coding (didn't get there yet, but I will :) ).   </p>
  
  <p>I have a column <code>Tax</code> in a table called <code>Orders</code> and I did my homework and found that it's best to use a <code>decimal</code> data type (I used decimal(5, 2)) with a <code>CHECK</code> constraint. </p>
  
  <p>So I right clicked the column -> constraints and in expression I typed </p>
  
  <pre><code>([TAX] &gt;= (0.00) AND [TAX] &lt;= (100.00))
  </code></pre>
  
  <p>My values exceed the check constraint, I can type 123456.0999 and I get 1234560999 in the table, and if I type 2.5 I get 25..... so a <strong>CHECK CONSTRAINT</strong> is not working what it should???  </p>
  
  <p>Please help</p>
  
  <hr>
  
  <p><strong>EDIT:  Here is the create script off my table</strong></p>
  
  <pre><code>    USE [MyCompany]
  GO
  
  /****** Object:  Table [dbo].[Orders]    Script Date: 03/22/2013 11:33:24 ******/
  SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  CREATE TABLE [dbo].[Orders](
      [OrderID] [int] IDENTITY(1,1) NOT NULL,
      [OrderDateTime] [smalldatetime] NOT NULL,
      [CustomerID] [int] NOT NULL,
      [Tax] [decimal](5, 2) NULL,
      [Shipping] [decimal](7, 3) NOT NULL,
   CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED 
  (
      [OrderID] 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
  
  ALTER TABLE [dbo].[Orders]  WITH CHECK ADD  CONSTRAINT [FK_Orders_Customers] FOREIGN KEY([CustomerID])
  REFERENCES [dbo].[Customers] ([CustomerID])
  GO
  
  ALTER TABLE [dbo].[Orders] CHECK CONSTRAINT [FK_Orders_Customers]
  GO
  
  ALTER TABLE [dbo].[Orders]  WITH CHECK ADD  CONSTRAINT [CK_Orders_Tax] CHECK  (([Tax]&gt;=(0.0) AND [Tax]&lt;=(100.0)))
  GO
  
  ALTER TABLE [dbo].[Orders] CHECK CONSTRAINT [CK_Orders_Tax]
  GO
  </code></pre>