The SQL CREATE DATABASE Statement
The CREATE DATABASE
statement is used to create a new SQL database.
Syntax
CREATE DATABASE databasename;
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
The ANY
and ALL
operators allow you to perform a comparison between a single column value and a range of other values.
The ANY
operator:
ANY
means that the condition will be true if the operation is true for any of the values in the range. Continue reading SQL ANY and ALL Operators
The EXISTS
operator is used to test for the existence of any record in a subquery.
The EXISTS
operator returns TRUE if the subquery returns one or more records.
SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);