Article View: cn.bbs.comp.database
Article #8253Some useful SQLs when playing around with Or...(ת��)
From: �������ƣ���ˮ����
Date: Fri, 05 Dec 2003 07:14
Date: Fri, 05 Dec 2003 07:14
62 lines
2904 bytes
2904 bytes
[1;37m�� ��������ת���� [32mHomepage [37m������ ��
�� ԭ����[32m OtherVoices[37m ��� ��[m
03.12.01.18:38.Eric
03.11.27.20:45.Eric
-- For oracle
-- Describe a table's structure
DESC tablename
-- Alter table name
RENAME oldtablename TO newtablename
-- Add new column
ALTER TABLE atable ADD (newcolumn varchar(128))
-- Alter table column name
ALTER TABLE atable RENAME COLUMN oldcolumnname TO newcolumnname
-- Modify table column datatype
-- - Assume the table "atable" has a column "acolumn" which is
-- - VARCHAR2(10), the following command will change it to VA-
-- - CHAR(20)
ALTER TABLE atable MODIFY (acolumn VARCHAR2(20))
-- Add FK contraint
ALTER TABLE material
add CONSTRAINT FK_MATERIAL_RELATIONS_DIFF
FOREIGN KEY(difficultycode)
REFERENCES difficulty (difficultycode)
-- Create a column equivalent to MySQL's AUTOINCREATMENT column
-- - Assume that we have a table "user" with two columns:
-- - USERID
-- - USERNAME
-- - First create a sequence
CREATE SEQUENCE seq_userid
START WITH [n]
-- Then create the trigger to "auto increase" the userid
CREATE TRIGGER trg_user_insert
BEFORE INSERT ON user
FOR EACH ROW
BEGIN
IF :new.userid IS NULL THEN
SELECT seq_userid.NEXTVAL INTO :new.userid FROM DUAL;
END IF;
END;
-- Set the Date column to get system date automatically
alter table atable modify (adatecolumn date default SYSDATE)
--
Nothing is easy in fact
Nothing is complicated indeed
- 03.10.05.19:21.Eric
[m[1;37m�� ��Դ:���Ұ��Ͽ�վ bbs.nankai.edu.cn��[FROM: 202.113.30.24][m --
[m[1;34m�� ת��:���Ұ��Ͽ�վ bbs.nankai.edu.cn��[FROM: 202.113.30.162][m
Technical Details
Message-ID:
<49WXdO$ZSB@bbs.nankai.edu.cn>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.webusenet.com!news.bylinux.net!news.ccie.net.cn!news.happynet.org!NanKaiShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 101948,d06515f1d98dc89e X-Google-Attributes: gid101948,public X-Google-ArrivalTime: 2003-12-04 23:15:59 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.webusenet.com!news.bylinux.net!news.ccie.net.cn!news.happynet.org!NanKai From: wilton.bbs@bbs.nankai.edu.cn (�������ƣ���ˮ����) Newsgroups: cn.bbs.comp.database Subject: Some useful SQLs when playing around with Or...(ת��) Date: 05 Dec 2003 07:14:48 GMT Organization: �Ұ��Ͽ�վ Message-ID: <49WXdO$ZSB@bbs.nankai.edu.cn> X-Filename: Database/M.1070608488.A Lines: 62