Home / Database / SQL Server / How to create table in SQL database?
create table

How to create table in SQL database?

Create table in SQL Database.

In below article we will see how to create table , delete table, update table and select table in qul database .It is easy to create table in sql.

Create Table Command:

To create table in the database following syntax is used.

  • Create Table < Table Name >

(< Column Name > < Datatype > [Constraint],
.
.
,

< Column Name > < Datatype > [Constraint],

[Table Level Constraints] )
E.g. Create Table MyTable (Id int primary key, Name nvarchar(10) )

Select Command:
Syntax:
Select */ < Column List >  from < Table Name >
[ Where < Condition > ] [ Order By , Column Name > [ asc / desc ] ]

  • For Ascending ordering acronym “asc” is used.
  • For descending ordering acronym “desc” is used.

Selecting list of tables from database:

  • Select * from information_schema.tables.

Selecting list of columns of a table:

  • Select * from information_schema.columns where table_name = ‘< Table Name >’

Selecting list of constraints on a table:

To get the list of constraints imposed on the table, use below system store procedure.

  • SP_helpconstraint < Table Name >

To get the list of constraints along with column information of table, use below system store procedure.

  • Sp_help < Table Name >

Creating Table using another table / Copy table to new table / Copying table structure & data to another table:

  • Select * < Column List > into < Destination Table Name > from < Source Table Name > [ Where < condition > ]

Insert Command:
To insert a row to database use following command.

  • Insert [ Into ] < Table Name > ( < Column List > ) Values ( < values > )

Inserting row from table to another table:

  • Row can be inserted from one table to another for the structurally same tables.
  • Syntax is : Insert Into < Table Name > < Select Table Command >
  • Example: Insert Into DestinationTable Select * from SourceTable.

Update Command:
To update data of a table row following command is used.

  • Update < Table Name >

Set < Column Name > = < value >, < Column Name > = < value >,
[Where < Condition >]

Delete Command:
Delete table:

  • Delete [ From ] < Table Name >

[Where < Condition >] Truncate Table:

  • Truncate Table < Table Name >

Drop Table:

  • Drop Table < Table Name >

About Helpservices

About This site (allhelpservices.com) is dedicated to helping other bloggers learn the skills of blogging, wordpress, education, technology, social media sharing , SEO, Electronics, Earn Money From Blogging, Web hosting and web share their own experiences and promote the blogging medium. We started Allhelpservices in August 2015 mainly because we wanted to keep a record of what we wear learning from development and because we wanted to connect with other learners.

Check Also

Database

Database level Queries & Identity functions

Get list of tables in the Database: We can get all the tables in the ...

Leave a Reply