标签:val foreign tab database column varchar str mod null
3.学会命令行管理代码
大航海时代1:世界的创建
--------------表的操作:海贼王世界
CREATE DATABASE ONE_PIECE
DROP DATABASE ONE_PIECE
CREATE TABLE ROLE(
ID INT IDENTITY(1,1) ,
NAME VARCHAR(20),
AGE INT ,
REWARD INT
)
CREATE TABLE AREA(
ID INT IDENTITY(1,1),
NAME VARCHAR(20),
REMARK TEXT,
)
SP_RENAME ‘AREA1‘ , ‘AREA‘
DROP TABLE AREA
INSERT INTO ROLE(NAME , AGE , REWARD ) VALUES(‘lu.fei‘ , 20 , 5 );
select * from ROLE ;
delete from ROLE;
ALTER TABLE ROLE DROP COLUMN AREA_ID;
ALTER TABLE ROLE ADD AREA_ID INT;
ALTER TABLE ROLE MODIFY AREA_ID BIGINT;
-----------2.SQL 约束
/*
1.NOT NULL
2.UNIQUE
3.PRIMARY KEY :拥有自动定义的 UNIQUE 约束
4.FOREIGN KEY :一个表中的 FOREIGN KEY 指向另一个表中的 PRIMARY KEY。
5.CHECK CHECK 约束用于限制列中的值的范围。
6.DEFAULT DEFAULT 约束用于向列中插入默认值
*/
1.ALTER TABLE ROLE MODIFY NAME NOT NULL
2.ALTER TABLE ROLE ADD UNIQUE( NAME)
ALTER TABLE ROLE ADD CONSTRAINT UC_PERSON UNIQUE( NAME , AGE )
ALTER TABLE ROLE DROP CONSTRAINT UC_PERSON
3.ALTER TABLE ROLE ADD PRIMARY KEY( ID )
ALTER TABLE ROLE ADD CONSTRAINT PK_PERSON PRIMARY KEY ( ID ,NAME )
ALTER TABLE ROLE DROP CONSTRAINT PK_PERSON
4.ALTER TABLE ROLE ADD FOREIGN KEY (AREA_ID) REFERENCES AREA(ID)
ALTER TABLE ROLE ADD CONSTRAINT fk_PerOrders FOREIGN KEY (AREA_ID) REFERENCES AREA(ID)
ALTER TABLE ROLE DROP CONSTRAINT fk_PerOrders
5.ALTER TABLE ROLE ADD CHECK (AGE<30)
ALTER TABLE ROLE ADD CONSTRAINT chk_Person CHECK (AGE<30 AND NAME IS NOT NULL)
ALTER TABLE ROLE DROP CONSTRAINT chk_Person
INSERT INTO ROLE(AGE , NAME ) VALUES( 5,‘yai si ‘)
--6
ALTER TABLE ROLE ALTER COLUMN REWARD SET DEFAULT ‘not find‘
ALTER TABLE ROLE ALTER COLUMN REWARD DROP DEFAULT
------------3.索引
标签:val foreign tab database column varchar str mod null
原文地址:http://www.cnblogs.com/0to9/p/6063933.html