先表后约束: ALTER TABLE Persons MODIFY Age int NOT NULL; ALTER TABLE Persons MODIFY City DEFAULT 'SANDNES'; ALTER TABLE Persons ADD CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName); ALTER TABLE Persons ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName); ALTER TABLE Persons ADD CONSTRAINT chk_Person CHECK (P_Id>0 AND City='Sandnes'); ALTER TABLE Orders ADD CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id);
删除约束: ALTER TABLE Persons MODIFY Age int NULL; ALTER TABLE Persons ALTER COLUMN City DROP DEFAULT; ALTER TABLE Persons DROP CONSTRAINT uc_PersonID; ALTER TABLE Persons DROP CONSTRAINT pk_PersonID; ALTER TABLE Persons DROP CONSTRAINT chk_Person; ALTER TABLE Orders DROP CONSTRAINT fk_PerOrders;
序列
1 2 3 4 5
CREATE SEQUENCE seq_person MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10 上面的代码创建一个名为seq_person的sequence对象,它以1起始且以1递增。该对象缓存10个值以提高性能。cache规定了为了提高访问速度要存储多少个序列值。
SELECT Websites.name, Websites.url, SUM(access_log.count) AS nums FROM access_log INNER JOIN Websites ON access_log.site_id=Websites.id) GROUP BY Websites.name HAVING SUM(access_log.count) > 200;
UCASE()函数
此函数把字段的值转换为大写。
1
SELECT UCASE(name) AS site_title, url FROM Websites;
LCASE()函数
此函数把字段的值转换为小写。
1
SELECT LCASE(name) AS site_title, url FROM Websites;
LEN()函数
此函数返回文本字段中值的长度。
1
SELECT name, LENGTH(url) as LengthOfURL FROM Websites;