SQL Not Null Constraint
6.What is the output of the given code?
CREATE TABLE items (
name VARCHAR(20),
price INT NOT NULL
);
INSERT INTO items(name) VALUES ('Bag');
-
A. price = 0
-
B. Error
-
C. price = NULL
-
D. price = default
Error
Error
7.What will happen?
CREATE TABLE data (
id INT,
info VARCHAR(50) NOT NULL
);
INSERT INTO data VALUES (1, NULL);
-
A. Row inserted
-
B. NULL accepted
-
C. Error due to NOT NULL
-
D. info = empty string
Error due to NOT NULL
Error due to NOT NULL
8.What is the default behavior of columns if NOT NULL is not specified?
-
A. They accept NULL
-
B. They must have values
-
C. They are PRIMARY
-
D. They are indexed
They accept NULL
They accept NULL
9.Which statement makes name column NOT NULL?
-
A. ALTER TABLE students MODIFY name NOT NULL;
-
B. ALTER TABLE students ADD NOT NULL name;
-
C. CHANGE name SET NOT NULL;
-
D. UPDATE TABLE SET NOT NULL name;
ALTER TABLE students MODIFY name NOT NULL;
ALTER TABLE students MODIFY name NOT NULL;
10.Guess the correct output.
CREATE TABLE test (
x INT NOT NULL DEFAULT 5
);
INSERT INTO test VALUES ();
-
A. NULL inserted
-
B. 0 inserted
-
C. 5 inserted
-
D. Error
5 inserted
5 inserted