Monday, June 26, 2017

Types of C Variables

An entity that may vary during program execution is called a variable. 
Variable names are names given to locations in memory. These locations can contain integer, real or character constants.

For example: 

an integer variable can hold only an integer constant, 
a real variable can hold only a real constant and 
a character variable can hold only a character constant.

Character Constants

A character constant is a single alphabet.
A single digit or a single special symbol enclosed within single inverted commas.
Both the inverted commas should point to the left.


For example:

’A’ is a valid character constant whereas ‘A’ is not.

The maximum length of a character constant can be 1 character.

Ex.:

'A'
'I'
'5'
'='

Wednesday, June 7, 2017

How can I get databse names in SQL Server Exist or Not.



Before the creating new database, here I want to check that any database is not created or not previously same name.

Generally we have used a simple command to create database like :

Syntax:
Create Database DB_Name;

Example:
Create Database TestDB


The important thing is this before this, let it check that the database I am going to create, is already exist or not in the master database or in our database previously.
For this I am writing below query to check database name exist or not :

Example:
Select * From master.dbo.sysdatabases
By above query you see all the database that you have created in your database.
Now finally, I am writing exact query that never give you error while the executing the query.


If Not Exists (Select * From master.dbo.sysdatabases Where Name=' TestDB')
Begin
                Create Database TestDB
End
Go

How can I get column names from a table in SQL Server?

In this discussion, I want to share the simple query to fetch all column name in specific table of the database.

As you already know that to show that all column name is existing in the table, you use ALT+F1. 

So, there are different short keys and SQL Queries to show column name and details of table. 

Keys and Queries are as follows:
You can use below SQL Query
SYNTAX 1:
SELECT * FROM DB_NAME.INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME='TABLE_NAME'
EXAMPLE:
SELECT * FROM EMPLOYEEINFO.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='EMPLOYEEDETAILS'

You can also use sp_help
SYNTAX 1:
            sp_help <table_name>;
EXAMPLE:
sp_help EMPLOYEEDETAILS

You can use keyboard Short_cut for the above command by Select Table Name (Highlight Table Name) and press ALT + F1.