Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Creating tables by using SQL

wajahatwajahat Member Posts: 24
I want to create a table/ Database in Sql Server 2000 by Using Query (Create table/Create database) but i need
i. Query should check is table/Database alreay exist if not then create table / database

Thanks for you help

Comments

  • The OschThe Osch Member Posts: 30
    : I want to create a table/ Database in Sql Server 2000 by Using Query
    : (Create table/Create database) but i need
    : i. Query should check is table/Database alreay exist if not then create
    : table / database
    :
    : Thanks for you help
    :

    To create database:

    use master
    if ( select count(dbid) from sysdatabases where name = 'my_database_name' ) = 0
    create database my_database_name

    To create table:

    use my_database_name
    if ( select count(id) from sysobjects where type = 'U' and name = 'my_table_name' ) = 0
    create table my_table_name /* ... - complete CREATE TABLE statement */


Sign In or Register to comment.