Make sure you are using the correct database;
USE MyDatabase;
GO
Create a synonym as an alternate name for an existing object.
CREATE SYNONYM employees2 FOR MyDatabase.dbo.employees;
Reference the synonym in a query.
SELECT * FROM employees2;
Drop the synonym.
DROP SYNONYM employees2;
For more information see:
Make sure you are using the correct database;
USE MyDatabase;
GO
Create a view.
CREATE VIEW employees_v as
SELECT employee_id,
first_name + ' ' + last_name as employee_name,
date_of_birth
FROM employees;
Display the data using the view.
SELECT * FROM employees_v;
Drop the view.
DROP VIEW employees_v;
For more information see:
Make sure you are using the correct database;
USE MyDatabase;
GO
Create a table.
CREATE TABLE employees
(
employee_id INT IDENTITY(1,1) PRIMARY KEY,
first_name VARCHAR(30),
middle_names VARCHAR(100),
last_name VARCHAR(30),
date_of_birth DATE
)
Insert some data.
INSERT INTO employees (first_name, middle_names, last_name, date_of_birth)
VALUES ('Peter', NULL, 'Parker', '2007-05-08');
Display the data in the table.
SELECT * FROM employees;
Drop the table.
DROP TABLE employees;
For more information see:
Here is a simple example of creating a database in SQL Server.
USER master;
GO
CREATE DATABASE MyDatabase
ON (
Name = N'MyDatabase',
FileName = N'e:\db\MyDatabase.mdf',
Size = 10MB,
maxsize = unlimited,
filegrowth = 1GB
)
LOG ON
(
Name = N'MyDatabaseLog',
FileName = N't:\tl\MyDatabase.ldf',
Size = 10MB,
maxsize = unlimited,
filegrowth = 1GB
)
You will typically see sizes referenced in units of KB, MB, GB or TB.
You can drop a database using the following type of command.
DROP DATABASE MyDatabase
For more information see: