5月15日夜のデータベースの復習

1769 ワード

//ネーミングに対して、学校の先生がやっています。超ゴミのようです。
create database DBS

use DBS

create table    
(YXBH CHAR(8) PRIMARY KEY CLUSTERED,--    
YXMC CHAR(20) NOT NULL,--    
YXZR CHAR(8) --    
)

CREATE TABLE    
(
XH CHAR(7)
CONSTRAINT PK_XH PRIMARY KEY NONCLUSTERED,--  
XM CHAR(20) NOT NULL,--  
sfz char(18) unique nonclustered,--   
yxbh char(8) references     --    ,  
)

create table    
(
kch char(3) constraint pk_kch primary key,
kcm char(20)
)
go

create table    
(
jsh char(5) constraint pk_jsh primary key,
jsm char(20)
)
go

create table    
(
xh char(7)--  
constraint pk_xh primary key nonclustered,
xm char(20) not null,
sfz char(18) unique nonclustered, --   
yxbh char(8) foreign key(yxbh) references    
)

create table    
(
xh char(7)  
constraint xh primary key nonclustered,
xm char(20) not null,
sfz char(18) unique nonclustered,
yxbh char(8) constraint fk_yxbh foreign key(yxbh) references    
)

create table    
(
xh char(7) references    ,--  
kch char(3) references    ,--   
cj int default 0 check (cj >= 0and cj <= 10),--  
jsh char(5) references    --   
constraint pk_cj primary key(xh,kch)--  
)

select * from    
--        
alter table     add column_b varchar(20) null
--            
alter table     add column_b varchar(20) null constraint b_unique unique
--       
alter table     drop column column_b
delete from     where column = 'column_b'