Skip to main content

Posts

Showing posts with the label create table code

SQL Stored Procedure Examples-Create,Delete and Drop Table ,insert,row count

Create,Delete and Drop Table  Through SQL Stored Procedure Following is code which you can create new Stored procedure in SQL Stored procedure section and can write following code. You can understand easily by reviewing whole code. set ANSI_NULLS OFF set QUOTED_IDENTIFIER OFF GO Create PROCEDURE [dbo].[SP_abc](@userID char(3)) AS BEGIN -- Statement to create table if NOT exists (select * from dbo.sysobjects where id = object_id('abc')) exec("CREATE TABLE abc(@field1 CHAR(3),LOGDT SMALLDATETIME,LOGTM DATETIME )") END set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO -- Statement to Delete records from table table Create PROCEDURE [dbo].[SP_DELETE](@ID1 char(3)) AS BEGIN SET NOCOUNT ON if exists (select * from dbo.sysobjects where id = object_id('L')) BEGIN DELETE FROM abc WHERE ID1=@id1 END END set ANSI_NULLS OFF set QUOTED_IDENTIFIER OFF GO -- Statement to Drop table Create PROCEDUR...

Example of Create table in sql

This is a simple example to learn how to create table in sql with different data types and columns. You can see also how to add foreign key in table in create syntax. create table Authors ( AuthorNumber number primary key, RefNumber varchar2(10), LastName varchar2(40), FirstName varchar2(40) null, Organization varchar2(50) null, city varchar2(50) null, State varchar2(30) null, Country varchar2(40) null, Address varchar2(200) null, email varchar2(50) null, Phone varchar2(50) null, Fax varchar2(50) null, foreign key(RefNumber) references papermst(RefNumber) );