Create table in Sybase

Few rules to create table in Sybase:

  • To create table user must added to the database.
  • To create table user must be granted create table permission on the database.
  • To create table in a database, use database_name
  • .

  • There are can be 2,000,000,000 tables per database.

1) Add user to the database

1> use k2schools
2> go
1> sp_adduser admin
2> go
New user added.
(return status = 0)

2) Grant create table permission to user

1> grant create table to admin
2> go

3) We can check whether a user is having create table permission using following syntax

Sp_helprotect user_name
Sp_helprotect admin
Go

4) Syntax to create table

create table table_name
(column_name, datatype, column_name1, datatype)

Examples:

1> create table student(rollno varchar(10), name varchar(20), age int, dob date)
2> go

1> create table employee(empname varchar(50), empno int, deptno int)
2> go

Insert data into table:
Using insert command, we can insert the data into table.

1> insert into student values(‘001A001′,’George’,6,’05-06-1982′)
2> go
(1 row affected)
To get data from table:
1> select *from student
2> go
rollno name age dob
——————– —————————————- ———– —————-
001A001 George 6 May 6 1982
001A002 Bali Reddy 18 Feb 10 1972
(2 rows affected)

Creating tables using select into query:

Select * into student_names from student
Go

Create tables in other database:
We can create in other database by using the database.. syntax.

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: