简体   繁体   中英

How to Create new Database from Existing Database in SQL Server

I need to create new database from existing database. I mean to say i have some "xyz" database in the sql server now i need to create new database and i want to import all the table structure and tables data and stored procedures and views and functions from the existing database("xyz") to newly created database. I want to do this entire process using stored procedure.

You can use PHP script.

executable file example01.php code as follows:

     <?php
// connection SQL server database
$conn=mssql_connect("localhost","sa","");        //sqlserver name, name,password
mssql_select_db("table_book",$conn);             //table_book is sqlserver database name
//connection mysql database
$id=mysql_connect("localhost","root","root");    //localhost,user name:root,password:root
mysql_select_db("shop_book",$id);                //shop_book is mysql database
//select all books table content in sqlserver
$ms_query=mssql_query("select * from book",$conn);
//foreach output book table content
while($msrow=mssql_fetch_array($ms_query)){
$name=$msrow[name];                              //set variable
$author=$msrow[author];
$bookconcern=$msrow[bookconcern];
//add data mysql database
$query=mysql_query("insert into book(name,author,bookconcern)
values('$name','$author','$bookconcern')",$id);   }
?>      

Copy and paste the database that is required to create a new database. You have to copy or clone the database names and its structures to another database with newest name to be provided. Hope it will help u....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM