views:

129

answers:

1
create table re(id numeric(1),bin varchar(10))

how to add not null on table as well as foreign key

+6  A: 

Just add "NOT NULL" to all the columns you want to prevent from being NULL:

create table re(id numeric(1) NOT NULL,
bin varchar(10) NOT NULL)

If you want to change it later on, you can do (syntax for SQL Server 2005 and up):

ALTER TABLE re
  ALTER COLUMN id NUMERIC(1) NOT NULL

ALTER TABLE re
  ALTER COLUMN bin VARCHAR(10) NOT NULL

What do you mean by "foreign key" ? On which column ? To which other table and column ?

Check out some of these basic SQL tutorials first - they should get you started:

Marc

marc_s
If I did help you - why don't you accept my answer? Click on the big "checkmark" to the left of the question. Helps you get a good reputation, too!
marc_s
Begging for rep is so undignified, @marc_s :-)
paxdiablo
@pax: yes, but efficient :-)
marc_s
and I'm trying to educate "domnic" as to how to successfully use and behave on SO :-) You should thank me for that :-)
marc_s
+1 for for your "au contraire", it's a good point you raise about education.
paxdiablo