Professional Documents
Culture Documents
Java - Unit 8 Solutions
Java - Unit 8 Solutions
1.
CREATE TABLE [dbo].[test3](
[name] [varchar](20) NULL,
[ssn] [char](9) NULL,
[dept_number] [int] NULL,
[acct_balance] [smallmoney] NULL
) ON [PRIMARY]
GO
INSERT test3(name,ssn,dept_number,acct_balance)
VALUES ('xx','yy',2,5),
('xx','yyy',200000000,5),
('xx','yyyy',2,1234567.89)
Gives
Msg 8115, Level 16, State 4, Line 1
Arithmetic overflow error converting numeric to data type smallmoney.
The statement has been terminated.
INSERT test3(name,ssn,dept_number,acct_balance)
VALUES ('xx','yy',2,5),
('xx','yyy',200000000,5),
('xx','yyyy',2,567.89)
GIVES
(3 row(s) affected)
2.
a.
Yes the ssn takes nulls, in order to correct this you would add a contraint of
not null
b. Yes the ssn allows duplicates, in order to prevent this you would add a constraint of
duplicates not allowed.
CREATE TABLE [dbo].[Test2](
[name] [varchar](20) NULL,
[ssn] [char](9) NOT NULL,
[dept_number] [int] NULL,
[acct_balance] [smallmoney] NULL
) ON [PRIMARY]
c. You cannot set a primary key on a table with nulls or duplicates Drop or recreate the table
then alter
d. You can put values in both the acct_balance and dept_number column however once
the constraint is added you cannot.