firebird学习笔记

firebird学习笔记

firebird学习笔记
firebird默认的用户名:SYSDBA 密码:masterkey

开源的Firebird的可视化管理工具Marathon
flameRobin也量个开源的可视化管理工具
1、创建表
CREATE TABLE table_name
(
    column_name {< datatype> | COMPUTED BY (< expr>) | domain}
        [DEFAULT { literal | NULL | USER}] [NOT NULL]
    ...
    CONSTRAINT constraint_name
        PRIMARY KEY (column_list),
        UNIQUE      (column_list),
        FOREIGN KEY (column_list) REFERENCES other_table (column_list),
        CHECK       (condition),
    ...
);

如:create table t1
(
   sno1 char(9) primary key,
   sno2 char(9) references student(sno)  
)
2、修改表
(1)增加字段
alter table table_name add fieldname datetype [not null ,primary key]
如:alter table student add sex char(2) not null
   primary key
   default 'm'
   CHECK (sex1='f' or sex1='m')

ALTER TABLE STUDENT
ADD AGE INTEGER[1:100]
DEFAULT 56
CHECK (age between 20 and 35)

ALTER TABLE STUDENT
ADD AGE INTEGER[1:100]
DEFAULT 56
CHECK (age>=20 and age<=35)
(2)删除字段
alter table table_name drop fieldname
ALTER TABLE STUDENT DROP AA
(3)增加主键
alter table SCORE
add constraint PK_SCORE_1
primary key (ID, CORUSENAME)
////////////////////////////////////////////////////////////////////////////
查询:
SELECT [TRANSACTION transaction]
[DISTINCT | ALL]
{* | [, …]}
[INTO :var [, :var …]]
FROM [, …]
[WHERE ]
[GROUP BY col [COLLATE collation] [, col [COLLATE collation] …]
[HAVING ]
[UNION [ALL]]
[PLAN ]
[ORDER BY ]
[FOR UPDATE [OF col [, col …]]];

在表上增加外键
alter table STUDENT
add constraint FK_STUDENT_1
foreign key (ID)
references SCORE (ID)
///////////////////////////////////////////////////////////////////////
创建域:
CREATE DOMAIN domain [AS]
[DEFAULT {literal | NULL | USER}]
[NOT NULL] [CHECK ()]
[COLLATE collation];
如:
(1)create domain MyScore as SMALLINT
default 0
check(value between 0 and 100)
(2)CREATE DOMAIN DEPTNO AS CHAR(3)
   CHECK ((VALUE = '000') OR
   (VALUE > '0' AND VALUE <= '999')
   OR (VALUE IS NULL))
修改域:
ALTER DOMAIN name {
SET DEFAULT {literal | NULL | USER}
| DROP DEFAULT
| ADD [CONSTRAINT] CHECK ()
| DROP CONSTRAINT | new_col_name

| TYPE datatype};
如:
(1)alter DOMAIN DAGE TYPE INTEGER
(2)alter DOMAIN DAGE TYPE INTEGER
set DEFAULT 40
add constraint CHECK (value between 10 and 90)
(3)alter DOMAIN DAGE TYPE INTEGER
drop   CONSTRAINT
(4)CREATE DOMAIN prodtype
    AS VARCHAR(12)
    DEFAULT 'software' NOT NULL
    CHECK (VALUE IN ('software', 'hardware', 'other', 'N/A'));
问题:不知道{USER}是什么意思,怎么用?

连接到数据:
CONNECT 'filespec' [USER 'username'][PASSWORD 'password']
[CACHE int] [ROLE 'rolename']
如:
connect g:\firebird\test.fdb user 'sysdba' password 'masterkey';//一定要加上‘;’以表示sql语句结束。

创建索引:
CREATE [UNIQUE] [ASC[ENDING] | DESC[ENDING]] INDEX index
ON table (col [, col …]);
创建视图:
CREATE VIEW name [(view_col [, view_col …])]
AS

转载于:https://www.cnblogs.com/figo-10/archive/2009/01/04/1368440.html

你可能感兴趣的:(python)