Some basic SQL Questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven O.

    Some basic SQL Questions

    First, this may not be the correct newsgroup. I have some relatively
    basic questions on SQL. I tried to find a newsgroup that was
    specifically just about SQL, and was surprised to find that all the
    SQL-related newsgroups seem to be product related. But if I missed
    something, and someone can steer me to a correct newsgroup, please do
    so.

    My specific questions:

    1. I want to put comments in an SQL script. For example, I want
    something like

    CREATE TABLE myTable
    (field1 CHAR(10), /* References the field1 table */
    field2 DECIMAL(3,2) /* References field2 table */
    );

    Here, I've used C-style comments, but I don't think that works with
    SQL. Is there any other syntax for sticking comments in a script?

    2. I am writing my script based on some texts from an Oracle class I
    took a year ago. But an online .pdf tutorial I found lists some data
    types that are not in my text:
    varchar2(n)
    number(o,d)
    Are these valid!?

    3. Is there any kind of "memo" field in SQL? My database references
    some text that may be arbitrary in length (like ingredients for a
    recipe), and a way to link to memo fields would be helpful. Or, is
    that the purpose of the varchar2 data type?

    Thanks in advance for all replies.

    Steve O.


    Standard Antiflame Disclaimer: Please don't flame me. I may actually *be* an idiot, but even idiots have feelings.
  • Jeff Boes

    #2
    Re: Some basic SQL Questions

    At some point in time, Steven O.
    <Steven@OpZZREM OVE_ALL_Zs_AND_ ALL_BETWEEN_ZZC omm.com> wrote:
    [color=blue]
    >First, this may not be the correct newsgroup. I have some relatively
    >basic questions on SQL. I tried to find a newsgroup that was
    >specifically just about SQL, and was surprised to find that all the
    >SQL-related newsgroups seem to be product related. But if I missed
    >something, and someone can steer me to a correct newsgroup, please do
    >so.[/color]

    Well, the answers you are most likely to get *here* will be specifically related
    to PostgreSQL. However, its SQL dialect is pretty close to what most other
    vendors support, so you should be OK in 97% of the things you try.
    [color=blue]
    >
    >1. I want to put comments in an SQL script. For example, I want
    >something like
    >
    >CREATE TABLE myTable
    >(field1 CHAR(10), /* References the field1 table */
    >field2 DECIMAL(3,2) /* References field2 table */
    >);
    >[/color]

    Perfectly acceptable in Pg. It also accepts the "--" line comment sequence (in
    which everything after a bare, unquoted "--", until the end of the line, is a
    comment).
    [color=blue]
    >2. I am writing my script based on some texts from an Oracle class I
    >took a year ago. But an online .pdf tutorial I found lists some data
    >types that are not in my text:
    >varchar2(n)
    >number(o,d)
    >Are these valid!?[/color]

    Depends on the specific SQL you are using. In Pg, it's fine.

    Chapter&nbsp;8.&nbsp;Data Types Table of Contents 8.1. Numeric Types 8.1.1. Integer Types 8.1.2. Arbitrary Precision Numbers 8.1.3. Floating-Point Types 8.1.4. Serial …


    [color=blue]
    >
    >3. Is there any kind of "memo" field in SQL? My database references
    >some text that may be arbitrary in length (like ingredients for a
    >recipe), and a way to link to memo fields would be helpful. Or, is
    >that the purpose of the varchar2 data type?
    >[/color]

    "TEXT" is the unspecified length datatype in Pg. See the previous URL.


    --
    ~~~~~~~~~~~~~~~ ~| Genius may have its limitations, but stupidity is not
    Jeff Boes | thus handicapped.
    jboes@qtm.net | --Elbert Hubbard (1856-1915), American author


    Comment

    • William ZHANG

      #3
      Re: Some basic SQL Questions


      "Steven O." <Steven@OpZZREM OVE_ALL_Zs_AND_ ALL_BETWEEN_ZZC omm.com> wrote:
      hh73001fej4r1ho trvk030ubmpffdc 6r0a@4ax.com...[color=blue]
      > First, this may not be the correct newsgroup. I have some relatively
      > basic questions on SQL. I tried to find a newsgroup that was
      > specifically just about SQL, and was surprised to find that all the
      > SQL-related newsgroups seem to be product related. But if I missed
      > something, and someone can steer me to a correct newsgroup, please do
      > so.[/color]
      comp.databases. theory covers database theory. You can find some stuff
      on SQL standards. For the basic SQL, some textbooks on SQL is helpful.
      [color=blue]
      >
      > My specific questions:
      >
      > 1. I want to put comments in an SQL script. For example, I want
      > something like
      >
      > CREATE TABLE myTable
      > (field1 CHAR(10), /* References the field1 table */
      > field2 DECIMAL(3,2) /* References field2 table */
      > );[/color]

      The standard way is using "--". Like,
      -- create a emp table
      create table emp(
      fno int, -- number of emp
      fname char(8) -- name of emp.
      )

      Some DBMSs, e.g. PostgreSQL, also support /* ... */.
      [color=blue]
      >
      > Here, I've used C-style comments, but I don't think that works with
      > SQL. Is there any other syntax for sticking comments in a script?
      >
      > 2. I am writing my script based on some texts from an Oracle class I
      > took a year ago. But an online .pdf tutorial I found lists some data
      > types that are not in my text:
      > varchar2(n)
      > number(o,d)
      > Are these valid!?[/color]

      See ORACLE's manuals for details. They are valid data types
      in ORACLE.
      [color=blue]
      >
      > 3. Is there any kind of "memo" field in SQL? My database references
      > some text that may be arbitrary in length (like ingredients for a
      > recipe), and a way to link to memo fields would be helpful. Or, is
      > that the purpose of the varchar2 data type?[/color]

      Use BYTEA/TEXT in PostgreSQL.
      Use BLOB/CLOB in standard SQL, ORACLE, ....
      Use IMAGE/TEXT in MSSQL.
      [color=blue]
      >
      > Thanks in advance for all replies.[/color]

      You are welcome.
      [color=blue]
      >
      > Steve O.
      >
      >
      > Standard Antiflame Disclaimer: Please don't flame me. I may actually[/color]
      *be* an idiot, but even idiots have feelings.


      Comment

      Working...