Connecting Tech Pros Worldwide Help | Site Map

sql queries

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 18th, 2008, 09:55 AM
mo/-/sin
Guest
 
Posts: n/a
Default sql queries

i made a table and there is a column name departmentid(this is the
primary key) and there is one another column name department name... i
want that this column should not accept the same value... i mean to
say that every row in this column should be unique. how can i do
this.......

  #2  
Old August 18th, 2008, 12:05 PM
Philipp Post
Guest
 
Posts: n/a
Default Re: sql queries

This is done by creating a UNIQUE constraint on department_name

CREATE TABLE Departments
(department_id NOT NULL PRIMARY KEY,
department_name NOT NULL UNIQUE)

brgds

Philipp Post

  #3  
Old August 18th, 2008, 12:15 PM
Philipp Post
Guest
 
Posts: n/a
Default Re: sql queries

well, and do not forget the datatype:

CREATE TABLE Departments
(department_id INTEGER NOT NULL PRIMARY KEY,
department_name VARCHAR(30) NOT NULL UNIQUE)

brgds

Philipp POst
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.