Rayz.com

Welcome to Rayz.com

SQL Various Statements

Delete Table

DROP table_name

Create Table

CREATE TABLE ‘table_name’ (
RecID INT IDENTITY(1,1) PRIMARY KEY,
LastName VarChar(50) NOT NULL,
FirstName VarChar(50),
Address1 VarChar(100),
Address2 VarChar(100),
City VarChar(50),
Region VarChar(25),
Country VarChar(25),
ZipCode VarChar(12)
);

Alter Table

ALTER TABLE ‘table_name’
ADD COLUMN ‘Phone’ VarChar(16);

ALTER TABLE ‘table_name’
DROP COLUMN Phone;

Insert Into Table

INSERT INTO ‘table_name’
(Country,Region)
VALUES
(:RecID,’USA’,’OK’);
NOTE: :RecID insures that no dupes will be created with an auto incrementing column

Update Table

UPDATE ‘table_name’
SET LastName = ‘Smith’
WHERE LastName = ‘Smithy’;

Delete From Table

DELETE FROM ‘table_name’
WHERE Country <> ‘USA’;

Create Data Types

CREATE DISTINCT TYPE USdollar AS DECIMAL (10,2)
and use them like:
CREATE TABLE Invoice (
InvoiceNumber INT IDENTITY(1,1) PRIMARY KEY,
CustomerID INTEGER NOT NULL,
SalesTotal USdollar,
Tax USdollar,
Shipping USdollar
);