Database Tips

Microsoft SQL Server

Database Creation/Alteration Keywords:

Create, Set and Alter

Process Keywords:

Go, Begin Transaction, Rollback and Use

Data Manipulation Keywords (or action queries):

Select, Insert, Update and Delete

Misc Notes:

-End all statements with a semicolon ;

-ALL String data is indicated by the use of single quotes

ex.

'Orange Juice' NOT "Orange Juice"

-SQL uses a dotted namespace

ex. dbo.products or production.inventory

-Case sensitivity is not important; dbo.products is the same as DBO.Products

Likewise, use northwind is the same as USE Northwind

-You can have extra white space in your SQL statements and the server will simply ignore it

-The asterisk (*) is commonly the wldcard character in our queries

-You can sort by a column or field that was NOT included in the original selection query

-When selecting several columns, use a comma (,) to separate the columns that you want to use

-ORDER BY clause orders in ascending order (ASC) by default; to have it order in descending order, use the keyword DESC

ex. ...order by city DESC;

-Numeric column values don't need quotes, unlike string column values, which are enclosed in SINGLE quotes ( ' )

-Comments are done in two different ways

//This is a single line comment (done by two forward slashes (//))

//To continue onto another line, you need to put the comment symbol in again

For a multiline comment, use the forward slash followed by an asterisk (/*)

/* This is a
multiline comment that
continues onto more than one line */

This is just like CSS comments


Keywords

Select
DESC
Insert (or Insert Into)
Delete
Update
Set (Used to set a value)
Grant
Revoke
Create (Create Table Test)
Drop (Drop Table Test)

Clauses

From
Order By (put last in the Statement)
Where (Allows Criteria)
(Order usually comes after a Where clause)

Here's some links for MS SQL Server

MySQL

(Notes gratefully taken from MySQL Press- MySQL Tutorial)

--Create a database

create database test2;

--To use the new database and create a table

use test2
create table ooga
(oogaid int not null auto_increment primary key,
type varchar(20)
)type=innodb;
--NOTE MS SQL doesn't like "auto_increment primary key" and definitely wouldn't like "type=innodb"

--To show what databases are on the machine [no MS SQL equivalant]
show databases;

 

--To show tables [no MS SQL equivalant]
show tables;

--To see the contents of said tables in the database [no MS SQL equivalant]
describe tablename;

Here's a way to test MySQL Installation...

Backing up and Restoring MySQL

Moving a MySQL database from GoDaddy servers to another MySQL server (preferrably a local server)

--Phase 1--

First, sign in to GoDaddy, then click on Hosting Account List, then to your hosted domain.

Click on Open, then click on the Databases tab, then MySQL.

Next, select your database that you want to back up and click on Open Manager.

Sign in.(This is the hardest part...remembering the stupid username/password...)

PHPMyAdmin graphic

Once in, it will look like this:

Signed into Database

Select the database on the dropdown menu on the left, then click on Export.

Export Feature

 

Click on Save as File at the bottom of the screen. Enter a name of your choosing and click on Go on the lower right portion of the screen.

It will prompt you to save the file as YOURFILENAME.sql.

Save As

--Phase 2--
Now, the easy part...restoring the DB.

Connect to your local server however you would normally connect.
(I would recommend Toad, found at http://www.toadsoft.com/
You can customize the interface to match whatever DB product you are used to. I selected MS Management Server, the one for Microsoft SQL Server 2005.)

Verify the successful download of your .sql file by opening it in Notepad (if it's small enough). [sample.sql]

Once verified, create the new database using your RDBMS. ( I called it RESTORE.)

Toad RDBMS

Next, open a query (or editor) window and copy and paste the contents in. Click the Run button.

Verify the imported data by running the following query:

use RESTOREDDBNAME;
select * from TABLENAME;

You should get the same results.

Tada!! You're done!!

Oracle


Back to Class Tips

Back to Home