CREATE:

CREATE command is used to create database structure. It is play an important role in SQL database server. Create command is used to create many database structures such as: Table, View, Stored procedure, function etc.

Create command to create table:
Syntax: Create SQL command to create Database Table 
CREATE T TABLE < [TABLE_NAME]>
(
COLUMN_NAME 1  DATA TYPES,
COLUMN_NAME 2  DATATYPES,
----                         ----
----                         -----
COLUMN NAME N   DATA TYPES
)
Example:   CREATE table in SQL server
CREATE TABLE TESTCREATE
(
--- WRITE COLUMN NAME AND THEIR DATE TYPE
 
  ID INT NOT NULL PRIMARY KEY,
  NAME VARCHAR(20),
  STREET_ADDRESS VARCHAR(30),
  PHONENO  INT
 
)

Command(s) completed successfully.

 

INSERT TABLE:

INSERT command is used for insert column value into database table.

Syntax: Insert command

INSERT INTO <TABLE_NAME> (COLUMN_NAME1, COLUMN_NAME2……) VALUES (<VALUE CORRESPONDING COLUMN>)

Example:
INSERT A SINGLR ROW VALUE
----- INSERT VALUES INTO DATABASE TESTCREATE TABLE
INSERT INTO TESTCREATE VALUES('104','SAD')
INSERT MULTIPLE ROW VALUE
----- INSERT MULTIPLE VALUES INTO DATABASE TESTCREATE TABLE
INSERT INTO TESTCREATE(ID,NAME,STREET_ADDRESS,PHONENO)
SELECT '106','RAMPAT TUKKAR'
UNION ALL
SELECT '107','RAMEDY MAARTODKAR'

 

CREATE Command in SQL Server

UPDATE TABLE:

UPDATE command is used for update data column of table in SQL server.

Syntax:

UPDATE <TABLE_NAME> SET <COLUMN_NAME> <COLUMN_VALUE> WHERE <CONDITION>

Example:
---- UPDATE NAME FORM NAME COLUMN WHERE CONDITION MATCH 
 UPDATE TESTCREATE SET NAME = 'JJ TAKKAR' WHERE [STREET_ADDRESS] ='HONG KONG'

 

Command(s) completed successfully.

 

DELETE TABLE:

 DELETE command used for delete database object from SQL database server.

Syntax:

DELETE FROM <TABLENAME> WHERE <CONDITION>

Example: DELETE COLUMN WITH CONDITION

--- DELETE ROW FROM TABLE WHERE CONDITION ARE TRUE

 DELETE FROM TESTCREATE WHERE ID = '101'

1 row effected.

Example: DELETE WHOLE COLUMN FROM TABLE

--- DELETE ROWS FROM TABLE E

 DELETE FROM TESTCREATE

 ALTER TABLE:

ALTER table statement are used to modify, edit, delete operation on column of table. There are lots of modification statement available by alter table in which some are statement are given as below:

ADD COLUMN NAME IN TABLE:

ALTER command to add new column in database table.

Syntax:

   ALTER TABLE <TABLE_NAME> ADD <NEW_COLUMN NAME> <DATA TYPE OF NEW COLUMN>

Example:

----ADD NEW COLUMN NAME CALLED DATE OF BIRTH

ALTER TABLE TESTCREATE  ADD DOB DATE

CREATE Command in SQL Server

If we not assign value then it takes by default NULL value.

DROP COLUMN NAME:

Drop command is used drop column name from table.

Syntax:

ALTER TABLE <TABLE_NAME> DROP COLUMN <SPECIFIED _COLUMN_NAME >

Example:

---- DROP TESTCREATE DOB COLUMN ANME

 ALTER TABLE TESTCREATE DROP COLUMN DOB

Command(s) completed successfully.

DROP TABLE:

Drop table command used to drop (delete) the table from database.    

Syntax:                                                                                                                                                                                                                                              

DROP TABLE <TABLE_NAME>                                                                                                                    

Example:                                                          

---- DROP TABLE FROM DATABASE

 DROP TABLE TESTCREATE

Command(s) completed successfully.

 

 

  Modified On Nov-29-2017 07:57:08 PM

Leave Comment