Thursday 6 August 2015

SQL Server - Most Important SQL Commands

SELECT - Get data from a Table
Example
select * from table1; 
select Column1,Column2,Column3 from table1;

UPDATE - update data in a Table
Example
update table1 set Column2='Value2',Column3='Value3' where Column1='Value1'

DELETE - delete data from a Table
Example
update table1 where Column1='Value1'

INSERT INTO - inserts new data into a Table
Example
insert into table1 (Column2,Column3) values ('Value2','Value3')

CREATE DATABASE - create a new DataBase
Example
create database DataBaseName;

ALTER DATABASE - modifies a DataBase
Example
ALTER DATABASE  OLDDataBaseName MODIFY NAME = newDBName

CREATE TABLE - create a new Table
Example
CREATE TABLE table_name (column_name1 data_type(size),column_name2 data_type(size),column_name3 data_type(size),....);

CREATE TABLE table1(column1 int,column2 varchar(255),column3 varchar(255));

ALTER TABLE - modifies a Table
Now we want to add a column named "Column4" in the "table1" table. We use the following SQL statement:
Example
ALTER TABLE table1 ADD column4 decimal(25,3)

Drop Column Example

ALTER TABLE table1 DROP COLUMN column4

DROP TABLE - delete a table
Example
DROP TABLE table1

No comments:

Post a Comment