The SQL BACKUP DATABASE Statement
The BACKUP DATABASE
statement is used in SQL Server to create a full back up of an existing SQL database.
Syntax
BACKUP DATABASE databasename
TO DISK = 'filepath';
The BACKUP DATABASE
statement is used in SQL Server to create a full back up of an existing SQL database.
BACKUP DATABASE databasename
TO DISK = 'filepath';
The DROP DATABASE
statement is used to drop an existing SQL database.
DROP DATABASE databasename;
Note: Be careful before dropping a database. Deleting a database will result in loss of complete information stored in the database!
The CREATE DATABASE
statement is used to create a new SQL database.
CREATE DATABASE databasename;
Operator | Description |
---|---|
+ | Add |
Subtract | |
* | Multiply |
/ | Divide |
% | Modulo |
Comments are used to explain sections of SQL statements, or to prevent execution of SQL statements.
Note: Comments are not supported in Microsoft Access databases!
Single line comments start with --
.
Any text between — and the end of the line will be ignored (will not be executed).
The following example uses a single-line comment as an explanation : Continue reading SQL Comments
A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again.
So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.
You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is passed. Continue reading SQL Stored Procedures for SQL Server
Look at the following “Products” table:
P_Id | ProductName | UnitPrice | UnitsInStock | UnitsOnOrder |
---|---|---|---|---|
1 | Jarlsberg | 10.45 | 16 | 15 |
2 | Mascarpone | 32.56 | 23 | |
3 | Gorgonzola | 15.67 | 9 | 20 |
Suppose that the “UnitsOnOrder” column is optional, and may contain NULL values. Continue reading SQL NULL Functions
The CASE
expression goes through conditions and returns a value when the first condition is met (like an if-then-else statement). So, once a condition is true, it will stop reading and return the result. If no conditions are true, it returns the value in the ELSE
clause.
If there is no ELSE
part and no conditions are true, it returns NULL. Continue reading SQL CASE Expression
The INSERT INTO SELECT
statement copies data from one table and inserts it into another table.
The INSERT INTO SELECT
statement requires that the data types in source and target tables match.
Note: The existing records in the target table are unaffected. Continue reading SQL INSERT INTO SELECT Statement
The SELECT INTO
statement copies data from one table into a new table.
Copy all columns into a new table:
SELECT *
INTO newtable [IN externaldb]
FROM oldtable
WHERE condition;
Copy only some columns into a new table : Continue reading SQL SELECT INTO Statement