Updating Data in SQL

Not only do you need to add new records, but at some point you also need to change the records. To update records, you use the UPDATE statement. Specifying which records to change is the main difference between inserting new data and updating existing data. You specify which records to update with the WHERE clause, which allows you to specify that the only records to update are those where a certain condition is true. For example, say film club member Steve Gee has changed his address. His MemberId is 4, so you could tell the database to...

read more

Inserting New Data in SQL

The INSERT INTO statement makes inserting new data into the database very easy. All you need to do is specify into which table you want to insert data, into which columns to insert data, and finally what data to insert. The basic syntax is as follows: INSERT INTO table_name (column_names) VALUES (data_values) This line of code adds a record to the Category table: INSERT INTO Category (CategoryId, Category) VALUES (1, ‘Thriller’); You can see that inserting data is simply a matter of listing each column name (separated by a comma) in the...

read more

Creating, Altering, and Deleting Tables in SQL

Creating a Table To create a table, use SQL’s CREATE TABLE statement. Creating a basic table involves naming the table and defining its columns and each column’s data type. The following is the basic syntax for creating a table: CREATE TABLE name_of_table ( name_of_column column_datatype ) CREATE TABLE is the keyword telling the database system what you want to do—in this case, you want to create a new table. The unique name or identifier for the table follows the CREATE TABLE statement. Then in brackets comes the list defining each...

read more

Comparing SQL to Other Programming Languages

Now that you know what SQL can be used for, you can compare it to other programming languages. To be honest, SQL is quite different from the procedural languages such as C++, Visual Basic, Pascal, and other third-generation programming languages, which allow the programmer to write step-by-step instructions telling the computer exactly what to do to achieve a specified goal. Taking the car sales example, your goal might be to select all the information about sales made in July from the New York car showroom. Very roughly, your procedural...

read more

Introducing SQL Queries

SQL queries are the most common use of SQL. A SQL sublanguage called Data Manipulation Language (DML) deals with queries and data manipulation. SQL allows you to pose a query (basically a question) to the database, and the database then provides the data that answers your query. For example, with a database that stores details of salespersons, car sales, type of cars sold, and so on, you might want to know how many cars each salesperson sold in each month and how much money they made the company. You could write a SQL query that asks this...

read more