I wanna create a table in SQL, and if the I wanna set the attributes to NULL, how do I do it?
For example, I wanna create a table named Courses and its attributes “CourseNo” and “Title” must not be null. I created one below:
CREATE TABLE Courses(
CourseNo INTEGER CHECK(100<=CourseNo<=999) PRIMARY KEY,
Title VARCHAR(100),
)
ALTER TABLE Courses
ALTER COLUMN CourseNo INTEGER NOT NULL
ALTER COLUMN Title VARCHAR(100) NOT NULL
Is this correct?
whatever you wrote that one correct but good practice is to write
not nullat a time of defining table.do like this:
primary key is by default
NOT NULLalways, hence you no need to declare it asNOT NULLNOT NULLin alter is used when u want to make change in column definations of table later