PHP MSSQL - How To Create a New Table?
Submitted by: AdministratorIf you want to create a table in the SQL Server database, you can run the CREATE TABLE SQL statement using the mssql_query() function, as shown in the following sample script:
<?php
$con = mssql_connect('LOCALHOST','sa','GlobalGuideLine');
mssql_select_db('GlobalGuideLineDatabase', $con);
# creating a new table
$sql = "CREATE TABLE ggl_links ("
. " id INT NOT NULL"
. ", url VARCHAR(80) NOT NULL"
. ", notes VARCHAR(1024)"
. ", counts INT"
. ", time DATETIME"
. ")";
$res = mssql_query($sql,$con);
if (!$res) {
print("Table creation failed with error: ");
print(" ".mssql_get_last_message()." ");
} else {
print("Table ggl_links created. ");
}
mssql_close($con);
?>
If you run this script for the first time and there is no existing table called ggl_links in the database, you will get:
Table ggl_links created.
If you run it again, you will get:
Table creation failed with error:
There is already an object named 'ggl_links' in the
database.
Submitted by: Administrator
<?php
$con = mssql_connect('LOCALHOST','sa','GlobalGuideLine');
mssql_select_db('GlobalGuideLineDatabase', $con);
# creating a new table
$sql = "CREATE TABLE ggl_links ("
. " id INT NOT NULL"
. ", url VARCHAR(80) NOT NULL"
. ", notes VARCHAR(1024)"
. ", counts INT"
. ", time DATETIME"
. ")";
$res = mssql_query($sql,$con);
if (!$res) {
print("Table creation failed with error: ");
print(" ".mssql_get_last_message()." ");
} else {
print("Table ggl_links created. ");
}
mssql_close($con);
?>
If you run this script for the first time and there is no existing table called ggl_links in the database, you will get:
Table ggl_links created.
If you run it again, you will get:
Table creation failed with error:
There is already an object named 'ggl_links' in the
database.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If NULL Values Are Involved in Bitwise Operations? |
☺ | What Are Binary String Data Types in MS SQL Server? |
☺ | How To Modify an Existing User Defined Function? |
☺ | What are system databases in MS SQL Server? |
☺ | How To Test ODBC DSN Connection Settings? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |