Click here to Skip to main content
15,921,905 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to create database,tables and stored procedures and userdefined functions for a sqlserver database using sqlquery from codebehind using c#.net.
Posted

 
Share this answer
 
You construct the proper SQL statements and execute them. Is there a specific problem? What have you tried?
 
Share this answer
 
To Create Data Base-

Sqlconnection con=new SqlConnection();
con.ConnectionString = "SERVER = FTCPU2144; DATABASE = master;
User ID = sa; Pwd = sa";
con.Open();
string sCreateDataBase="CREATE DATABASE db_DataBase";
SqlCommand cmd=new SqlCommand(sCreateDataBase,con);
cmd.ExecuteNonQuery();

To Create Tables-

Sqlconnection con=new SqlConnection();
con.ConnectionString ="SERVER = FTCPU2144; DATABASE = master;
User ID = sa; Pwd = sa";
con.Open();
string sCreateDataBase="CREATE TABLE tb_Test(n_Id int,s_Name VARCHAR(20) )";
SqlCommand cmd=new SqlCommand(sCreateDataBase,con);
cmd.ExecuteNonQuery();


To Create Tables-

Sqlconnection con=new SqlConnection();
con.Open();
string sCreateDataBase="CREATE TABLE tb_Test(n_Id int,s_Name VARCHAR(20) )";
SqlCommand cmd=new SqlCommand(sCreateDataBase,con);
cmd.ExecuteNonQuery();

To Create Stored Procedures go through the belo link

http://msdn.microsoft.com/en-us/library/zxsa8hkf(v=vs.80).aspx

To Craete User Defined functions go through below link

http://msdn.microsoft.com/en-us/library/w2kae45k(v=vs.80).aspx
 
Share this answer
 
Comments
RoshInd 18-Nov-11 6:15am    
THis works,thanks alot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900