473,411 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

sql date contraints

Hi,

I was wondering how to do this.

I have a table with two columns in design view (start date, end date).

How do I set it within sql server (as constraint) or whatever that the
start date less than or equal to end date?

Thanks

:DHRUV
Jul 20 '05 #1
5 4780
On 15 Jun 2004 14:07:05 -0700, Dhruv wrote:
Hi,

I was wondering how to do this.

I have a table with two columns in design view (start date, end date).

How do I set it within sql server (as constraint) or whatever that the
start date less than or equal to end date?

Thanks

:DHRUV


Hi Dhruv,
Use a CHECK contraint:

CREATE TABLE MyTest (PK int not null primary key,
StartDate datetime not null,
EndDate datetime,
CONSTRAINT Date_CK CHECK (StartDate < EndDate))
(untested)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
[posted and mailed, please reply in news]

Dhruv (dm**********@yahoo.com) writes:
I was wondering how to do this.

I have a table with two columns in design view (start date, end date).

How do I set it within sql server (as constraint) or whatever that the
start date less than or equal to end date?


CREATE TABLE hoppla (a int NOT NULL,
startdate datetime NOT NULL,
enddate datetime NULL,
CONSTRAINT pk_hoppla PRIMARY KEY (a),
CONSTRAINT ckt_dates CHECK (startdate <= endddate))

Note: this is a command to run in Query Analyzer. I guess that with
"design view" you mean something in Enterprise Manager, but I don't
use that, so I don't know you add a constraint this way.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
Thanks a lot,

what about if the table was already created, can you update a table
with a constraint??

:D

Erland Sommarskog <es****@sommarskog.se> wrote in message news:<Xn********************@127.0.0.1>...
[posted and mailed, please reply in news]

Dhruv (dm**********@yahoo.com) writes:
I was wondering how to do this.

I have a table with two columns in design view (start date, end date).

How do I set it within sql server (as constraint) or whatever that the
start date less than or equal to end date?


CREATE TABLE hoppla (a int NOT NULL,
startdate datetime NOT NULL,
enddate datetime NULL,
CONSTRAINT pk_hoppla PRIMARY KEY (a),
CONSTRAINT ckt_dates CHECK (startdate <= endddate))

Note: this is a command to run in Query Analyzer. I guess that with
"design view" you mean something in Enterprise Manager, but I don't
use that, so I don't know you add a constraint this way.

Jul 20 '05 #4
Dhruv (dm**********@yahoo.com) writes:
what about if the table was already created, can you update a table
with a constraint??


Yes, you can use the ALTER TABLE statement. Check Books Online for
details.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5
dm**********@yahoo.com (Dhruv) wrote in message news:<b6*************************@posting.google.c om>...
Thanks a lot,

what about if the table was already created, can you update a table
with a constraint??

:D


alter table hoppla add constraint ckt_dates CHECK (startdate <= endddate)

Simon
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
8
by: Stuart McGraw | last post by:
Is Microsoft full of #*$#*% (again) or am I badly misunderstanding something? Quote from Microsoft's T-SQL doc: > INSTEAD OF triggers are executed instead of the triggering action. > These...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
5
by: m_t_hill | last post by:
Running MS Access 2000 MS Windows XP Pro This has caused me a lot of hair loss in the last few days so would appreciate any help. I am running code to append/update a local access database...
1
by: awebguynow | last post by:
I've seen the syntax in the J. Stephens/C. Russell book and believe the "alter table" would be: ALTER TABLE tbl FOREIGN KEY (column_list) REFERENCES tbl_name (column_list) the Syntax is...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
2
by: paragpdoke | last post by:
Hello Everyone. I'm new to XML and was trying to get my first DTD configured. I could not find an example of a constraint on the value of a node using the DTD. I'm trying to build a very simple...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.