How to add null value to table field

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

      

how to add non null to table as well as foreign key

+2


source to share


1 answer


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, you can do (syntax for SQL Server 2005 and above):

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"? Which column? Which other table and column?

Check out some of these basic SQL tutorials first: they need to get started:

Mark

+7


source







All Articles