Go Back   Webmaster Forum > Development > Database and SQL
REMOVE the ads below !
Reply
 
LinkBack Thread Tools
  # 1 (permalink)
Old
Max
Administrator
Posts: 337
Join Date: Feb 2007
iTrader: (0)
[004] Mysql - Create a record - 01-03-2008

Create a record


Type: INSERT INTO name (id, first, last) VALUES (NULL, 'George', 'Washington'); then press ENTER.

This command string creates the first record in the table name. It reads much like a sentence: INSERT INTO the table name (which has the fields id, first, and last) the corresponding VALUES NULL, George, and Washington

Since the id field can't be blank (it has a NOT NULL property), putting a NULL value in it forces MySQL to automatically number the record (because the id field also has the property AUTO_INCREMENT).
The data in the table name is now organized like this:
Fields:
id
first
last
Record:
1
George
Washington

TIP: Text is enclosed within single quotes to let MySQL know that it's just text, not a command.
If the phrase
'What is the first name of the president named Washington whose values kept him from cutting down the cherry tree?'
was not enclosed in single quotes, MySQL might interpret the words name and values as commands, and get confused.
In these examples, single-quotes are used. Double-quotes perform the same function.

Type: INSERT INTO name (id, first, last) VALUES (NULL, 'John', 'Adams'), (NULL, 'Thomas', 'Jefferson'), (NULL, 'James', 'Madison'); then press ENTER. This adds three records to the table name: one record each for presidents John Adams, Thomas Jefferson, and James Madison. The data in the table name are now organized like this: Fields:
id
first
last
Records:
1
George
Washington

2
John
Adams

3
Thomas
Jefferson

4
James
Madison


Yours Sincerely,
Max.
Administrator
GeekPoint Network
Reply With Quote
Reply


Thread Tools



Advertise Here for just $6 per month

vBulletin®, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. | SEO by vBSEO | Skin developed by vBStyles.com