Article View: cn.bbs.comp.database
Article #8252Some useful SQLs when playing around with Or...(ת��)
From: 99SE.Eric.Hsu.��̹ܿ�
Date: Fri, 05 Dec 2003 07:14
Date: Fri, 05 Dec 2003 07:14
62 lines
2928 bytes
2928 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;37m�� ת��:���Ұ��Ͽ�վ bbs.nankai.edu.cn��[FROM: 202.113.30.24][m
Technical Details
Message-ID:
<49WXcc$Z0A@bbs.nankai.edu.cn>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!167.206.3.103.MISMATCH!news3.optonline.net!maily.cic.tsinghua.edu.cn!news.happynet.org!NanKaiShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 101948,d06515f1d98dc89e,start X-Google-Attributes: gid101948,public X-Google-ArrivalTime: 2003-12-04 23:15:58 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!167.206.3.103.MISMATCH!news3.optonline.net!maily.cic.tsinghua.edu.cn!news.happynet.org!NanKai From: OtherVoices.bbs@bbs.nankai.edu.cn (99SE.Eric.Hsu.��̹ܿ�) Newsgroups: cn.bbs.comp.database Subject: Some useful SQLs when playing around with Or...(ת��) Date: 05 Dec 2003 07:14:14 GMT Organization: �Ұ��Ͽ�վ Message-ID: <49WXcc$Z0A@bbs.nankai.edu.cn> X-Filename: Database/M.1070608454.A Lines: 62