Professional Documents
Culture Documents
• Show Database • Show all field Names with Data Types in selected Table
• Select Database
Day 3 - Manage Database
What is Syntax?
SQL is followed by unique set of rules and guidelines called Syntax. This tutorial gives you a
quick start with SQL by listing all the basic SQL Syntax:
All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE,
ALTER, DROP, CREATE, USE, SHOW
Syntax:
CREATE DATABASE <DATABASE NAME>
Example:
CREATE DATABASE CMPortal
Alter Database
Modify existing database name from old name to new name.
Syntax:
ALTER DATABASE <OLD DATABASE NAME> MODIFY NAME = <NEW DATABASE NAME>
Example:
ALTER DATABASE CMPortal MODIFY NAME = SCCMPortal
Show Database
When you have multiple databases in your SQL schema, then before starting your operation,
you would need to select a database where all the operations would be performed.
Always database name should be unique within the RDBMS.
Syntax:
SELECT * FROM SYSDATABASES
Example:
SELECT * FROM SYSDATABASES
Select Database
When you have multiple databases in your SQL Schema, then before starting your operation,
you would need to select a database where all the operations would be performed.
The SQL USE statement is used to select any existing database in SQL schema.
Always database name should be unique within the RDBMS.
Syntax:
USE <DATABASE NAME>
Example:
USE SCCMPortal
Drop Database
• The SQL Drop Database statement is used to drop an existing database in SQL schema.
• Always database name should be unique within the RDBMS.
• Make sure you have admin privilege before dropping any database. Once a database is
dropped.
Note:
Be careful before using this operation because by deleting an existing database would result
in loss of complete information stored in the database.
Syntax:
DROP DATABASE <DATABASE NAME>
Example:
DROP DATABASE SCCMPortal
Show all Objects in selected Database
• Show list of objects in selected Database.
Note:
• U User Tables
• SQ Sequences
• V Views
• P Procedure
Syntax:
SELECT * FROM SYSOBJECTS
Example:
SELECT * FROM SYSOBJECTS
Show all Tables in selected Database
• Show all tables in selected Database.
Syntax:
SELECT * FROM SYS.TABLES
Example:
SELECT * FROM SYS.TABLES
Show all Views in selected Database
• Show all views in selected Database.
Syntax:
SELECT * FROM SYS.VIEWS
Example:
SELECT * FROM SYS.VIEWS
Show all field names with Data types
• Show all filed names with data types in selected table.
Syntax:
SP_COLUMNS <TABLE NAME>
Example:
SP_COLUMNS STUDENT
LAB Demo
To Learn SQL Server you have use it more
Here are Some reference Links :