How to create a table

create table [table name] ([column 1 name] [data 1 type], [column 2 name] [data 2 type], ... ) [constraints];

...where the constraints can be...

  • unique - no 2 records have same value in a particular column
  • not null - column can't be left blank
  • primary key - unique id for each record/row
Examples:

CREATE TABLE `main` ( `id` INT UNSIGNED NOT NULL auto_increment, `hash` CHAR(32), `info` VARCHAR(255),  `data` LONGBLOB, PRIMARY KEY (`id`));

How to see a list of columns in a table

show columns from <table>

Delete from a table

All rows: DELETE FROM some_table
Selected stuff: DELETE FROM some_table WHERE `some_column` = "some_value";

How to insert data into a table

INSERT INTO [table name] ([column 1 name], [column 2 name], ...) VALUES ([column 1 value], [column 2 value], ...);

What are common data types?

  • char(size) - Fixed-length character string. size is specified in parenthesis. Max 255 bytes.
  • varchar(size) - Variable-length character string. size specifies the maximum size
  • number(size) - Number value. size specifies max number of column digits
  • number(size,d) - Number value. size specifies max number of total column digits, d specifies number of decimal places
  • date - for date values

A good online tutorial?

-- MattWalsh - 07 Aug 2002

Topic revision: r4 - 07 Nov 2006 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback