Google Answers Logo
View Question
 
Q: database concepts (4) ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: database concepts (4)
Category: Computers > Software
Asked by: fahd-ga
List Price: $5.00
Posted: 09 Oct 2002 13:38 PDT
Expires: 08 Nov 2002 12:38 PST
Question ID: 74587
How can I use basic SQL in the giving table of info. 
name           Address  ID #         fam
Bob            A           1         Null
Joe            B           3         Null
Mark           C           5         Null
Mary           A           2         1
Vickie         B           4         3
Wayne          D           6         null

How would delete rows where fam is null using SQL?
Answer  
Subject: Re: database concepts (4)
Answered By: willie-ga on 10 Oct 2002 00:26 PDT
Rated:5 out of 5 stars
 
Hi there

To delete rows with a NULL data item you should use the folowing

DELETE from <TABLE> WHERE fam is NULL;

(Also note that some versions of SQL also use the construct 
DELETE * from <TABLE> WHERE fam is NULL; 
All this means is that the * is equivalent to saying "delete all rows
where the condition applies".

The other constructs you might have thought of are: 
DELETE from <TABLE> WHERE fam = 0;
This won't work as fam is a string variable, not a number

and 
DELETE from <TABLE> WHERE fam = ""; 
This won't work as SQL doesn't recognise "" as a valid item to search
for.

The DELETE statement will erase an entire row from a table in your
database. Be careful to always limit the scope of your DELETE
statement with the WHERE clause, or you run the risk of emptying your
entire table.


There's a nice basic SQL tutorial online at
http://www.baycongroup.com/sql.htm

Google search stategy
://www.google.com/search?q=%22SQL+Basics%22+DELETE

Clarification of Answer by willie-ga on 10 Oct 2002 01:24 PDT
I just realised that your question could be read two ways. Do you want
to know how to do other SQL commands on the table?

If so, here are the basics

To create the empty table use CREATE
eg
CREATE TABLE FAMILY
(name VARCHAR(15), 
address VARCHAR(1), 
ID# SMALLINT(3), 
fam VARCHAR(2)
);

To populate your table, do this for each row, changing the data
eg
INSERT INTO FAMILY 
VALUES ('Bob','A', 1,);
or 
INSERT INTO FAMILY 
VALUES ('Mary','A',2,'1');
(NOTE that to insert a null, you just leave a blank after the ,


To update the table use the UPDATE command
eg to change Marks address to B
UPDATE FAMILY
SET    Address = 'B'
WHERE  name='Mark';


To get data from table use SELECT
eg
SELECT name, fam FROM table
WHERE fam is NOT NULL;
Would return 

Mary, 1 
Vickie, 3

When you've used the statements (called DML - Database Manipulation
Language statements)  such as INSERT, UPDATE and DELETE during a SQL
session you must 'finalise' the changes you've made to the table by
using the COMMIT command:
An example of your SQL session might look like this

DELETE FROM 	FAMILY
WHERE	name='Joe';
1 row deleted

COMMIT;
commit completed


Hope I'm not teaching granny to suck eggs. 
The tutorial I referred to in the answer goes through it all nice and
easily

and theres a nice neat overview of the basic commands at
http://www.dragonlee.co.uk/sql02.html

Willie
fahd-ga rated this answer:5 out of 5 stars and gave an additional tip of: $3.00
Thank you for your help
could you please look into one other Access question I posted dealing
with HotelTable, Departure>=Arrival
fch

Comments  
Subject: Re: database concepts (4)
From: alan_dershowitz-ga on 09 Oct 2002 14:25 PDT
 
delete from TABLENAME where fam is null;

you cannot test for equality on a null value, so you have to use "is null"

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy