Archive for September 21st, 2007
ALTER TABLE ORDERS FOREIGN KEY
MySQL:
CREATE TABLE ORDERS
(Order_ID integer,
Order_Date date,
Customer_SID integer,
Amount double,
Primary Key (Order_ID),
Foreign Key (Customer_SID) references CUSTOMER(SID));
Oracle:
CREATE TABLE ORDERS
(Order_ID integer primary key,
Order_Date date,
Customer_SID integer references CUSTOMER(SID),
Amount double);
SQL Server:
CREATE TABLE ORDERS
(Order_ID integer primary key,
Order_Date datetime,
Customer_SID integer references CUSTOMER(SID),
Amount double);
Below are examples for specifying a foreign key by altering a table. This assumes that the ORDERS table has been created, and the foreign key has not yet been put in:
MySQL:
ALTER TABLE ORDERS
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
Oracle:
ALTER TABLE ORDERS
ADD (CONSTRAINT fk_orders1) FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
SQL Server:
ALTER TABLE ORDERS
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
MySQL migration: MyISAM to InnoDB
What is referential integrity?
Simply put, referential integrity means that when a record in a table refers to a corresponding record in another table, that corresponding record will exist. Look at the following:
Backup – Restore SQL 2005
Posted by carlosap in SQL Server on September 21st, 2007
T-SQL code
BACKUP:
USE myDatabaseName
GO
BACKUP DATABASE myDatabaseName
TO DISK = ‘C:\filePath\myDatabaseName.bak’
NAME = ‘The name of the back up.’
RESTORE:
RESTORE databaseName
FROM DISK = ‘C:\filePath\backupFilename’