Firebird common SQL

Source: Internet
Author: User

I. Paging syntax example:
Select first 10 templateid, code, name from template;
Select first 10 skip 10 templateid, code, name from template;
Select * from shop rows 1 to 10; -- firebird2.0 supports this method

Ii. Show
Show tables;
Show table tablename;
III,
D: \ firebird2 \ bin> iSQL-u sysdba-P masterkey
Connect "E: \ company \ xmwsoft \ newxmwsoft \ C2 \ dB \ cts2.fdb ";
Iv. -- Update field comments
Update RDB $ relation_fields
Set RDB $ description = 'descriptive information'
Where (RDB $ relation_name = 'shop ') and
(RDB $ field_name = 'credit _ buy ')

V. -- display field comments
Select RDB $ field_name, RDB $ description from RDB $ relation_fields
Where (RDB $ relation_name = 'shop ')
And
(RDB $ field_name = 'credit _ buy ')

Vi. -- Update Table Comments
Update RDB $ relations set RDB $ description = 'descriptive information' where RDB $ relation_name = 'table _ name'

VII. -- Query all tables and views (including system tables and system views)
Select RDB $ relation_name from RDB $ relations;

8. -- Query all user tables and user views
Select RDB $ relation_name from RDB $ relations where RDB $ system_flag = 0;

9. -- Query all user tables
Select RDB $ relation_name from RDB $ relations where RDB $ system_flag = 0 and RDB $ view_blr is null

10. query all fields and definitions in all user tables and user views
Select a. RDB $ relation_name, B. RDB $ field_name, B. RDB $ field_id, D. RDB $ type_name,
C. RDB $ field_length, C. RDB $ field_scale
From RDB $ relations
Inner join RDB $ relation_fields B
On a. RDB $ relation_name = B. RDB $ relation_name
Inner join RDB $ fields C
On B. RDB $ field_source = C. RDB $ field_name
Inner join RDB $ TYPES D
On C. RDB $ field_type = D. RDB $ type
Where a. RDB $ system_flag = 0
And D. RDB $ field_name = 'rdb $ field_type'
Order by A. RDB $ relation_name, B. RDB $ field_id
11. Search for all fields and definitions of a table
Select a. RDB $ field_name, B. RDB $ field_type, B. RDB $ field_length, B. RDB $ field_precision, B. RDB $ field_scale
From RDB $ relation_fields A, RDB $ fields B
Where a. RDB $ relation_name = 'tablename'
And a. RDB $ field_source = B. RDB $ field_name
Order by A. RDB $ field_position
12. Search for the primary key definition field of a table
Select a. RDB $ field_name from RDB $ index_segments A, RDB $ relation_constraints B
Where B. RDB $ constraint_type = 'Primary key'
And B. RDB $ relation_name = 'tablename'
And a. RDB $ index_name = B. RDB $ index_name
Order by A. RDB $ field_position
XIII. Search for the foreign key definition of a table
Select r1.rdb $ constraint_name, rind. RDB $ field_name, r2.rdb $ relation_name
From RDB $ relation_constraints R1, RDB $ relation_constraints R2, RDB $ ref_constraints ref, RDB $ index_segments rind
Where r1.rdb $ relation_name = 'tablename'
And r1.rdb $ constraint_type = 'foreign key'
And r1.rdb $ constraint_name = ref. RDB $ constraint_name
And ref. RDB $ const_name_uq = r2.rdb $ constraint_name
And r1.rdb $ index_name = rind. RDB $ index_name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.