Connecting Tech Pros Worldwide Forums | Help | Site Map

sql queries

mo/-/sin
Guest
 
Posts: n/a
#1: Aug 18 '08
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.......

Philipp Post
Guest
 
Posts: n/a
#2: Aug 18 '08

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

Philipp Post
Guest
 
Posts: n/a
#3: Aug 18 '08

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
Closed Thread