0
SQL> create table artwork
  2         (
      artwork_id number(7) NOT NULL,
       barcode char(20),
        title char(20),
        description char(50),
      PRIMARY KEY (artwork_id)
      );  

Table created.


SQL> select * from artwork;

no rows selected

I created the table but it showing me this error dont know. Why table it not showing?

agam
  • 1
  • 1
  • 7
  • you create a table and doesn't `INSERT` rows. So your `SELECT` can't select rows of your table. You can insert a row with a `INSERT` statement (`INSERT INTO artwork VALUES (...)`). – Sebastian Brosch Apr 20 '18 at 05:19
  • 2
    What are these numbers? 2 3 4 5 6 7 8 – DxTx Apr 20 '18 at 05:25
  • You haven't inserted any to be selected. INSERT INTO artwork (artwork_id, barcode, title, description) values (1, '', '', ''); – DxTx Apr 20 '18 at 05:29
  • ok got it have one more query `SQL> create table artist 2 ( artist_id number(7) NOT NULL, name varchar(20), address varchar(20), contact_number int(10), PRIMARY KEY (artist_id) ); 3 4 5 6 7 8 contact_number int(10), * ERROR at line 6: ORA-00907: missing right parenthesis` – agam Apr 20 '18 at 05:39
  • 2
    Is this Microsoft SQL Server or MySQL? Or Oracle? ORA is usually Oracle server. – tadman Apr 20 '18 at 05:57
  • Well you never inserted rows, how do you expect the table to magically contain rows? There is no error in your question –  Apr 20 '18 at 11:22

2 Answers2

0

I would expect the create to look like this:

create table artwork (
    artwork_id number primary key,
    barcode char(20),
    title varchar2(20),
    description varchar2(50)
);

Notes:

  • There is no need to have number(7). You can specify the length, but it is not necessary.
  • For title and description you definitely want varchar2(). There is no reason to store trailing spaces at the end of a name.
  • That may be the same for barcode, but because it might always be exactly 20 characters or trailing spaces might be significant, you might leave it as char().
  • The primary key constraint can be expressed in-line. There is no need for a separate declaration.
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

You probably simply want something like

create table artwork
(
  artwork_id number(7) NOT NULL,
  barcode varchar2(20),
  title varchar2(20),
  description varchar2(50),
  PRIMARY KEY (artwork_id)
);

insert into artwork values (0, 'barcode', 'fancytitle', 'somedescription');
insert into artwork values (1, 'barcode1', 'fancytitle1', 'somedescription1');

select * from artwork;

This creates a table "ARTWORK", inserts 2 rows in it and then selects all rows currently in the table.

An empty table contains no data, with the create table-statement you only define the bucket of data, you have to fill the bucket as well with items.

I'd also recommend a auto increment column (oracle 12c) or a trigger/sequence to increment the id automatically. But that's something to read later :)

Chrᴉz remembers Monica
  • 1,829
  • 1
  • 10
  • 24